25.11.2015 Views

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

Optimizer API for Python - Documentation - Mosek

Optimizer API for Python - Documentation - Mosek

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

5.7. INTEGER OPTIMIZATION 57<br />

137 sys.exit(0)<br />

5.7.1.2 Code comments<br />

Please note that when Task.getsolutionslice is called, the integer solution is requested by using<br />

soltype.itg. No dual solution is defined for integer optimization problems.<br />

5.7.2 Specifying an initial solution<br />

Integer optimization problems are generally hard to solve, but the solution time can often be reduced<br />

by providing an initial solution for the solver. Solution values can be set using Task.putsolution (for<br />

inputting a whole solution) or Task.putsolutioni (for inputting solution values related to a single<br />

variable or constraint).<br />

It is not necessary to specify the whole solution. By setting the iparam.mio construct sol parameter<br />

to onoffkey.on and inputting values for the integer variables only, will force <strong>MOSEK</strong> to compute the<br />

remaining continuous variable values.<br />

If the specified integer solution is infeasible or incomplete, <strong>MOSEK</strong> will simply ignore it.<br />

5.7.3 Example: Specifying an integer solution<br />

Consider the problem<br />

maximize 7x 0 + 10x 1 + x 2 + 5x 3<br />

subject to x 0 + x 1 + x 2 + x 3 ≤ 2.5<br />

x 0 , x 1 , x 2 integer , x 0 , x 1 , x 2 , x 3 ≥ 0<br />

<strong>The</strong> following example demonstrates how to optimize the problem using a feasible starting solution<br />

generated by selecting the integer values as x 0 = 0, x 1 = 2, x 2 = 0.<br />

1 ##<br />

[ mioinitsol.py ]<br />

2 # Copyright: Copyright (c) <strong>MOSEK</strong> ApS, Denmark. All rights reserved.<br />

3 #<br />

4 # File: mioinitsol.py<br />

5 #<br />

6 # Purpose: Demonstrates how to solve a small mixed<br />

7 # integer linear optimization problem using the <strong>MOSEK</strong> <strong>Python</strong> <strong>API</strong>.<br />

8 ##<br />

9<br />

10 import sys<br />

11<br />

12 import mosek<br />

13<br />

14 # If numpy is installed, use that, otherwise use the<br />

15 # Mosek’s array module.<br />

16 try:<br />

17 from numpy import array,zeros,ones

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

Saved successfully!

Ooh no, something went wrong!