#import module
import mosek
#import numpy arrays or mosek arraystry: from numpy import array,zeros,ones
except ImportError:
from mosek.array import array, zeros, ones
# stream for collect data from MOSEKdef streamprintertext: sys.stdout.flush #main functiondef main (bkc,blc,buc,bkx,blx,bux,csub,cval,asub,acof,ptrb,ptre,niv,ntc): # create mosek environment env = mosek.Env # add stream to environment env.set_Stream mosek.streamtype.log,streamprinter # create task task = env.Task0,0 # add output-data stream to task task.set_Stream mosek.streamtype.log,streamprinter
#there are examples of creation right part of constraints and variable constraints# bkc = mosek.boundkey.up,mosek.boundkey.lo# blc = −inf,−4.0
# buc = 250.0,inf
# bkx = mosek.boundkey.lo,mosek.boundkey.lo
# blx = 0.0,0.0
# bux = inf,inf
#coefficients of goal function# c = 1.0,0.64
#coeff numbers in constraints
# asub = array([0,1), array[0,1] ]
#...and this values
# aval = array([50.0,3.0), array[31.0,−2.0] ]
#number of variables numvar = lenbkx
#number of constraints numcon = lenbkc
# create constraints
task.appendmosek.accmode.con,numcon
# create variables
task.appendmosek.accmode.var,numvar
# The goal function adding csub−numbersofvariables,cval−coefficientsofvariables
task.putcfix0.0 task.putclistcsub,cval
# add constraints task.putboundslice(mosek.accmode.con, 0, numcon,
bkc, blc, buc)
# add variable constraints task.putboundslice(mosek.accmode.var, 0, numvar,
bkx, blx, bux)
# Input non-zero elements of matrix A bycolumn for j in rangenumcon:
aptrb,aptre = ptrbj,ptrej
task.putavecmosek.accmode.con,j,asub[aptrb:aptre],acof[aptrb:aptre]
# input optimize criterion minimize/maximize task.putobjsense(mosek.objsense.minimize) # integer variables numlist=list
typelist=list
for i in rangeniv,numvar:
numlist.appendi
typelist.appendmosek.variabletype.typeint
task.putvartypelistnumlist,typelist
# constants of begin solve task.putintparam(mosek.iparam.mio_construct_sol, mosek.onoffkey.on);
# all variable are unknown in begin of solve task.makesolutionstatusunknown(mosek.soltype.itg);
#we can save task in some file #task.writedata"test.lp" # solve task task.optimize
# output solution
if task.solutiondefmosek.soltype.itg:
...
#import numpy arrays or mosek arraystry: from numpy import array,zeros,ones
except ImportError:
from mosek.array import array, zeros, ones
# stream for collect data from MOSEKdef streamprintertext: sys.stdout.flush #main functiondef main (bkc,blc,buc,bkx,blx,bux,csub,
#there are examples of creation right part of constraints and variable constraints# bkc = mosek.boundkey.up,mosek.boundkey.lo# blc = −inf,−4.0
# buc = 250.0,inf
# bkx = mosek.boundkey.lo,mosek.boundkey.lo
# blx = 0.0,0.0
# bux = inf,inf
#coefficients of goal function# c = 1.0,0.64
#coeff numbers in constraints
# asub = array([0,1), array[0,1] ]
#...and this values
# aval = array([50.0,3.0), array[31.0,−2.0] ]
#number of variables numvar = lenbkx
#number of constraints numcon = lenbkc
# create constraints
task.appendmosek.accmode.con,numcon
# create variables
task.appendmosek.accmode.var,numvar
# The goal function adding csub−numbersofvariables,cval−coefficientsofvariables
task.putcfix0.0 task.putclistcsub,cval
# add constraints task.putboundslice(mosek.
bkc, blc, buc)
# add variable constraints task.putboundslice(mosek.
bkx, blx, bux)
# Input non-zero elements of matrix A bycolumn for j in rangenumcon:
aptrb,aptre = ptrbj,ptrej
task.putavecmosek.accmode.con,j,asub[aptrb:aptre],acof[aptrb:aptre]
# input optimize criterion minimize/maximize task.putobjsense(mosek.
typelist=list
for i in rangeniv,numvar:
numlist.appendi
typelist.appendmosek.variabletype.typeint
task.putvartypelistnumlist,typelist
# constants of begin solve task.putintparam(mosek.iparam.
# all variable are unknown in begin of solve task.
#we can save task in some file #task.writedata"test.lp" # solve task task.optimize
# output solution
if task.solutiondefmosek.soltype.itg:
...