-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCPLEX-format.htm
More file actions
390 lines (374 loc) · 17.2 KB
/
CPLEX-format.htm
File metadata and controls
390 lines (374 loc) · 17.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<HEAD>
<TITLE>CPLEX lp files</TITLE>
<style TYPE="text/css"> BODY { font-family:verdana,arial,helvetica; margin:0; }
</style>
</HEAD>
<BODY>
<TABLE STYLE="TABLE-LAYOUT:fixed" class="clsContainer" CELLPADDING="15" CELLSPACING="0"
WIDTH="100%" BORDER="0">
<TR>
<TD VALIGN="top">
<p><h1 align="left"><u>CPLEX lp files</u></h1>
<p>The CPLEX LP file format provides a facility for entering a problem in a
natural, algebraic LP formulation from the keyboard. The problem can be
modified and saved from within lpsolve. This procedure is one way to create a
file in a format that lpsolve can read. An alternative technique is to create a
similar file using a standard text editor and to read it into lpsolve.</p>
<P>The CPLEX LP format is provided as an input alternative to the MPS file format.
An LP format file may be easier to generate than an MPS file if your problem
already exists in an algebraic format or if you have an application that
generates the problem file more readily in algebraic format (such as a C
application).</P>
<p>Note that the CPLEX LP format is not the same as the lpsolve LP format.
See <a href="lp-format.htm">LP file format</a> for a description about
the native lpsolve lp format. To read/write this format from lpsolve, you need
an XLI (see <a href="XLI.htm">External Language Interfaces</a>). The XLI for the CPLEX
format is called xli_CPLEX.</p>
<h3>Options</h3>
<p>The XLI accepts several options:</p>
<h4>Reading</h4>
<pre>
-objconst Allow constants in the objective (default).
-noobjconst Don't allow constants in the objective.
</pre>
<p>Note that CPLEX doesn't allow constants in the objective (until at least v10).
However, the lp_solve XLI does allow it by default.
Use the option -noobjconst if these should not be allowed.
The parser will then give an error.</p>
<h4>Writing</h4>
<pre>
-objconst Allow constants in the objective.
-noobjconst Don't use constants in the objective (default).
</pre>
<p>Note that CPLEX doesn't allow constants in the objective (until at least v10).
However, the lp_solve XLI does allow it when the option -objconst is used.
By default or when the option -noobjconst is used, a constant in the objective
is translated to a variable objconst_term with a bound equal to the constant set
to it. So no error is generated when there is a constant.</p>
<h3>Example</h3>
<pre>
lp_solve -rxli xli_CPLEX input.lpt
lp_solve -mps input.mps -wxli xli_CPLEX output.lpt -wxliopt "-objconst"
</pre>
<h3>Syntax Rules of LP File Format</h3>
<P>lpsolve will accept any problem saved in an ASCII file provided that it adheres
to the following syntax rules.
</P>
<ol>
<li value="1">
<a name="157718">
Anything that follows a backslash (\) is a comment and is ignored until a
return is encountered. Blank lines are also ignored. Blank and comment lines
may be placed anywhere and as frequently as you want in the file. </a>
<p></p>
<li value="2">
<a name="157738">
In general, white space between characters is irrelevant as it is skipped when
a file is read. However, white space is not allowed in the keywords used to
introduce a new section, such as <code>MAX</code>, <code>MIN</code>, <code>ST</code>,
or <code>BOUNDS</code>. Also the keywords must be separated by white space from
the rest of the file and must be at the beginning of a line. The maximum length for any
name is 255. The maximum length of any line of input is 510. </A>
<p></p>
</li>
</ol>
<dl>
<dt>
<dd><a name="157736"></a>
Skipping spaces may cause lpsolve to misinterpret (and accept) an invalid
entry, such as the following:
<p>
<Table border="0" bgcolor="#eeeeee" width="100%" ID="Table1">
<tr>
<td><pre><a name="157770"> x1 x2 = 0
</a><a name="157777">
</a></pre>
</td>
</tr>
</Table>
<p>
<p></p>
<dt>
<dd><a name="157778">
If the user intended to enter that example as a nonlinear constraint,
lpsolve would instead interpret it as a constraint specifying
that one variable named <code>x1x2</code> must be equal to zero. </A>
<p></p>
</dd>
</dl>
<ol>
<li value="3"><a name="157784">
The problem statement must begin with the word <code>MINIMIZE</code> or <code>MAXIMIZE</code>,
<code>MINIMUM</code> or <code>MAXIMUM</code>, or the abbreviations <code>MIN</code>
or <code>MAX</code>, in any combination of upper- and lower-case
characters. The word introduces the objective function section. </a>
<p></p>
<li value="4"><a name="157797">
Variables can be named anything provided that the name does not exceed 255
characters, all of which must be alphanumeric (a-z, A-Z, 0-9) or one of these
symbols: ! " # $ % & ( ) / , . ; ? @ _ ` ' { } | ~. Longer names are
truncated to 255 characters. A variable name cannot begin with a number or a
period. </A>
<p></p>
</li>
</ol>
<dl>
<dt>
<dd><a name="157811">
The letter <code>E</code> or <code>e</code>, alone or followed by other valid
symbols, or followed by another <code>E</code> or <code>e</code>, should be
avoided as this notation is reserved for exponential entries. Thus, variables
cannot be named <code>e9</code>, <code>E-24</code>, <code>E8cats</code>, or
other names that could be interpreted as an exponent. Even variable names such
as <code>eels</code> or <code>example</code> can cause a read error,
depending on their placement in an input line. </a>
<p></p>
<dt>
<dd><a name="157809">
Also, the following characters are not valid in variable names (in order to
allow for quadratic objective information): ^, *, [ and ]. </A>
<p></p>
</dd>
</dl>
<ol>
<li value="5"><a name="157824">
The objective function definition must follow <code>MINIMIZE</code> or <code>MAXIMIZE</code>.
It may be entered on multiple lines as long as no variable,
constant, or sense indicator is split by a return. For example, this
objective function <code>1x1 + 2x2 +3x3</code> can be entered like this:<br>
<br>
<Table border="0" bgcolor="#eeeeee" width="100%" ID="Table2">
<tr>
<td><pre><a name="157828">1x1 + 2x2
</a><a name="157841">+ 3x3
</a><a name="157842">
</a></pre>
</td>
</tr>
</Table>
</a>
</LI>
</ol>
<ol>
<a name="157829">but not like this:<br>
<br>
<Table border="0" bgcolor="#eeeeee" width="100%" ID="Table3">
<tr>
<td><pre><a name="157832">1x1 + 2x
</a><a name="157847">2 + 3x3 \ a bad idea
</a><a name="157848">
</a></pre>
</td>
</tr>
</Table>
<br>
</a>
<a name="157849">
because the second style splits the variable name <code>x2</code> with a return.
</A>
<p></p>
</ol>
<ol>
<li value="6">
<a name="157754">
The objective function may be named by typing a name and a colon before the
objective function. The objective function name and the colon must appear on
the same line. Objective function names must conform to the same guidelines as
variable names (Rule <a href="CPLEX-format.htm#157797">4</a>).</a>
<p><a name="157865"></p>
<li value="7">
The constraints section is introduced by the keyword <code>SUBJECT TO</code>.
This expression can also appear as <code>such that</code>, <code>st</code>, <code>S.T.</code>,
or <code>ST.</code> in any mix of upper- and lower-case characters. One of
these expressions must precede the first constraint and be separated from it by
at least one space. </A>
<p></p>
<li value="8">
<a name="157869">
Each constraint definition must begin on a new line. A constraint may be named
by typing a name and a colon before the constraint. The constraint name and the
colon must appear on the same line. Constraint names must adhere to the same
guidelines as variable names (Rule <a href="CPLEX-format.htm#157797">4</a>). If
no constraint names are specified, lpsolve assigns the names <code>R1</code>,
<code>R2</code>, <code>R3</code>, etc. </A>
<p><a name="157942"></p>
<li value="9">
The constraints are entered in the same way as the objective function; however,
a constraint must be followed by an indication of its sense and a right-hand
side coefficient. The right-hand side coefficient must be typed on the same
line as the sense indicator. Acceptable sense indicators are <, <=,
=<, >, >=, =>, and =. These are interpreted as <=, <=, <=, >=, >=, >= and
=, respectively. </A>
<p></p>
</li>
</ol>
<ol>
<a name="157850">For example, here is a named constraint:
<p>
<Table border="0" bgcolor="#eeeeee" width="100%" ID="Table4">
<tr>
<td><pre><a name="158874">time: x1 + x2 <= 10
</a><a name="158876">
</a></pre>
</td>
</tr>
</Table>
<p></a>
<p></p>
</ol>
<ol>
<a name="158004">
<li value="10">
The optional <code>BOUNDS</code> section follows the mandatory constraint
section. It is preceded by the word <code>bounds</code> or <code>bound</code>
in any mix of lower- and upper-case characters. </a>
<p><a name="158005"></p>
<li value="11">
Each bound definition must begin on a new line. The format for a bound is <em>l</em><sub>n</sub> <= <em>x</em><sub>n
</sub> <= <em>u</em><sub>n</sub> except in the following cases: </A>
<p></p>
</li>
</ol>
<ol>
<a name="158001">
Upper and lower bounds may also be entered separately as:<br>
<br>
<em>l</em><sub>n</sub> <= <em>x</em><sub>n</sub><br>
<em>x</em><sub>n</sub> <= <em>u</em><sub>n</sub></a>
<p><a name="158016"></p>
with the default lower bound of 0 (zero) and the default upper bound of +infinite
remaining in effect until the bound is explicitly changed. </A>
<p><a name="158017"></p>
Bounds that fix a variable can be entered as simple equalities.<br>
For example, <code>x5
= 5.6</code> is equivalent to <code>5.6 <= x5 <= 5.6</code>. </A>
<p><a name="158033"></p>
The bounds positive infinity and negative infinity must be entered as
words: <code>+infinity</code>, <code>-infinity</code>,<code> +inf</code>, <code>-inf</code>.
</A>
<p><a name="158044"></p>
A variable with a negative infinity lower bound and positive infinity upper
bound may be entered as <code>free</code>, in any mix of upper- and lower-case
characters, with a space separating the variable name and the word <code>free</code>.<br>
For example, <code>x7 free</code> is equivalent to <code>-infinity <= x7 <=
+infinity</code>. </A>
<p></p>
</ol>
<ol>
<a name="157973">
<li value="12">
The file must end with the word <code>end</code> in any combination of upper-
and lower-case characters, alone on a line. This word is not required for files that are read in to lpsolve, but
it is strongly recommended. Files that have been corrupted can frequently be
detected by a missing last line. </a>
<p><a name="158045"></p>
<li value="13">
To specify any of the variables as general integer variables, add a <code>GENERAL</code>
section; to specify any of the variables as binary integer variables, add a <code>BINARY</code>
section. The <code>GENERAL</code> and <code>BINARY</code> sections follow the <code>
BOUNDS</code> section, if one is present; otherwise, they follow the
constraints section. Either of the <code>GENERAL</code> or <code>BINARY</code> sections
can precede the other. The <code>GENERAL</code> section is preceded by the word <code>
GENERAL</code>, <code>GENERALS</code>, or <code>GEN</code> in any mix of
upper- and lower-case characters which must appear alone.
The following line or lines should list the names of
all variables which are to be restricted to general integer values, separated
by at least one space. The <code>BINARY</code> section is preceded by the word <code>
BINARY</code>, <code>BINARIES</code>, or <code>BIN</code> in any mix of
upper- and lower-case characters which must appear alone on a line.
The following line or lines should list the names of all
variables which are to be restricted to binary integer values, separated by at
least one space. Binary variables are automatically given bounds of 0 (zero)
and 1 (one), unless alternative bounds are specified in the <code>BOUNDS</code>
section, in which case a warning message is issued. </A>
<p></p>
</li>
</ol>
<ol>
<a name="158090">
Here is an example of a problem formulation in LP format where <code>x4</code> is
a general integer:
<p></p>
<Table border="0" bgcolor="#eeeeee" width="100%" ID="Table5">
<tr>
<td><pre><a name="158093">Maximize
</a><a name="158102"> obj: x1 + 2 x2 + 3 x3 + x4
</a><a name="158103">Subject To
</a><a name="158104"> c1: - x1 + x2 + x3 + 10 x4 <= 20
</a><a name="158105"> c2: x1 - 3 x2 + x3 <= 30
</a><a name="158106"> c3: x2 - 3.5 x4 = 0
</a><a name="158107">Bounds
</a><a name="158108"> 0 <= x1 <= 40
</a><a name="158109"> 2 <= x4 <= 3
</a><a name="158110">General
</a><a name="158111"> x4
</a><a name="158112">End
</a><a name="158113">
</a></pre>
</td>
</tr>
</Table>
<p></a>
<p><a name="158118"></p>
<p></p>
</ol>
<ol>
<li value="14"><a name="162647">
To specify any of the variables as semi-continuous variables, that is as variables that
may take the value <code>0</code> or values between the specified lower and upper bounds, use a <code>SEMI-CONTINUOUS</code> section. This section must follow the <code>BOUNDS</code>, <code>GENERALS</code>, and <code>BINARIES</code> sections. The <code>SEMI-CONTINUOUS</code> section is preceded by the keyword <code>SEMI-CONTINUOUS</code>, <code>SEMI</code>, or <code>SEMIS</code>.
The following line or lines should list the names of all the variables
which are to be declared semi-continuous, separated by at least one
space.
</a></li><a name="162649">
<p></p>
<Table border="0" bgcolor="#eeeeee" width="100%" ID="Table5">
<tr>
<td><pre>
Semi-continuous
x1 x2 x3
</pre>
</td>
</tr>
</table>
<p></p>
</a>
<li value="15"><a name="162651">
To specify special ordered
sets, use a SOS section, which is preceded by the SOS keyword. The SOS
section should follow the Bounds, General, Binaries and Semi-Continuous
sections. Special ordered sets of type 1 require that, of the variables
in the set, one at most may be non-zero. Special ordered sets of type 2
require that at most two variables in the set may be non-zero, and if
there are two non-zeros, they must be adjacent. Adjacency is defined by
the weights, which must be unique within a set given to the variables.
The sorted weights define the order of the special ordered set. For MIP
branch and cut, the order is used to determine how the variables are
branched upon. The set is specified by an optional set name followed
by a colon and then either of the S1 or S2 keywords (specifying the type)
followed by a double colon. The set member names are
listed on this line or lines, with their weights. Variable names and
weights are separated by a colon, for example:
</a></li><a name="162655">
<p></p>
<Table border="0" bgcolor="#eeeeee" width="100%" ID="Table5">
<tr>
<td><pre>
SOS
set1: S1:: x1:10 x2:13
</pre>
</td>
</tr>
</table>
</a>
</ol>
<p></p>
<DL>
</DL>
</A>
</TD>
</TR>
</TABLE>
</BODY>
</html>