Initializing help system before first use

Reference Manual

Using this chapter

This chapter provides a list of functions available through the Xpress Python interface. For each function, the synopsis and an example are given.

In keeping with the Xpress Optimizer's C API, the name and order of the parameters used in these functions has been retained. However, in order to make optimal use of the greater flexibility provided by Python, the argument lists and the return value of some functions has been modified so as to obtain a more compact notation.

For example, for functions with a list as an argument, the number of elements of the list is not part of the arguments. Compare the call to the C function XPRSaddrows, where the parameters newrow and newnz must be passed, to its Python counterpart:

(C)      result = XPRSaddrows (prob, n, nnz, type,
                               rhs, NULL, mstart, indices, values);
(Python) p.addrows (type, rhs, None, mstart, indices, values)

In the Python version, the prob pointer is not provided as obviously addrows is a method of the problem class. The C variables n and nnz, which are assigned to arguments newrow and newnz, respectively, of the call to XPRSaddrows, are not necessary in the Python call as the length of rhs, mstart, etc. is inferred from the passed lists. If the lengths of all lists passed as arguments are not consistent with one another, an error will be returned.

Because Python lists (or tuples, generators, iterators, sequences) can be used as parameters of all functions in this manual, their size does not need to be passed explicitly as it is detected from the parameter itself. The interface will check the consistency and the content if the vector is referred to the variables or constraints, and will return an error in case of a mismatch.

When passing (lists, arrays, dictionaries of) variables, constraints, or SOSs, there are three ways of referring to these entities: by numerical index, by Python object, and by name. For instance, consider the problem.getSolution method, which admits both an empty argument and one or a list of variables. If we define a variable with a name as follows

         x = xpress.var (name = 'myvar')
         p = xpress.problem()
         p.addVariable (x)
x"myvar"
         print ('x is ', p.getSolution (x))
         print ('x is ', p.getSolution (0))
         print ('x is ', p.getSolution ('myvar'))

Another difference between the Python methods and their C API counterpart is that some output arguments are no longer passed (by reference) as arguments to the Python functions but rather are (part of) the value returned by the function. Where multiple scalar output parameters are returned by the C API function, some Python functions return a tuple containing all such output values.

The non-scalar parameters can instead be specified as Python lists, NumPy arrays, sequences, or generators when applicable. The output non-scalar parameters are stored as Python lists.

Optional parameters can be specified as None or skipped, provided the subsequent arguments are explicitly declared with their parameter name as Python allows:

p.addrows (qrtype = type, rhs = rhs, mstart = mstart,
                  mclind = indices, dmatval = values)

Because the Python interface relies on the Xpress Optimizer low-level interface, it is advisable to complement the knowledge in this reference manual with that of the Xpress Optimizer reference manual.

Format of the reference

The descriptions in the following pages report, for each function:

  • Name;
  • A short description of its purpose;
  • Its synopsis, i.e., how it must be called. If it returns a value, then it will be presented as an assignment Python command, otherwise it will be just shown as a call without a returned value; also, if it is a module function rather than a problem-specific function, it will be prefixed by xpress;
  • A description of its arguments and whether each argument is optional;
  • Error values;
  • Associated controls;
  • A sample usage of the function;
  • Further useful information about the function;
  • Related functions, parameters.

Note that all arguments defined in the following as "array" can be many other Python non-scalar objects: lists, generators, and NumPy arrays are admissible as parameters, except when specified (e.g. getControl). However, for simplicity we refer to non-scalar arguments as array.

Finally, some attributes and controls are referred to as uppercase words for clarity. For example, ROWS indicates the attribute "rows" of a problem, hence it is equivalent to problem.attributes.rows.

Global methods of the Xpress module

Below is a list of functions that are invoked from the Xpress module, i.e., they are not methods of the problem or the branchobj class and can be invoked after the import command. The invocation is therefore as in the example that follows:


             import xpress as xp
             print (xp.getlasterror ())

    

xpress.init xpress.free xpress.addcbmsghandler
xpress.getbanner xpress.getcheckedmode xpress.getdaysleft
xpress.getlasterror xpress.getlicerrmsg xpress.getversion
xpress.Sum xpress.Dot xpress.setcheckedmode
xpress.removecbmsghandler xpress.setdefaultcontrol xpress.setdefaults

Methods of the problem class

The tables below show all methods of the class problem of the Xpress Python interface, with the exception of callbacks, which are listed separately. Their invocation is therefore to be preceded by a problem object (the class prefix problem. is omitted in the table for compactness), as follows:

      import xpress as xp
      x = xp.var ()
      p = xp.problem ()
      p.setObjective (x + 3 * x**2 + 2)
    

