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 55<br />

21 # for symbolic purposes:<br />

22 inf = 0.0<br />

23<br />

24 # Define a stream printer to grab output from <strong>MOSEK</strong><br />

25 def streamprinter(text):<br />

26 sys.stdout.write(text)<br />

27 sys.stdout.flush()<br />

28<br />

29 # We might write everything directly as a script, but it looks nicer<br />

30 # to create a function.<br />

31 def main ():<br />

32 # Make a <strong>MOSEK</strong> environment<br />

33 env = mosek.Env ()<br />

34 # Attach a printer to the environment<br />

35 env.set Stream (mosek.streamtype.log, streamprinter)<br />

36<br />

37 # Create a task<br />

38 task = env.Task(0,0)<br />

39 # Attach a printer to the task<br />

40 task.set Stream (mosek.streamtype.log, streamprinter)<br />

41<br />

42 bkc = [ mosek.boundkey.up, mosek.boundkey.lo ]<br />

43 blc = [ -inf, -4.0 ]<br />

44 buc = [ 250.0, inf ]<br />

45<br />

46 bkx = [ mosek.boundkey.lo, mosek.boundkey.lo ]<br />

47 blx = [ 0.0, 0.0 ]<br />

48 bux = [ inf, inf ]<br />

49<br />

50 c = [ 1.0, 0.64 ]<br />

51<br />

52 asub = [ array([0, 1]), array([0, 1]) ]<br />

53 aval = [ array([50.0, 3.0]), array([31.0, -2.0]) ]<br />

54<br />

55 numvar = len(bkx)<br />

56 numcon = len(bkc)<br />

57<br />

58 # Append ’numcon’ empty constraints.<br />

59 # <strong>The</strong> constraints will initially have no bounds.<br />

60 task.appendcons(numcon)<br />

61<br />

62 #Append ’numvar’ variables.<br />

63 # <strong>The</strong> variables will initially be fixed at zero (x=0).<br />

64 task.appendvars(numvar)<br />

65<br />

66 for j in range(numvar):<br />

67 # Set the linear term c j in the objective.<br />

68 task.putcj(j,c[j])<br />

69 # Set the bounds on variable j<br />

70 # blx[j]

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

Saved successfully!

Ooh no, something went wrong!