summaryrefslogtreecommitdiff
path: root/help/en_US/linprog.xml
blob: 88fe15a2e91fa54bc0d9b65de77d2110f2db10e0 (plain)
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
<?xml version="1.0" encoding="UTF-8"?>

<!--
 *
 * This help file was generated from linprog.sci using help_from_sci().
 *
 -->

<refentry version="5.0-subset Scilab" xml:id="linprog" xml:lang="en"
          xmlns="http://docbook.org/ns/docbook"
          xmlns:xlink="http://www.w3.org/1999/xlink"
          xmlns:svg="http://www.w3.org/2000/svg"
          xmlns:ns3="http://www.w3.org/1999/xhtml"
          xmlns:mml="http://www.w3.org/1998/Math/MathML"
          xmlns:scilab="http://www.scilab.org"
          xmlns:db="http://docbook.org/ns/docbook">

  <refnamediv>
    <refname>linprog</refname>
    <refpurpose>Solves a linear programming problem.</refpurpose>
  </refnamediv>


<refsynopsisdiv>
   <title>Calling Sequence</title>
   <synopsis>
   xopt = linprog(c,A,b)
   xopt = linprog(c,A,b,Aeq,beq)
   xopt = linprog(c,A,b,Aeq,beq,lb,ub)
   xopt = linprog(c,A,b,Aeq,beq,lb,ub,param)
   xopt = linprog(file)
   xopt = linprog(file,param)
   [xopt,fopt,exitflag,output,lambda] = linprog( ... )
   
   </synopsis>
</refsynopsisdiv>

     <refsection>
   <title>Input Parameters</title>
   <variablelist>
   <varlistentry><term>c :</term>
      <listitem><para> A vector of doubles, containing the coefficients of the variables in the objective function.</para></listitem></varlistentry>
   <varlistentry><term>A :</term>
      <listitem><para> A matrix of doubles, containing the coefficients of linear inequality constraints of size (m X n) where 'm' is the number of linear inequality constraints.</para></listitem></varlistentry>
   <varlistentry><term>b :</term>
      <listitem><para> A vector of doubles, related to 'A' and containing the the Right hand side equation of the linear inequality constraints of size (m X 1).</para></listitem></varlistentry>
   <varlistentry><term>Aeq :</term>
      <listitem><para> A matrix of doubles, containing the coefficients of linear equality constraints of size (m1 X n) where 'm1' is the number of linear equality constraints.</para></listitem></varlistentry>
   <varlistentry><term>beq :</term>
      <listitem><para> A vector of doubles, related to 'Aeq' and containing the the Right hand side equation of the linear equality constraints of size (m1 X 1).</para></listitem></varlistentry>
   <varlistentry><term>lb :</term>
      <listitem><para> A vector of doubles, containing the lower bounds of the variables of size (1 X n) or (n X 1) where 'n' is the number of variables.</para></listitem></varlistentry>
   <varlistentry><term>ub :</term>
      <listitem><para> A vector of doubles, containing the upper bounds of the variables of size (1 X n) or (n X 1) where 'n' is the number of variables.</para></listitem></varlistentry>
   <varlistentry><term>options :</term>
      <listitem><para> A list, containing the option for user to specify. See below for details.</para></listitem></varlistentry>
   <varlistentry><term>file :</term>
      <listitem><para> A string describing the path to the mps file.</para></listitem></varlistentry>
         </variablelist>
</refsection>
<refsection>
<title> Outputs</title>
 <variablelist>
   <varlistentry><term>xopt :</term>
      <listitem><para> A vector of doubles, containing the computed solution of the optimization problem.</para></listitem></varlistentry>
   <varlistentry><term>fopt :</term>
      <listitem><para> A double, containing the the function value at x.</para></listitem></varlistentry>
   <varlistentry><term>exitflaf :</term>
      <listitem><para>  An integer, containing the flag which denotes the reason for termination of algorithm. See below for details.</para></listitem></varlistentry>
   <varlistentry><term>output :</term>
      <listitem><para> A structure, containing the information about the optimization. See below for details.</para></listitem></varlistentry>
   <varlistentry><term>lambda :</term>
      <listitem><para> A structure, containing the Lagrange multipliers of lower bound, upper bound and constraints at the optimized point. See below for details.</para></listitem></varlistentry>
   </variablelist>
</refsection>



<refsection>
   <title>Description</title>
   <para>
Search the minimum of a constrained linear programming problem specified by :
   </para>
   <para>
<latex>
\begin{eqnarray}
\hspace{10pt} &amp;\mbox{min}_{x}
\hspace{10pt} &amp; c^T⋅x  \\
\hspace{10pt} &amp; \text{Subjected to:} &amp; A⋅x \leq b \\
\end{eqnarray}\\
\begin{eqnarray}
\hspace{115pt} &amp; Aeq⋅x = beq \\
\hspace{115pt} &amp; lb \leq x \leq ub \\
\end{eqnarray}
</latex>
</para>
   <para>
