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

52 CHAPTER 5. BASIC API TUTORIAL 139 print("Other solution status") 140 141 # call the main function 142 try: 143 main () 144 except mosek.Exception as e: 145 print ("ERROR: %s" % str(code)) 146 if msg is not None: 147 print ("\t%s" % e.msg) 148 sys.exit(1) 149 except: 150 import traceback 151 traceback.print exc() 152 sys.exit(1) 153 sys.exit(0) The only new function introduced in this example is Task.putqconk, which is used to add quadratic terms to the constraints. While Task.putqconk add quadratic terms to a specific constraint, it is also possible to input all quadratic terms in all constraints in one chunk using the Task.putqcon function. 5.6 The solution summary All computations inside MOSEK are performed using finite precision floating point numbers. This implies the reported solution isonly be an approximate optimal solution. Therefore after solving an optimization problem it is important to investigate how good an approximation the solution is. This can easily be done using the function Task.solutionsummary which reports how much the solution violate the primal and dual constraints and the primal and dual objective values. Recall for a convex optimization problem the optimality conditions are: • The primal solution must satisfy all the primal constraints. • The dual solution much satisfy all the dual constraints. • The primal and dual objective values must be identical. Thus the solution summary reports information that makes it possible to evaluate the quality of the solution obtained. In case of a linear optimization problem the solution summary may look like Basic solution summary Problem status : PRIMAL AND DUAL FEASIBLE Solution status : OPTIMAL Primal. obj: -4.6475314286e+002 Viol. con: 2e-014 var: 0e+000 Dual. obj: -4.6475316001e+002 Viol. con: 7e-009 var: 4e-016 The summary reports information for the basic solution. In this case we see: • The problem status is primal and dual feasible which means the problem has an optimal solution. The problem status can be obtained using Task.getprosta.

5.6. THE SOLUTION SUMMARY 53 • The solution status is optimal. The solution status can be obtained using Task.getsolsta. • Next information about the primal solution is reported. The information consists of the objective value and violation meassures for the primal solution. In this case violations for the constraints and variables are small meaning the solution is very close to being an exact feasible solution. The violation meassure for the variables is the worst violation of the solution in any of the bounds on the variables. The constraint and variable violations are computed with Task.getpviolcon and Task.getpviolvar. • Similarly for the dual solution the violations are small and hence the dual solution is feasible. The constraint and variable violations are computed with Task.getdviolcon and Task.getdviolvar respectively. • Finally, it can be seen that the primal and dual objective values are almost identical. Using Task.getprimalobj and Task.getdualobj the primal and dual objective values can be obtained. To summarize in this case a primal and a dual solution with small feasiblity violations are available. Moreover, the primal and dual objective values are almost identical and hence it can be concluded that the reported solution is a good approximation to the optimal solution. Now what happens if the problem does not have an optimal solution e.g. it is primal infeasible. In that case the solution summary may look like Basic solution summary Problem status : PRIMAL INFEASIBLE Solution status : PRIMAL INFEASIBLE CER Dual. obj: 3.5894503823e+004 Viol. con: 0e+000 var: 2e-008 i.e. MOSEK reports that the solution is a certificate of primal infeasibility. Since the problem is primal infeasible it does not make sense to report any information about the primal solution. However, the dual solution should be a certificate of the primal infeasibility. If the problem is a minimization problem then the dual objective value should be positive and in the case of a maximization problem it should be negative. The quality of the certificate can be evaluated by comparing the dual objective value to the violations. Indeed if the objective value is large compared to the largest violation then the certificate highly accurate. Here is an example Basic solution summary Problem status : PRIMAL INFEASIBLE Solution status : PRIMAL INFEASIBLE CER Dual. obj: 3.0056574100e-005 Viol. con: 9e-013 var: 2e-011 of a not so strong infeasibility certificate because the dual objective value is small compared to largest violation. In the case a problem is dual infeasible then the solution summary may look like Basic solution summary Problem status : DUAL INFEASIBLE Solution status : DUAL INFEASIBLE CER Primal. obj: -1.4500853392e+001 Viol. con: 0e+000 var: 0e+000 Observe when a solution is a certificate of dual infeasibility then the primal solution contains the certificate. Moreoever, given the problem is a minimization problem the objective value should negative and the objective should be large compared to the worst violation if the certificate is strong.

5.6. THE SOLUTION SUMMARY 53<br />

• <strong>The</strong> solution status is optimal. <strong>The</strong> solution status can be obtained using Task.getsolsta.<br />

• Next information about the primal solution is reported. <strong>The</strong> information consists of the objective<br />

value and violation meassures for the primal solution. In this case violations for the constraints<br />

and variables are small meaning the solution is very close to being an exact feasible solution. <strong>The</strong><br />

violation meassure for the variables is the worst violation of the solution in any of the bounds<br />

on the variables.<br />

<strong>The</strong> constraint and variable violations are computed with Task.getpviolcon and Task.getpviolvar.<br />

• Similarly for the dual solution the violations are small and hence the dual solution is feasible. <strong>The</strong><br />

constraint and variable violations are computed with Task.getdviolcon and Task.getdviolvar<br />

respectively.<br />

• Finally, it can be seen that the primal and dual objective values are almost identical. Using<br />

Task.getprimalobj and Task.getdualobj the primal and dual objective values can be obtained.<br />

To summarize in this case a primal and a dual solution with small feasiblity violations are available.<br />

Moreover, the primal and dual objective values are almost identical and hence it can be concluded<br />

that the reported solution is a good approximation to the optimal solution.<br />

Now what happens if the problem does not have an optimal solution e.g. it is primal infeasible. In<br />

that case the solution summary may look like<br />

Basic solution summary<br />

Problem status : PRIMAL INFEASIBLE<br />

Solution status : PRIMAL INFEASIBLE CER<br />

Dual. obj: 3.5894503823e+004 Viol. con: 0e+000 var: 2e-008<br />

i.e. <strong>MOSEK</strong> reports that the solution is a certificate of primal infeasibility. Since the problem is primal<br />

infeasible it does not make sense to report any information about the primal solution. However, the<br />

dual solution should be a certificate of the primal infeasibility. If the problem is a minimization problem<br />

then the dual objective value should be positive and in the case of a maximization problem it should be<br />

negative. <strong>The</strong> quality of the certificate can be evaluated by comparing the dual objective value to the<br />

violations. Indeed if the objective value is large compared to the largest violation then the certificate<br />

highly accurate. Here is an example<br />

Basic solution summary<br />

Problem status : PRIMAL INFEASIBLE<br />

Solution status : PRIMAL INFEASIBLE CER<br />

Dual. obj: 3.0056574100e-005 Viol. con: 9e-013 var: 2e-011<br />

of a not so strong infeasibility certificate because the dual objective value is small compared to largest<br />

violation.<br />

In the case a problem is dual infeasible then the solution summary may look like<br />

Basic solution summary<br />

Problem status : DUAL INFEASIBLE<br />

Solution status : DUAL INFEASIBLE CER<br />

Primal. obj: -1.4500853392e+001 Viol. con: 0e+000 var: 0e+000<br />

Observe when a solution is a certificate of dual infeasibility then the primal solution contains the<br />

certificate. Moreoever, given the problem is a minimization problem the objective value should negative<br />

and the objective should be large compared to the worst violation if the certificate is strong.

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

Saved successfully!

Ooh no, something went wrong!