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.

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

18 except ImportError:<br />

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

20<br />

21 # Since the actual value of Infinity is ignores, we define it solely<br />

22 # for symbolic purposes:<br />

23 inf = 0.0<br />

24<br />

25<br />

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

27 def streamprinter(text):<br />

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

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

30<br />

31<br />

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

33 # to create a function.<br />

34 def main ():<br />

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

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

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

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

39<br />

40 # Create a task<br />

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

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

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

44<br />

45<br />

46 bkc = [ mosek.boundkey.up ]<br />

47 blc = [ -inf, ]<br />

48 buc = [ 2.5 ]<br />

49<br />

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

51 mosek.boundkey.lo,<br />

52 mosek.boundkey.lo,<br />

53 mosek.boundkey.lo ]<br />

54<br />

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

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

57<br />

58 c = [ <strong>7.0</strong>, 10.0, 1.0, 5.0 ]<br />

59<br />

60 asub = [ 0, 0, 0, 0 ]<br />

61 acof = [ 1.0, 1.0, 1.0, 1.0]<br />

62<br />

63 ptrb = [ 0, 1, 2, 3 ]<br />

64 ptre = [ 1, 2, 3, 4 ]<br />

65<br />

66 numvar = len(bkx)<br />

67 numcon = len(bkc)<br />

68<br />

69 # Input linear data<br />

70 task.inputdata(numcon,numvar,<br />

71 c,0.0,<br />

72 ptrb, ptre, asub, acof,<br />

73 bkc, blc, buc,<br />

74 bkx, blx, bux)<br />

75

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

Saved successfully!

Ooh no, something went wrong!