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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

5.7 Integer optimization<br />

An optimization problem where one or more of the variables are constrained to integer values is denoted<br />

an integer optimization problem.<br />

5.7.1 Example: Mixed integer linear optimization<br />

In this section the example<br />

maximize x 0 + 0.64x 1<br />

subject to 50x 0 + 31x 1 ≤ 250,<br />

3x 0 − 2x 1 ≥ − 4,<br />

x 0 , x 1 ≥ 0 and integer<br />

is used to demonstrate how to solve a problem with integer variables.<br />

(5.10)<br />

5.7.1.1 Source code<br />

<strong>The</strong> example (5.10) is almost identical to a linear optimization problem except for some variables being<br />

integer constrained. <strong>The</strong>refore, only the specification of the integer constraints requires something new<br />

compared to the linear optimization problem discussed previously. In <strong>MOSEK</strong> these constraints are<br />

specified using the function Task.putvartype as shown in the code:<br />

[ milo1.py ]<br />

83 task.putvartypelist([ 0, 1 ],<br />

84 [ mosek.variabletype.type int,<br />

85 mosek.variabletype.type int ])<br />

<strong>The</strong> complete source for the example is listed below.<br />

1 ##<br />

[ milo1.py ]<br />

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

3 #<br />

4 # File: milo1.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 # If numpy is installed, use that, otherwise use the<br />

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

15 try:<br />

16 from numpy import array,zeros,ones<br />

17 except ImportError:<br />

18 from mosek.array import array, zeros, ones<br />

19<br />

20 # Since the actual value of Infinity is ignores, we define it solely

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

Saved successfully!

Ooh no, something went wrong!