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

368 APPENDIX A. API REFERENCE A.3.12 Env.putlicensepath() Env.putlicensepath(licensepath) Set the path to the license file. Arguments licensepath : str A path specifycing where to search for the license. Description: Set the path to the license file. A.3.13 Env.putlicensewait() Env.putlicensewait(licwait) Control whether mosek should wait for an available license if no license is available. Arguments licwait : int If this argument is non-zero, then MOSEK will wait for a license if no license is available. Moreover, licwait-1 is the number of milliseconds to wait between each check for an available license. Description: If licwait is non-zero, then MOSEK will wait for a license if no license is available. Moreover, licwait-1 is the number of milliseconds to wait between each check for an available license. A.4 Callback functions and related methods Callbacks from task methods are performed by attaching a function to the task object. A.4.1 Progress callback When MOSEK is optimizing or doing other tasks that may potentially take a long time, it is possible to recieve periodical calls from MOSEK indicating the current status. This achieved by attaching a callback handler to the task. A callback handler is simply a function that accepts one integer argument and returns an integer.

A.4. CALLBACK FUNCTIONS AND RELATED METHODS 369 The argument is an integer indicating the current location in MOSEK. If the function returns a nonzero value or raises an exception, MOSEK will attempt to stop the current task and return as fast as possible. def myCallback(caller, dinf, iinf, liinf): print "Caller : %d, intpnt iteration = %d" % (caller, iinf[iinfitem.intpnt iter]) return 0 task.set Progress(myCallback) The arguments dinf, iinf and liinf are arrays of values containing information items for the current state of the solver. The Progress callback can be detached by calling task.set Progress(None) NOTE: Due to the way the Python garbage collector works, it is necessary to hold a reference to the callback function for the duration of the lifetime of the Task object. This means that a construction as #NOTE: WRONG way to attach callback! task.set Progress(lambda caller, dinf, iinf, liinf: print "Caller : %d" % caller) will not work. A.4.2 Stream callback Text written to specific MOSEK streams can be intercepted by attaching a stream handler to the specific stream. A stream handler is simply a function that accepts one string argument. To attach a stream callback to a Task, use: def myStream(msg): sys.stdout.write(msg) sys.stdout.flush() task.set Stream(streamtype.log,myStream) The Stream object can be detached by calling task.set Stream(None) In this example we attached to the log stream; see streamtype for other options. NOTE: As for Progress callbacks, it is necessary to hold a reference to the callback function for the duration of the lifetime of the Task or ttEnv object.

368 APPENDIX A. <strong>API</strong> REFERENCE<br />

A.3.12<br />

Env.putlicensepath()<br />

Env.putlicensepath(licensepath)<br />

Set the path to the license file.<br />

Arguments<br />

licensepath : str<br />

A path specifycing where to search for the license.<br />

Description:<br />

Set the path to the license file.<br />

A.3.13<br />

Env.putlicensewait()<br />

Env.putlicensewait(licwait)<br />

Control whether mosek should wait for an available license if no license is available.<br />

Arguments<br />

licwait : int<br />

If this argument is non-zero, then <strong>MOSEK</strong> will wait for a license if no license is available.<br />

Moreover, licwait-1 is the number of milliseconds to wait between each check for an<br />

available license.<br />

Description:<br />

If licwait is non-zero, then <strong>MOSEK</strong> will wait for a license if no license is available. Moreover,<br />

licwait-1 is the number of milliseconds to wait between each check for an available license.<br />

A.4 Callback functions and related methods<br />

Callbacks from task methods are performed by attaching a function to the task object.<br />

A.4.1<br />

Progress callback<br />

When <strong>MOSEK</strong> is optimizing or doing other tasks that may potentially take a long time, it is possible<br />

to recieve periodical calls from <strong>MOSEK</strong> indicating the current status. This achieved by attaching a<br />

callback handler to the task. A callback handler is simply a function that accepts one integer argument<br />

and returns an integer.

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

Saved successfully!

Ooh no, something went wrong!