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.

86 CHAPTER 7. ADVANCED <strong>API</strong> TUTORIAL<br />

13 #<br />

14 # <strong>The</strong> first argument tells which <strong>optimizer</strong> to use<br />

15 # i.e. psim is primal simplex, dsim is dual simplex<br />

16 # and intpnt is interior-point.<br />

17 ##<br />

18 from future import with statement<br />

19<br />

20 import sys<br />

21<br />

22 import mosek<br />

23 from mosek import *<br />

24<br />

25<br />

26 def makeUserCallback(maxtime):<br />

27 def userCallback(caller,<br />

28 douinf,<br />

29 intinf,<br />

30 lintinf):<br />

31 opttime = 0.0<br />

32<br />

33 if caller == callbackcode.begin intpnt:<br />

34 print ("Starting interior-point <strong>optimizer</strong>")<br />

35 elif caller == callbackcode.intpnt:<br />

36 itrn = intinf[iinfitem.intpnt iter ]<br />

37 pobj = douinf[dinfitem.intpnt primal obj]<br />

38 dobj = douinf[dinfitem.intpnt dual obj ]<br />

39 stime = douinf[dinfitem.intpnt time ]<br />

40 opttime = douinf[dinfitem.<strong>optimizer</strong> time ]<br />

41<br />

42 print ("Iterations: %-3d" % itrn)<br />

43 print (" Elapsed time: %6.2f(%.2f) " % (opttime,stime))<br />

44 print (" Primal obj.: %-18.6e Dual obj.: %-18.6e" % (pobj,dobj))<br />

45 elif caller == callbackcode.end intpnt:<br />

46 print ("Interior-point <strong>optimizer</strong> finished.")<br />

47 elif caller == callbackcode.begin primal simplex:<br />

48 print ("Primal simplex <strong>optimizer</strong> started.")<br />

49 elif caller == callbackcode.update primal simplex:<br />

50 itrn = intinf[iinfitem.sim primal iter ]<br />

51 pobj = douinf[dinfitem.sim obj ]<br />

52 stime = douinf[dinfitem.sim time ]<br />

53 opttime = douinf[dinfitem.<strong>optimizer</strong> time ]<br />

54<br />

55 print ("Iterations: %-3d" % itrn)<br />

56 print (" Elapsed time: %6.2f(%.2f)" % (opttime,stime))<br />

57 print (" Obj.: %-18.6e" % pobj )<br />

58 elif caller == callbackcode.end primal simplex:<br />

59 print ("Primal simplex <strong>optimizer</strong> finished.")<br />

60 elif caller == callbackcode.begin dual simplex:<br />

61 print ("Dual simplex <strong>optimizer</strong> started.")<br />

62 elif caller == callbackcode.update dual simplex:<br />

63 itrn = intinf[iinfitem.sim dual iter ]<br />

64 pobj = douinf[dinfitem.sim obj ]<br />

65 stime = douinf[dinfitem.sim time ]<br />

66 opttime = douinf[dinfitem.<strong>optimizer</strong> time ]<br />

67 print ("Iterations: %-3d" % itrn)<br />

68 print (" Elapsed time: %6.2f(%.2f)" % (opttime,stime))<br />

69 print (" Obj.: %-18.6e" % pobj)<br />

70 elif caller == callbackcode.end dual simplex:

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

Saved successfully!

Ooh no, something went wrong!