OSI-CLP, an optimization library written in C++, is used for solving the linear programming problems.

   </para>
<para>
<title>Options</title>
The options allow the user to set various parameters of the Optimization problem. The syntax for the options is given by:
   </para>
   <para>
options= list("MaxIter", [---], "CpuTime", [---], "GradObj", ---, "Hessian", ---, "GradCon", ---);
   </para>
   <para>
The options should be defined as type "list" and consist of the following fields:
<itemizedlist>
<listitem>MaxIter : A Scalar, specifying the Maximum Number of iterations that the solver should take.</listitem>
</itemizedlist>
</para>
<para>
The default values for the various items are given as:
   </para>
   <para>
options = list("MaxIter", [3000], "CpuTime", [600]);
   </para>

   <para>
The exitflag allows the user to know the status of the optimization which is returned by Ipopt. The values it can take and what they indicate is described below:
<itemizedlist>
<listitem>0 : Optimal Solution Found </listitem>
<listitem>1 : Primal Infeasible </listitem>
<listitem>2 : Dual Infeasible</listitem>
<listitem>3 : Maximum Number of Iterations Exceeded. Output may not be optimal.</listitem>
<listitem>4 : Solution Abandoned</listitem>
<listitem>5 : Primal objective limit reached.</listitem>
<listitem>6 : Dual objective limit reached.</listitem>
</itemizedlist>
   </para>
   
   <para>
The output data structure contains detailed information about the optimization process.
It is of type "struct" and contains the following fields.
<itemizedlist>
<listitem>output.Iterations: The number of iterations performed.</listitem>
<listitem>output.constrviolation: The max-norm of the constraint violation.</listitem>
</itemizedlist>
   </para>
   <para>
The lambda data structure contains the Lagrange multipliers at the end of optimization. In the current version the values are returned only when the the solution is optimal.
It has type "struct" and contains the following fields.
<itemizedlist>
<listitem>lambda.lower: The Lagrange multipliers for variable lower bounds.</listitem>
<listitem>lambda.eqlin: The Lagrange multipliers for the linear equality constraints.</listitem>
<listitem>lambda.ineqlin: The Lagrange multipliers for the linear inequality constraints.</listitem>
</itemizedlist>
   </para>
   <para>
</para>

</refsection>

<para>
A few examples displaying the various functionalities of linprog have been provided below. You will find a series of problems and the appropriate code snippets to solve them.
   </para>
<refsection>
   <title>Example</title>
   <para>
 Here we solve a simple objective function, subjected to six linear inequality constraints.
   </para>
   <para>
Find x in R^2 such that it minimizes:
   </para>
   <para>
<latex>
\begin{eqnarray}
\mbox{min}_{x}\ f(x) = -x_{1} - \dfrac{x_{2}}{3} \\
\end{eqnarray}
\text{Subjected to:}\\
\begin{eqnarray}
\hspace{1pt} &amp;x_{1} + x_{2}&amp;\leq 2\\ 
\hspace{1pt} &amp;x_{1} + \dfrac{x_{2}}{4}&amp;\leq 1\\
\hspace{1pt} &amp;x_{1} - x_{2}&amp;\leq 2\\
\hspace{1pt} &amp;-\dfrac{x_{1}}{4} - x_{2}&amp;\leq 1\\
\hspace{1pt} &amp;-x_{1} - x_{2}&amp;\leq -1\\
\hspace{1pt} &amp;-x_{1} + x_{2}&amp;\leq 2\\
\end{eqnarray}
</latex>
   </para>
   <para>

   </para>
   <programlisting role="example"><![CDATA[
//Example 1: Linear program, linear inequality constraints
c=[-1,-1/3]'
A=[1,1;1,1/4;1,-1;-1/4,-1;-1,-1;-1,1]
b=[2,1,2,1,-1,2]
[xopt,fopt,exitflag,output,lambda]=linprog(c, A, b)
// Press ENTER to continue

   ]]></programlisting>
</refsection>

<refsection>
   <title>Example</title>
<para>
Here we build up on the previous example by adding linear equality constraints.
We add the following constraints to the problem specified above:
   </para>
   <para>
<latex>
\begin{eqnarray}
\hspace{1pt} &amp;x_{1} + \dfrac{x_{2}}{4}&amp;= 1/2 
\end{eqnarray}
</latex>
  </para>
<para>
</para>
   <programlisting role="example"><![CDATA[
//Example 2: Linear program with Linear Inequalities and Equalities`
c=[-1,-1/3]'
A=[1,1;1,1/4;1,-1;-1/4,-1;-1,-1;-1,1]
b=[2,1,2,1,-1,2]
Aeq=[1,1/4]
beq=[1/2]
[xopt,fopt,exitflag,output,lambda]=linprog(c, A, b, Aeq, beq)
// Press ENTER to continue

   ]]></programlisting>
