LP格式


LP格式

LP格式以比MPS格式更容易读取人类的方式捕获优化模型,并且通常可以更自然地生产。LP格式的一个限制是它不保留几个模型属性。特别是,LP文件在读取时不保留列顺序,并且通常不保留系数的确切数值(尽管这不是格式的固有状态)。

与MPS文件不同,LP文件不依赖于固定字段宽度。排行中断和空格字符用于分隔对象。这是一个简单的例子:

\ LP格式示例最大化x + y + z对c0:x + y = 1 c1:x + 5 y + 2 z <= 10 qc0:x + y + [x ^ 2  -  2 x * y + 3 y ^2 ] <= 5 Bounds 0 <= x <= 5 z >= 2 Generals x y z End

反斜杠符号开始注释;忽略了该系列的其余部分。

Variable names play a major role in LP files. Each variable must have its own unique name. A name should be no longer than 255 characters, and to avoid confusing the LP parser, it can not begin with a number or any of the characters+, - ,*,^,<,>,=,(,),[],,或:。For similar reasons, a name should not contain any of the characters+, - ,*,^,或:。此外,变量名称不应与任何LP文件格式关键字相等(不区分大小写),例如,St,界限,分钟,最大,二进制或结束。Names must be preceded and followed by whitespace.

The same rules apply to any other type of names in the LP format, e.g., constraint names or the objective name.

Note that whitespace characters are not optional in the Gurobi LP format. Thus, for example, the textX+y+zwould be treated as a single variable name, whilex + y + zwould be treated as a three term expression.

LP files are structured as a list of sections, where each section captures a logical piece of the whole optimization model. Sections begin with particular keywords, and must generally come in a fixed order, although a few are allowed to be interchanged.

Objective Section

The first section in an LP file is the objective section. This section begins with one of the following six keywords:最小化最大化minimum最大min那要么最大限度。忽略了大写。此关键字可以单独出现,或者它可能会立即后跟multi-objectives,表示该模型包含多个目标函数。

单目标案例

让我们首先考虑单目标模型,其中该标题后跟一个捕获目标函数的单个线性或二次表达式。

目标可选择从标签开始。标签由名称组成,后跟冒号字符,按空格。在名称和冒号之间允许一个空间,但不需要。

然后,目标继续列出线性术语列表,由此分开+要么-运营商。术语可以包含系数和变量(例如,4.5 x的)那要么just a variable (e.g.,X)。The objective can be spread over many lines, or it may be listed on a single line. Line breaks can come between tokens, but never within tokens.

目标可以选择继续列出二次术语。目标表达的二次部分始于一个[symbol and ends with a]symbol, followed by/ 2.。这些括号应附上一个或多个二次术语。方格术语(例如,2 x ^ 2)或产品术语(例如,3 x * y)被接受。二次术语上的系数是可选的。

For variables with piecewise-linear objective functions, the objective section will include a__pwl(x)术语,在哪里X是变量的名称。您应该将这些视为评论;LP阅读器忽略了它们。实际的分段 - 线性表达式从后来拉动PWLObj部分。

The objective expression must always end with a line break.

An objective section might look like the following:

最小化obj:3.1 x + 4.5 y + 10 z + [x ^ 2 + 2 x * y + 3 y ^ 2] / 2

Multi-Objective Case

在多目标情况下,标题后跟一个或多个线性目标函数,其中每个函数以其自己的子报头开始。子标题给出目标的名称,然后提供提供a的多个字段Priority重量,绝对的宽容(AbsTol的)和relative tolerance (RelTol)对于那个目标(见objnpriority.ObjNWeightObjNAbsTol, 和objnreltol.for details on the meanings of these fields). The fields start with the field name, followed by a=,其次是值。例如:

obj0:优先级= 2重量= 1 abstol = 0 Reltol = 0
请参考multi-objectivesection for additional details.

Each sub-header is followed by a linear expression that captures that objective.

完整的多目标部分可能如下所示:

最小化多目标obj0:优先级= 2重量= 1 abstol = 0 Reltol = 0 3.1 x + 4.5 y + 10 z obj1:优先级= 1重量= 1 abstol = 0 Reltol = 0 10 x + 0.1 y

The objective section is optional. The objective is set to 0 when it is not present.

约束部分

The next section is the constraints section. It begins with one of the following headers, on its own line:约束such thatst那要么英石。。忽略了大写。

约束部分可以具有任意数量的约束。每个约束从一个可选标签开始(约束名称,后跟冒号,后跟空间),用线性表达式继续,然后是可选的二次表达式(括在方括号中),并以比较运算符结束,然后结束数值,然后是换行符。有效的比较运算符是=<=<>=那要么>。请注意,LP格式不区分严格和非严格的不平等,例如<<=是等同的。

