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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

152 CHAPTER 11. THE OPTIMIZERS FOR CONTINUOUS PROBLEMS<br />

# for symbolic purposes:<br />

inf = 0.0<br />

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

class streamprinter:<br />

def init (self,prefix):<br />

self.prefix = str(prefix)<br />

def call (self,text):<br />

#sys.stdout.write (self.prefix + text)<br />

sys.stdout.write (self.prefix + text)<br />

sys.stdout.flush()<br />

pass<br />

# We might write everything directly as a script, but it looks nicer<br />

# to create a function.<br />

def main (args):<br />

# Open <strong>MOSEK</strong> and create an environment and task<br />

# Create a <strong>MOSEK</strong> environment<br />

env = mosek.Env ()<br />

# Attach a printer to the environment<br />

env.set Stream (mosek.streamtype.log, streamprinter("[env]"))<br />

# Create a task<br />

task = env.Task(0,0)<br />

# Attach a printer to the task<br />

task.set Stream (mosek.streamtype.log, streamprinter("simplex: "))<br />

# Create a task<br />

task list = [env.Task(0,0)]<br />

# Attach a printer to the task<br />

task list[0].set Stream(mosek.streamtype.log, streamprinter("intpnt: "))<br />

task.readdata(args[0]);<br />

# Assign different parameter values to each task.<br />

# In this case different <strong>optimizer</strong>s.<br />

task.putintparam(mosek.iparam.<strong>optimizer</strong>,<br />

mosek.<strong>optimizer</strong>type.primal simplex)<br />

task list[0].putintparam(mosek.iparam.<strong>optimizer</strong>,<br />

mosek.<strong>optimizer</strong>type.intpnt)<br />

# Optimize task and task list[0] in parallel.<br />

# <strong>The</strong> problem data i.e. C, A, etc.<br />

# is copied from task to task list[0].<br />

task.optimizeconcurrent(task list)<br />

task.solutionsummary(mosek.streamtype.log)<br />

# call the main function<br />

try:<br />

main (sys.argv[1:])<br />

except mosek.Exception as e:<br />

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

if e.msg is not None:<br />

print ("\t%s" % e.msg)

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

Saved successfully!

Ooh no, something went wrong!