</refsection>

<refsection>
   <title>Example</title>
<para>
In this example, we proceed to add the upper and lower bounds to the objective function.
   </para>
   <para>
<latex>
\begin{eqnarray}
-1 &amp;\leq x_{1} &amp;\leq 1.5\\
-0.5 &amp;\leq x_{2} &amp;\leq 1.25
\end{eqnarray}
</latex>
   </para>
<para>
</para>
   <programlisting role="example"><![CDATA[
//Example 3: Linear program with all constraint types
c=[-1,-1/3]'
A=[1,1;1,1/4;1,-1;-1/4,-1;-1,-1;-1,1]
b=[2,1,2,1,-1,2]
Aeq=[1,1/4]
beq=[1/2]
lb=[-1,-0.5]
ub=[1.5,1.25]
[xopt,fopt,exitflag,output,lambda]=linprog(c, A, b, Aeq, beq, lb, ub)
// Press ENTER to continue

   ]]></programlisting>
</refsection>
<refsection>
<title>Example</title>

   <para>
Primal Infeasible Problems: Find x in R^3 such that it minimizes:
   </para>
   <para>
<latex>
\begin{eqnarray}
mbox{min}_{x}\ f(x) = x_{1} - x_{2}  \- x_{3}\\
\end{eqnarray}
\\\text{Subjected to:}\\
\begin{eqnarray}
\hspace{70pt} &amp;x_{1} + 2x_{2} - x{3}&amp;\leq -4\\
\hspace{70pt} &amp;x_{1} + 4x_{2} + 3x{3}&amp;= 10\\
\hspace{70pt} &amp;x_{1} + x_{2}&amp;= 100\\
\end{eqnarray}
\\
\begin{eqnarray}
\hspace{135pt}0 &amp;\leq x_{1} &amp;\leq \infty\\
\hspace{135pt}0 &amp;\leq x_{2} &amp;\leq \infty\\
\hspace{135pt}0 &amp;\leq x_{3} &amp;\leq \infty
\end{eqnarray}
</latex>
   </para>
   <para>
   </para>   <programlisting role="example"><![CDATA[
//Example 4: Primal Infeasible Problem
c=[-1,-1,-1]'
A=[1,2,-1]
b=[-4]
Aeq=[1,5,3;1,1,0]
beq=[10,100]
lb=[0,0,0]
ub=[%inf,%inf,%inf]
[xopt,fopt,exitflag,output,lambda]= linprog(c,A,b,Aeq,beq,lb,ub)
// Press ENTER to continue

   ]]></programlisting>
</refsection>

<refsection>
   <title>Example</title>

   <para>
Unbounded Problems: Find x in R^3 such that it minimizes:
   </para>
   <para>
<latex>
\begin{eqnarray}
mbox{min}_{x}\ f(x) = x_{1} - x_{2}  \- x_{3}\\
\end{eqnarray}
\\\text{Subjected to:}\\
\begin{eqnarray}
\hspace{70pt} &amp;-x_{1} - x_{2} + 4x{3}&amp;\leq -8\\
\hspace{70pt} &amp;x_{1} + x_{2} + 4x{3}&amp;\leq 5\\
\end{eqnarray}
\\
\begin{eqnarray}
\hspace{115pt}-\infty &amp;\leq x_{1} &amp;\leq \infty\\
\hspace{115pt}-\infty &amp;\leq x_{2} &amp;\leq \infty\\
\hspace{115pt}-\infty &amp;\leq x_{3} &amp;\leq \infty
\end{eqnarray}
</latex>
   </para>
   <para>
   </para>
   <programlisting role="example"><![CDATA[
//Example 5: Unbounded Problem
c=[3,5,-7]'
A=[-1,-1,4;1,1,4]
b=[-8,5]
Aeq=[]
beq=[]
lb=[-%inf,-%inf,-%inf]
ub=[%inf,%inf,%inf]
[xopt,fopt,exitflag,output,lambda]= linprog(c,A,b,Aeq,beq,lb,ub)
// Press ENTER to continue

   ]]></programlisting>
</refsection>

<refsection>
   <title>Example</title>
   <programlisting role="example"><![CDATA[
filepath = get_absolute_file_path('linprog.dem.sce');
filepath = filepath + "exmip1.mps"
[xopt,fopt,exitflag,output,lambda] =linprog(filepath)
   ]]></programlisting>
</refsection>





<refsection>
   <title>Authors</title>
   <simplelist type="vert">
   <member>Bhanu Priya Sayal, Guru Pradeep Reddy</member>
   </simplelist>
</refsection>
</refentry>