Note that the left-hand side of a constraint may not contain a constant term; the constant must appear on the right-hand side.

以下是有效的线性约束的一个简单示例:

C0:2.5 x + 2.3 y + 5.3 z <= 8.1
The following is a valid quadratic constraint:
QC0:3.1 x + 4.5 y + 10 z + [x ^ 2 + 2 x * y + 3 y ^ 2] <= 10

The constraint section may also contain another constraint type: the so-called indicator constraint. Indicator constraints start with an optional label (constraint name, followed by a colon, followed by a space), followed by a binary variable, a space, a=那again a space and a value, either0.要么1。他们继续走空间,然后是- >, 和again a space and finally a linear constraint (without a label).

例如:

c0: b1 = 1 -> 2.5 x + 2.3 y + 5.3 z <= 8.1

This example constraint requires the given linear constraint to be satisfied if the variableB1takes a value of1

Every LP format file must have a constraints section.

懒惰的约束部分

The next section is the lazy constraints section. It begins with the lineLazy Constraints那optional followed by a space and a laziness level 1-3 (if no laziness level is specified 1 is assumed), and continues with a list of linear constraints in the exact same format as the linear constraints in the constraints section. For example:

Lazy Constraints c0: 2.5 x + 2.3 y + 5.3 z <= 8.1 Lazy Constraints 2 c1: 1.5 x + 3.3 y + 4.3 z <= 8.1

延迟约束是线性约束,它们是语义上等同于标准的线性约束。根据他们的懒惰水平,他们由MIP求解器不同地强制执行。手机万博登录请参阅以下描述Lazyattribute for details.

This section is optional.

边界部分

The next section is the bounds section. It begins with the word界限那on its own line, and is followed by a list of variable bounds. Each line specifies the lower bound, the upper bound, or both for a single variable. The keywordsinf要么无穷can be used in the bounds section to specify infinite bounds. A bound line can also indicate that a variable isfree那meaning that it is unbounded in either direction.

Here are examples of valid bound lines:

0 <= x0 <= 1 x1 <= 1.2 x2> = 3 x3 free x2> = -inf

没有必要为所有变量指定界限;默认情况下,每个变量具有0的下限和无限的上限。实际上,整个界限部分是可选的。

变量类型部分

下一节是变量类型部分。变量可以指定为二进制,常规整数或半连续。在所有情况下,首先提供适当的标题(在其自己的行),然后列出具有相关类型的变量,应用指定。例如:

二进制x y z
Variable type designations don't need to appear in any particular order (e.g., general integers can either precede or follow binaries). If a variable is included in multiple sections, the last one determines the variable type.

Valid keywords for variable type headers are:二进制箱ariesgeneralgeneralsgen半连续半星期六那要么semi

变量类型部分是可选的。默认情况下,假设变量是连续的。

SOS.Section

An LP file can contain a section that captures SOS constraints of type 1 or type 2. The SOS section begins with theSOS.标题在其自己的线上(大写不重要)。可以遵循任意数量的SOS约束。SOS约束从名称开始,后跟冒号(与线性约束不同,此处不可选项)。接下来是SOS类型,可以是S1要么S2。该类型后跟一对冒号。

Next come the members of the SOS set, along with their weights. Each member is captured using the variable name, followed by a colon, followed by the associated weight. Spaces can optionally be placed before and after the colon. An SOS constraint must end with a line break.

Here's an example of an SOS section containing two SOS constraints:

SOS.sos1: S1 :: x1 : 1 x2 : 2 x3 : 3 sos2: S2 :: x4:8.5 x5:10.2 x6:18.3

SOS部分是可选的。

pwlobj部分

An LP file can contain a section that captures piecewise-linear objective functions. The PWL section begins with thePWLObj标题在其自己的线上(大写不重要)。Each piecewise-linear objective function is associated with a model variable. A PWL function starts with the corresponding variable name, followed immediately by a colon (the name is not optional). Next come the points that define the piecewise-linear function. These points are represented as(X那y)对,括号围绕两个值和分隔它们的逗号。PWL功能必须以换行符结尾。

以下是包含两个简单分段线性函数的PWLOBJ部分的示例:

pwlobj x1:(1,1)(2,2)(3,4)x2:(1,3)(3,5)(100,300)

The PWLObj section is optional.

一般约束部分

An LP file may contain an optional section that captures一般约束。This section starts with one of the following keywords一般约束general constraint哥伦桑那要么g.c.(capitalization is ignored).

