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

Optimizer API for Python - Documentation - Mosek Optimizer API for Python - Documentation - Mosek

25.11.2015 Views

34 CHAPTER 5. BASIC API TUTORIAL 109 xx = zeros(numvar, float) 110 task.getxx(mosek.soltype.bas, 111 xx) 112 113 if solsta == mosek.solsta.optimal or solsta == mosek.solsta.near optimal: 114 print("Optimal solution: %s" % xx) 115 elif solsta == mosek.solsta.dual infeas cer: 116 print("Primal or dual infeasibility.\n") 117 elif solsta == mosek.solsta.prim infeas cer: 118 print("Primal or dual infeasibility.\n") 119 elif solsta == mosek.solsta.near dual infeas cer: 120 print("Primal or dual infeasibility.\n") 121 elif solsta == mosek.solsta.near prim infeas cer: 122 print("Primal or dual infeasibility.\n") 123 elif mosek.solsta.unknown: 124 print("Unknown solution status") 125 else: 126 print("Other solution status") 127 128 # call the main function 129 try: 130 main () 131 except mosek.Exception as e: 132 print ("ERROR: %s" % str(e.code)) 133 if msg is not None: 134 print ("\t%s" % e.msg) 135 sys.exit(1) 136 except: 137 import traceback 138 traceback.print exc() 139 sys.exit(1) 140 sys.exit(0) 5.3 Conic quadratic optimization Conic optimization is a generalization of linear optimization, allowing constraints of the type x t ∈ C t , where x t is a subset of the problem variables and C t is a convex cone. Actually, since the set R n of real numbers is also a convex cone, all variables can in fact be partitioned into subsets belonging to separate convex cones, simply stated x ∈ C. MOSEK can solve conic quadratic optimization problems of the form minimize c T x + c f subject to l c ≤ Ax ≤ u c , l x ≤ x ≤ u x , x ∈ C, where the domain restriction, x ∈ C, implies that all variables are partitioned into convex cones (5.4)

5.3. CONIC QUADRATIC OPTIMIZATION 35 x = (x 0 , x 1 , . . . , x p−1 ), with x t ∈ C t ⊆ R nt . For convenience, the user only specify subsets of variables x t belonging to cones C t different from the set R nt of real numbers. These cones can be a: • Quadratic cone: ⎧ ⎨ Q n = ⎩ x ∈ Rn : x 0 ≥ √ n−1 ∑ j=1 x 2 j ⎫ ⎬ ⎭ . • Rotated quadratic cone: ⎧ ⎨ Q r n = ⎩ x ∈ Rn : 2x 0 x 1 ≥ ⎫ n−1 ∑ ⎬ x 2 j, x 0 ≥ 0, x 1 ≥ 0 ⎭ . j=2 From these definition it follows that (x 4 , x 0 , x 2 ) ∈ Q 3 , is equivalent to x 4 ≥ √ x 2 0 + x2 2 . Furthermore, each variable may belong to one cone at most. The constraint x i −x j = 0 would however allow x i and x j to belong to different cones with same effect. 5.3.1 Example: Conic quadratic optimization The problem minimize x 3 + x 4 + x 5 subject to x 0 + x 1 + 2x 2 = 1, x 0 √ , x 1 , x 2 ≥ 0, x 3 ≥ x 2 0 + x2 1 , 2x 4 x 5 ≥ x 2 2. (5.5) is an example of a conic quadratic optimization problem. The problem includes a set of linear constraints, a quadratic cone and a rotated quadratic cone.

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

109 xx = zeros(numvar, float)<br />

110 task.getxx(mosek.soltype.bas,<br />

111 xx)<br />

112<br />

113 if solsta == mosek.solsta.optimal or solsta == mosek.solsta.near optimal:<br />

114 print("Optimal solution: %s" % xx)<br />

115 elif solsta == mosek.solsta.dual infeas cer:<br />

116 print("Primal or dual infeasibility.\n")<br />

117 elif solsta == mosek.solsta.prim infeas cer:<br />

118 print("Primal or dual infeasibility.\n")<br />

119 elif solsta == mosek.solsta.near dual infeas cer:<br />

120 print("Primal or dual infeasibility.\n")<br />

121 elif solsta == mosek.solsta.near prim infeas cer:<br />

122 print("Primal or dual infeasibility.\n")<br />

123 elif mosek.solsta.unknown:<br />

124 print("Unknown solution status")<br />

125 else:<br />

126 print("Other solution status")<br />

127<br />

128 # call the main function<br />

129 try:<br />

130 main ()<br />

131 except mosek.Exception as e:<br />

132 print ("ERROR: %s" % str(e.code))<br />

133 if msg is not None:<br />

134 print ("\t%s" % e.msg)<br />

135 sys.exit(1)<br />

136 except:<br />

137 import traceback<br />

138 traceback.print exc()<br />

139 sys.exit(1)<br />

140 sys.exit(0)<br />

5.3 Conic quadratic optimization<br />

Conic optimization is a generalization of linear optimization, allowing constraints of the type<br />

x t ∈ C t ,<br />

where x t is a subset of the problem variables and C t is a convex cone. Actually, since the set R n of<br />

real numbers is also a convex cone, all variables can in fact be partitioned into subsets belonging to<br />

separate convex cones, simply stated x ∈ C.<br />

<strong>MOSEK</strong> can solve conic quadratic optimization problems of the form<br />

minimize<br />

c T x + c f<br />

subject to l c ≤ Ax ≤ u c ,<br />

l x ≤ x ≤ u x ,<br />

x ∈ C,<br />

where the domain restriction, x ∈ C, implies that all variables are partitioned into convex cones<br />

(5.4)

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

Saved successfully!

Ooh no, something went wrong!