The MOSEK Python optimizer API manual Version 7.0 (Revision 141)
Optimizer API for Python - Documentation - Mosek Optimizer API for Python - Documentation - Mosek
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.
- Page 23 and 24: Contact information Phone +45 3917
- Page 25 and 26: License agreement Before using the
- Page 27 and 28: Chapter 1 Changes and new features
- Page 29 and 30: 1.4. API CHANGES 7 1.3.3 Mixed-inte
- Page 31 and 32: 1.10. SUMMARY OF API CHANGES 9 •
- Page 33 and 34: 1.10. SUMMARY OF API CHANGES 11 •
- Page 35 and 36: 1.10. SUMMARY OF API CHANGES 13 •
- Page 37 and 38: Chapter 2 About this manual This ma
- Page 39 and 40: Chapter 3 Getting support and help
- Page 41 and 42: Chapter 4 Testing installation and
- Page 43 and 44: Chapter 5 Basic API tutorial In thi
- Page 45 and 46: 5.1. THE BASICS 23 5 # 6 # Purpose:
- Page 47 and 48: 5.2. LINEAR OPTIMIZATION 25 and the
- Page 49 and 50: 5.2. LINEAR OPTIMIZATION 27 Load a
- Page 51 and 52: 5.2. LINEAR OPTIMIZATION 29 Optimiz
- Page 53 and 54: 5.2. LINEAR OPTIMIZATION 31 88 task
- Page 55 and 56: 5.2. LINEAR OPTIMIZATION 33 51 mose
- Page 57 and 58: 5.3. CONIC QUADRATIC OPTIMIZATION 3
- Page 59 and 60: 5.3. CONIC QUADRATIC OPTIMIZATION 3
- Page 61 and 62: 5.4. SEMIDEFINITE OPTIMIZATION 39 m
- Page 63 and 64: 5.4. SEMIDEFINITE OPTIMIZATION 41 4
- Page 65 and 66: 5.4. SEMIDEFINITE OPTIMIZATION 43 1
- Page 67 and 68: 5.5. QUADRATIC OPTIMIZATION 45 with
- Page 69 and 70: 5.5. QUADRATIC OPTIMIZATION 47 68 #
- Page 71 and 72: 5.5. QUADRATIC OPTIMIZATION 49 5.5.
- Page 73: 5.5. QUADRATIC OPTIMIZATION 51 81 a
- Page 77 and 78: 5.7. INTEGER OPTIMIZATION 55 21 # f
- Page 79 and 80: 5.7. INTEGER OPTIMIZATION 57 137 sy
- Page 81 and 82: 5.8. THE SOLUTION SUMMARY FOR MIXED
- Page 83 and 84: 5.9. RESPONSE HANDLING 61 Note that
- Page 85 and 86: 5.10. PROBLEM MODIFICATION AND REOP
- Page 87 and 88: 5.10. PROBLEM MODIFICATION AND REOP
- Page 89 and 90: 5.11. SOLUTION ANALYSIS 67 151 # Pu
- Page 91 and 92: 5.13. CONVENTIONS EMPLOYED IN THE A
- Page 93 and 94: 5.13. CONVENTIONS EMPLOYED IN THE A
- Page 95 and 96: 5.13. CONVENTIONS EMPLOYED IN THE A
- Page 97 and 98: 5.13. CONVENTIONS EMPLOYED IN THE A
- Page 99 and 100: Chapter 6 Nonlinear API tutorial Th
- Page 101 and 102: 6.1. SEPARABLE CONVEX (SCOPT) INTER
- Page 103 and 104: 6.1. SEPARABLE CONVEX (SCOPT) INTER
- Page 105 and 106: 6.1. SEPARABLE CONVEX (SCOPT) INTER
- Page 107 and 108: Chapter 7 Advanced API tutorial Thi
- Page 109 and 110: 7.1. THE PROGRESS CALL-BACK 87 71 p
- Page 111 and 112: 7.2. SOLVING LINEAR SYSTEMS INVOLVI
- Page 113 and 114: 7.2. SOLVING LINEAR SYSTEMS INVOLVI
- Page 115 and 116: 7.2. SOLVING LINEAR SYSTEMS INVOLVI
- Page 117 and 118: 7.2. SOLVING LINEAR SYSTEMS INVOLVI
- Page 119 and 120: Chapter 8 A case study 8.1 Portfoli
- Page 121 and 122: 8.1. PORTFOLIO OPTIMIZATION 99 e T
- Page 123 and 124: 8.1. PORTFOLIO OPTIMIZATION 101 is
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.