一般约束可以是两个基本类型:simple一般约束-MIN最大限度要么ABS那要么PWL那要么功能约束 - 多项式(POLY), 力量 (POW),指数(exp.要么expa.的)那logarithmic (LOG要么徽标)或三角仪(cos那要么TAN)。

A simple general constraint starts with an optional label (constraint name, followed by a colon), followed by a variable name (the so-calledresultant),然后等于标志=。该行继续使用一般约束类型说明符(MIN最大限度要么那要么ABS的)那then a。所有令牌必须使用空格分隔。忽略了大写。

What follows depends on the general constraint type.MIN要么最大限度约束期望非空,逗号分隔的变量或值列表。要么constraints expect a comma-separated list of binary variables.ABSconstraints only expect one variable name. Again, all tokens (including commas) must be separated using spaces.

All of these general constraints end with a的)和a line break.

这里有一些例子:

GC0:R1 = MAX(X1,X2,X10,0.7)Gencons1:R2 = min(Y0,10,Y1,R1)和1:R = AND(B1,B2)OR1:R = OR(B3,B4)GC14:xabs = abs(x)

分段 - 线性约束也从一个可选标签开始(约束名称,后跟冒号)。该行继续具有变量名称(所谓的resultant)和一个等号=。接下来是关键词PWLthat indicates that the constraint is of type piecewise-linear. This is followed by a,然后通过变量名称(所谓的操作数)随后是一个的)。The line continues with a然后在括号(例如,(x0,y0)(x1,y1))中分段 - 线性断点列表,x上的非降低值。回想一下令牌之间需要空格。

在这里:

GC0: y[0] = PWL ( x[0] ) : (-1, 2) (0, 1) (0, 0) (0, 1) (1, 2)

还有一种其他类型的简单约束INDICATORconstraint. Those appear in the regular constraints section (described above), not in the general constraint section.

函数约束也从一个可选的label (constraint name, followed by a colon). An optional list of attribute assignments follows. These start with a,然后是一个空格分开的列表Name=Valuestrings (no spaces before or after the=的)那closed with a的)。An example is shown below. Default values are used if no attributes are specified.

该行继续具有变量名称(所谓的resultant)和一个等号=。接下来是一个关键字,指示已定义的函数类型(POLYPOWexp.expa.LOGlog_a.cos那要么TAN)。为一个LOG, 采用log_a.如果它不是自然的日志,在哪里<span>$</span>A<span>$</span>是基地。这是一个, 和then by the expression that defines the actual function. The line closes with a的)。回想一下令牌之间需要空格。

Polynomials and powers are described in what is hopefully the natural way, with exponents preceded by the^象征。

The following give examples of a few function constraints:

GC1 :(转换机= 1E-05 PieRatio = 0.5)Z = SIN(Y)GC2 :( PICTELENCTENCHER = 0.001)Y = POLY(5 x ^ 3 + 2 x + 5)gc3:z = expa(3.5 ^ y)gc4:z = log_10(y)logytoz:z = log(y)

For more information, consult thegeneral constraint discussion

场景部分

LP文件可能包含捕获方案数据的可选部分。模型可以具有多种情况,其中每个方案定义了对原始模型的一组更改(我们将其称为base model)。

本节开始于此Scenario关键字(忽略大写字母),然后是场景名称。场景被描述为对目标函数的一组更改,线性约束的右侧侧面以及变量的界限。首先说明目标变更,然后右侧变化,然后绑定变化。场景可以是空的(即,与基础模型相同)。

目标函数的更改以允许的客观关键词之一开始(最小化Maximize等;有关其他信息,请参阅上面的目标部分)。请注意,关键字需要匹配基本模型的客观意义。接下来这是一条线路,每个改变的物体系数包含可变名称及其修改值(由空格分隔)。

Changes to the right-hand sides of linear constraints start with one of the allowed constraint section keywords (Subject To等;另外看到上面的约束部分tional information). This is followed by a line for each changed right-hand side value that contains the constraint name followed by a colon, then a space, the constraint sense, a space, and the scenario right-hand side value.

Changes to variable bounds start with the界限keyword. This is followed by a line for each variable with changed scenario bounds; the format of each such line is the same as in the bounds section above.

以下示例显示了LP格式的三种情况:

Scenario scenario0 Scenario scenario1 Maximize x1 0 x2 1 Subject To c1: <= 2 c2: >= 2 Bounds x3 <= 1.5 x1 free 0 <= x2 <= 0 x3 >= 0.5 Scenario scenario2 Bounds x3 = 3

For more information, consult the多种情景讨论

结束陈述

The last line in an LP format file should be an结尾statement.