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.

14.3. FEASIBILITY REPAIR IN <strong>MOSEK</strong> 183<br />

14.3.2 Feasibility repair using the <strong>API</strong><br />

<strong>The</strong> function Task.primalrepair can be used to repair an infeasible problem.<br />

function Task.primalrepair can be seen in the reference.<br />

Details about the<br />

1 #<br />

14.3.2.1 An example<br />

Consider once again the example (14.7) then<br />

[ feasrepairex1.py ]<br />

2 # Copyright: Copyright (c) <strong>MOSEK</strong> ApS, Denmark. All rights reserved.<br />

3 #<br />

4 # File: feasrepairex1.py<br />

5 #<br />

6 # Purpose: To demonstrate how to use the MSK relaxprimal function to<br />

7 # locate the cause of an infeasibility.<br />

8 #<br />

9 # Syntax: On command line<br />

10 # python feasrepairex1.py feasrepair.lp<br />

11 # feasrepair.lp is located in mosek\\tools\examples.<br />

12<br />

13<br />

14 import sys<br />

15 import mosek<br />

16<br />

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

18 # for symbolic purposes:<br />

19 inf = 0.0<br />

20<br />

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

22 def streamprinter(text):<br />

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

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

25<br />

26 def main (inputfile):<br />

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

28 with mosek.Env () as env:<br />

29 with env.Task(0,0) as task:<br />

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

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

32<br />

33 # Read data<br />

34 task.readdata(inputfile)<br />

35<br />

36 task.putintparam(mosek.iparam.log feas repair,3)<br />

37<br />

38 task.primalrepair(None,None,None,None)<br />

39<br />

40 sum viol = task.getdouinf(mosek.dinfitem.primal repair penalty obj)<br />

41 print ("Minimized sum of violations = %e" % sum viol)<br />

42<br />

43 task.optimize()<br />

44<br />

45 task.solutionsummary(mosek.streamtype.msg)<br />

46

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

Saved successfully!

Ooh no, something went wrong!