Initializing help system before first use

Reference Manual

Topics covered in this chapter:

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)

As of version 8.12, the names in the C API have undergone a change in order to have more expressive names in the C API. The Python API was updated accordingly. The old names still work but are now deprecated. This reference documentation and all error messages refer to the new names.

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 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

p = xpress.problem()
x = p.addVariable(name='myvar')
then we can refer to its index (which will be 0 here as it is the first variable added to the problem), by its object name, i.e., x, and by its given name "myvar", in the three following (equivalent) ways:
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 lists, NumPy arrays, sequences, or generators when applicable. The output non-scalar parameters are stored as 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(rowtype=type, rhs=rhs, start=mstart,
           colind=indices, rowcoef=values)

Because the Python interface relies on the Xpress Optimizer C Application Program 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 a Python assignment statement, 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 remainder of this chapter as "array" or "vector" 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.

Classes of the Xpress module

Below is a list of classes used in all operations of the xpress module. While for a few of these classes an explicit constructor exists (for instance, xpress.problem and xpress.sos), objects of other classes, like xpress.linterm and xpress.expression, cannot be created with a constructor methods but are created using algebraic operators applied to constants, variables, and other expressions.

xpress.attr xpress.branchobj xpress.ctrl
xpress.constraint xpress.expression xpress.linterm
xpress.nonlin xpress.problem xpress.poolcut
xpress.quadterm xpress.sos xpress.var
xpress.voidstar xpress.xprsobject

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 statement. 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.getversionnumbers xpress.Sum xpress.Dot
xpress.setcheckedmode xpress.And xpress.Or
xpress.pwl xpress.setdefaultcontrol xpress.setdefaults
xpress.featurequery xpress.removecbmsghandler xpress.setarchconsistency
xpress.manual xpress.examples xpress.getcomputeallowed
xpress.setcomputeallowed

Methods of the class problem

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
p = xp.problem()
x = p.addVariable()
p.setObjective(x + 3 * x**2 + 2)
    

addcols addConstraint addgencons addIndicator
addmipsol addnames addObjective addpwlcons
addqmatrix addrows addsetnames addSOS
addVariable basisstability btran calcobjective
calcreducedcosts calcslacks calcsolinfo chgbounds
chgcoef chgcoltype chgglblimit chgmcoef
chgmqobj chgobj chgobjsense chgqobj
chgqrowcoeff chgrhs chgrhsrange chgrowtype
copy copycontrols crossoverlpsol delConstraint
delgencons delpwlcons delqmatrix delSOS
delVariable dumpcontrols estimaterowdualranges fixmipentities
ftran

getAttrib getbasis getbasisval getCallbackDuals
getCallbackSlacks getCallbackSolution getCallbackRedCosts getCallbackPresolveDuals
getCallbackPresolveSlacks getCallbackPresolveSolution getCallbackPresolveRedcosts getcoef
getcols getcoltype getConstraint getControl
getdirs getDuals getdualray getgencons
getmipentities getiisdata getIndex getIndexFromName
getindicators getinfeas getlastbarsol getlasterror
getlb getlpsol getlpsolval getmessagestatus
getmipsol getmipsolval getmqobj getnamelist
getobj getObjVal getOutputEnabled getpivotorder
getpivots getpresolvebasis getpresolvemap getpresolvesol
getprimalray getProbStatus getProbStatusString getpwlcons
getqobj getqrowcoeff getqrowqmatrix getqrowqmatrixtriplets
getqrows getRedCosts getrhs getrhsrange
getrows getrowtype getscaledinfeas getSlacks
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 optimize postsolve
presolverow read readbasis readbinsol
readdirs readslxsol refinemipsol repairinfeas
repairweightedinfeas repairweightedinfeasbounds restore reset
rhssa save scale setControl
setdefaults setindicators setlogfile setmessagestatus
setObjective setOutputEnabled setprobname strongbranch
tune tuneprobsetfile tunerreadmethod tunerwritemethod
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 chgdeltatype chgdf
chgrowstatus chgrowwt chgtolset
chgvar construct delcoefs
deltolsets delvars evaluatecoef
evaluateformula fixpenalties getcoefformula
getcoefs getcolinfo getdf
getrowinfo getrowstatus getrowwt
getslpsol gettolset getvar
loadcoefs loaddfs loadtolsets
loadvars msaddcustompreset msaddjob
msaddpreset msclear nlpchgformula
nlpchgformulastr nlpgetformula nlpgetformulastr
nlpsetinitval presolve printmemory
printevalinfo reinitialize scaling
setcurrentiv slpchgcoef slpchgcoefstr
slpgetcoefformula slpgetcoefstr unconstruct
updatelinearization 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
addcbchecktime removecbchecktime
addcbcutlog removecbcutlog
addcbdestroymt removecbdestroymt
addcbgapnotify removecbgapnotify
addcbmiplog removecbmiplog
addcbinfnode removecbinfnode
addcbintsol removecbintsol
addcblplog removecblplog
addcbmessage removecbmessage
addcbmipthread removecbmipthread
addcbnewnode removecbnewnode
addcbnodecutoff removecbnodecutoff
addcbnodelpsolved removecbnodelpsolved
addcboptnode removecboptnode
addcbpreintsol removecbpreintsol
addcbprenode removecbprenode
addcbusersolnotify removecbusersolnotify
addcbbeforeobjective removecbbeforeobjective
addcbafterobjective removecbafterobjective

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 storecuts strongbranchcb
addcuts

setcbcascadeend setcbcascadestart setcbcascadevar
setcbcascadevarfail setcbcoefevalerror setcbconstruct
setcbdestroy setcbdrcol setcbintsol
setcbiterend setcbiterstart setcbitervar
setcbmessage setcbmsjobend setcbmsjobstart
setcbmswinner setcboptnode setcbprenode
setcbpreupdatelinearization setcbslpend setcbslpnode
setcbslpstart

© 2001-2024 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.