addcols addConstraint addIndicator addmipsol
addqmatrix addrows addSOS addVariable
basisstability btran calcobjective calcreducedcosts
calcslacks calcsolinfo chgbounds chgcoef
chgcoltype chgglblimit chgmcoef chgmqobj
chgobj chgobjsense chgqobj chgqrowcoeff
chgrhs chgrhsrange chgrowtype copy
copycontrols delConstraint delqmatrix delSOS
delVariable dumpcontrols estimaterowdualranges fixglobals
ftran

getAttrib getbasis getcoef getcols
getcoltype getConstraint getControl getdirs
getDual getdualray getglobal getiisdata
getIndex getIndexFromName getindicators getinfeas
getlasterror getlb getlpsol getmessagestatus
getmipsol getmqobj getobj getObjVal
getpivotorder getpivots getpresolvebasis getpresolvemap
getpresolvesol getprimalray getProbStatus getProbStatusString
getqobj getqrowcoeff getqrowqmatrix getqrowqmatrixtriplets
getqrows getRCost getrhs getrhsrange
getrows getrowtype getscaledinfeas getSlack
getSolution getSOS getub getunbvec
getVariable hasdualray hasprimalray

iisall iisclear iisfirst
iisisolations iisnext iisstatus
iiswrite loadbasis loadbranchdirs
loaddelayedrows loaddirs loadlpsol
loadmipsol loadmodelcuts loadpresolvebasis
loadpresolvedirs loadproblem loadsecurevecs
lpoptimize mipoptimize name
objsa postsolve presolverow
read readbasis readbinsol
readdirs readslxsol refinemipsol
repairinfeas repairweightedinfeas repairweightedinfeasbounds
restore reset rhssa
save scale setControl
setdefaults setindicators setlogfile
setmessagestatus setObjective setprobname
solve strongbranch write
writebasis writebinsol writedirs
writeprtsol writeslxsol writesol

The following table contains the problem functions to be called for nonlinear problems.

addcoefs adddfs addtolsets
addvars cascade cascadeorder
chgcascadenlimit chgccoef chgnlcoef
chgdeltatype chgdf chgrowstatus
chgrowwt chgtolset chgvar
construct delcoefs deltolsets
delvars evaluatecoef evaluateformula
filesol fixpenalties getccoef
getcoefformula getcoefs getcolinfo
getdf getdtime getmessagetype
getrowinfo getrowstatus getrowwt
getslpsol gettolset getvar
globalsol loadcoefs loaddfs
loadtolsets loadvars msaddcustompreset
msaddjob msaddpreset msclear
parsecformula parseformula preparseformula
presolve printmemory printevalinfo
printmsg reinitialize scaling
setcurrentiv setuniqueprefix tokencount
unconstruct updatelinearization validformula
validate validatekkt validaterow
validatevector

Methods for branching objects

The following pages present the methods of the branchobj class, i.e., the methods used when creating and manipulating branching objects. Their invocation can be as follows:


           import xpress as xp
           b = xp.branchobj ()
           b.addbranches (3)

    

branchobj.addbounds branchobj.addbranches branchobj.addcuts
branchobj.addrows branchobj.getbounds branchobj.getbranches
branchobj.getid branchobj.getlasterror branchobj.getrows
branchobj.setpreferredbranch branchobj.setpriority branchobj.store
branchobj.validate

Methods for adding/removing callbacks of a problem object

The following pages present methods that can be called from a problem before optimization has started, to add or remove callbacks. All these methods are part of the problem class and have to be instantiated from a problem object.

addcbbariteration removecbbariteration
addcbbarlog removecbbarlog
addcbchgbranchobject removecbchgbranchobject
addcbcutlog removecbcutlog
addcbdestroymt removecbdestroymt
addcbgapnotify removecbgapnotify
addcbgloballog removecbgloballog
addcbinfnode removecbinfnode
addcbintsol removecbintsol
addcblplog removecblplog
addcbmessage removecbmessage
addcbmipthread removecbmipthread
addcbnewnode removecbnewnode
addcbnodecutoff removecbnodecutoff
addcboptnode removecboptnode
addcbpreintsol removecbpreintsol
addcbprenode removecbprenode
addcbusersolnotify removecbusersolnotify

Methods to be used within a callback of a problem object

The following methods can be called from within a callback function that has been passed in one of the problem.addcb* methods. Calling these functions outside of a callback may result in an error and trigger termination of the optimization process. We provide two tables: one is for the Optimizer and another for the nonlinear solvers.

copycallbacks delcpcuts delcuts
getcpcutlist getcpcuts getcutlist
getcutmap getcutslack interrupt
loadcuts setbranchbounds setbranchcuts
storebounds storecuts strongbranchcb
addcuts

setcbcascadeend setcbcascadestart setcbcascadevar
setcbcascadevarfail setcbcoefevalerror setcbconstruct
setcbdestroy setcbdrcol setcbformula
setcbiterend setcbiterstart setcbitervar
setcbmsjobend setcbmsjobstart setcbmswinner
setcbslpend setcbslpnode setcbslpstart