## # Copyright : MOSEK ApS # # File : rmt.py # # Purpose : Template for use with solve.mosek.com ## import mosek import sys def streamprinter(msg): sys.stdout.write(msg) sys.stdout.flush() # Create the mosek environment. with mosek.Env() as env: # Create a task object linked with the environment env. with env.Task(0, 0) as task: # Log stream task.set_Stream(mosek.streamtype.log, streamprinter) # Set up the URL of the OptServer task.putoptserverhost("http://solve.mosek.com:30080") ## SET UP THE OPTIMIZATION PROBLEM HERE # Trivial test problem task.appendvars(1) task.putcj(0, 1.0) task.putvarbound(0,mosek.boundkey.ra, 2.0, 3.0) task.putobjsense(mosek.objsense.minimize) ## END PROBLEM SETUP # Optimize try: trm = task.optimize() except mosek.Error as e: symname, desc = mosek.Env.getcodedesc(e.errno) print("Error during optimize: {0} {1}".format(symname, desc)) if e.errno == mosek.rescode.err_server_problem_size: print("Error: the problem was too big for the demo server.") sys.exit(e.errno) if trm == mosek.rescode.trm_user_callback: print("Note: the demo server time limit was reached.") # Print a summary of the solution task.solutionsummary(mosek.streamtype.log) # Proceed to fetch the solution # ...