The MOSEK Python optimizer API manual Version 7.0 (Revision 141)

Optimizer API for Python - Documentation - Mosek Optimizer API for Python - Documentation - Mosek

25.11.2015 Views

24 CHAPTER 5. BASIC API TUTORIAL 51 task.writedata (sys.argv[2]) [ simple.py ] Similarly, controlled by iparam.read data format, the function Task.readdata can read a problem from a file: 33 task.readdata (sys.argv[1]) [ simple.py ] 5.1.2.2 Working with the problem data An optimization problem consists of several components; objective, objective sense, constraints, variable bounds etc. Therefore, the interface provides a number of methods to operate on the task specific data, all of which are listed under the Task class-specification. 5.1.2.3 Setting parameters Apart from the problem data, the task contains a number of parameters defining the behavior of MOSEK. For example the iparam.optimizer parameter defines which optimizer to use. There are three kinds of parameters in MOSEK • Integer parameters that can be set with Task.putintparam, • Double parameters that can be set with Task.putdouparam, and • string parameters that can be set with Task.putstrparam, The values for integer parameters are either simple integer values or enum values. A complete list of all parameters is found in Chapter B. 5.2 Linear optimization The simplest optimization problem is a purely linear problem. problem of the following form: Minimize or maximize the objective function A linear optimization problem is a subject to the linear constraints n−1 ∑ c j x j + c f (5.1) j=0 l c k ≤ n−1 ∑ a kj x j ≤ u c k, k = 0, . . . , m − 1, (5.2) j=0

5.2. LINEAR OPTIMIZATION 25 and the bounds lj x ≤ x j ≤ u x j , j = 0, . . . , n − 1, (5.3) where we have used the problem elements: m and n which are the number of constraints and variables respectively, x c which is the variable vector of length n, which is a coefficient vector of size n ⎡ c = ⎣ c 0 c n−1 ⎤ ⎦ , c f A which is a constant, which is a m×n matrix of coefficients is given by l c and u c ⎡ A = ⎣ a 0,0 · · · a 0,(n−1) ⎤ · · · ⎦ , which specify the lower and upper bounds on constraints respectively, and l x and u x which specifies the lower and upper bounds on variables respectively. Please note the unconventional notation using 0 as the first index rather than 1. Hence, x 0 is the first element in variable vector x. This convention has been adapted from Python arrays which are indexed from 0. 5.2.1 Example: Linear optimization The following is an example of a linear optimization problem:

24 CHAPTER 5. BASIC <strong>API</strong> TUTORIAL<br />

51 task.writedata (sys.argv[2])<br />

[ simple.py ]<br />

Similarly, controlled by iparam.read data format, the function Task.readdata can read a problem<br />

from a file:<br />

33 task.readdata (sys.argv[1])<br />

[ simple.py ]<br />

5.1.2.2 Working with the problem data<br />

An optimization problem consists of several components; objective, objective sense, constraints, variable<br />

bounds etc. <strong>The</strong>refore, the interface provides a number of methods to operate on the task specific<br />

data, all of which are listed under the Task class-specification.<br />

5.1.2.3 Setting parameters<br />

Apart from the problem data, the task contains a number of parameters defining the behavior of<br />

<strong>MOSEK</strong>. For example the iparam.<strong>optimizer</strong> parameter defines which <strong>optimizer</strong> to use. <strong>The</strong>re are<br />

three kinds of parameters in <strong>MOSEK</strong><br />

• Integer parameters that can be set with Task.putintparam,<br />

• Double parameters that can be set with Task.putdouparam, and<br />

• string parameters that can be set with Task.putstrparam,<br />

<strong>The</strong> values for integer parameters are either simple integer values or enum values.<br />

A complete list of all parameters is found in Chapter B.<br />

5.2 Linear optimization<br />

<strong>The</strong> simplest optimization problem is a purely linear problem.<br />

problem of the following form:<br />

Minimize or maximize the objective function<br />

A linear optimization problem is a<br />

subject to the linear constraints<br />

n−1<br />

∑<br />

c j x j + c f (5.1)<br />

j=0<br />

l c k ≤<br />

n−1<br />

∑<br />

a kj x j ≤ u c k, k = 0, . . . , m − 1, (5.2)<br />

j=0

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!