Initializing help system before first use

Accessing controls and attributes as object members

An alternative, more "prompt-friendly" way to get controls and attributes is through their direct access in a problem or, in the case of controls, the Xpress module itself.

The Xpress module has an object, called controls, containing all controls of the Optimizer. Upon importing the Xpress module, these controls are initialized at their default value. The user can obtain their value at any point and can also set their value; this new value will be inherited by all problems created after the modification. They can be read and written as follows:

xpress.controls.<controlname>
xpress.controls.<controlname> = <new value>

For example, the object xpress.controls.miprelstop contains the value of the control miprelstop. Controls can be read (and, for example, printed) and set as follows:

import xpress as xp
print(xp.controls.heurstrategy)
xp.controls.feastol = 1e-4 # Set new default to 1e-4

These "global" controls are maintained throughout while the Xpress module is loaded. Note that the controls object of the Xpress module does not refer to any specific problem. All controls have default values that are determined by the Optimizer's library, except for the control xslp_postsolve that is set to 1, as opposed to its default value of 0 in the Xpress Optimizer's library.

In addition, every problem has a controls object that stores the controls related to the problem itself. This is the object the functions getControl and setControl refer to. Similar to the Xpress module's controls object, all members of a problem's object can be read and written. For a problem p, the following shows how to read and write a problem's control:

p.controls.<controlname>
p.controls.<controlname> = <new value>

A problem's controls are independent of the global controls object of the Xpress module. However, when a new problem is created its controls are copied from the current values in the global object. Note that after creating a new problem, changing the members in xpress.controls does not affect the problem's controls. The following examples should clarify this:

import xpress as xp

# create a new problem whose MIPRELSTOP is ten times smaller
# than the default value

p1 = xp.problem("problem1")
p1.controls.miprelstop = 0.1 * xp.controls.miprelstop
p1.controls.feastol = 1e-5
p1.read("example1.lp")

xp.controls.miprelstop = 1e-8 # Set new default

# The new problem will have a MIPRELSTOP of 1e-8

p2 = xp.problem("problem2")
p2.read("example2.lp")

# The next problem has a less restrictive feasibility tolerance
# (i.e. 1e-6) than problem 2

p2v = xp.problem("problem2 variant")
p2v.read("example2.lp")
p2v.controls.feastol = 100 * p2.controls.feastol

p1.solve()
p2.solve()

# solve "example2.lp" with a less restrictive
# feasibility tolerance
p2v.solve()

Attributes can be handled similar as above through a member of the class problem, called attributes, with two exceptions: first, there is no "global" attribute object, as a set of attributes only makes sense when associated with a problem; second, an attribute cannot be set.

Once a problem p has been created (or read from a file), its attributes are available as p.attribute.attribute_name. The example in the previous section can be modified as follows:

import xpress as xp
p = xp.problem()
p.read("example.lp")
print("The problem has",
    p.attributes.rows, "rows and",
    p.attributes.cols, "columns")

When using the Python prompt in creating problems with the Xpress module, the name of controls and attributes can be auto-completed by pressing TAB (note: this only works in Python 3.4 and subsequent versions). For instance,

>>> import xpress
>>> p = xp.problem()
>>> p.read("example.lp")
>>> p.attributes.n<TAB>
p.attributes.namelength  p.attributes.nodedepth   p.attributes.nodes  p.attributes.numiis
>>> p.attributes.nodedepth
0
>>> p.attributes.ma<TAB>
p.attributes.matrixname          p.attributes.maxabsdualinfeas
p.attributes.maxabsprimalinfeas  p.attributes.maxprobnamelength
p.attributes.maxreldualinfeas    p.attributes.maxrelprimalinfeas
>>> p.attributes.matrixname
'noname'
>>> xp.controls.o<TAB>
xp.controls.oldnames             xp.controls.omniformat
xp.controls.optimalitytol        xp.controls.optimalitytoltarget
xp.controls.outputlog            xp.controls.outputmask
xp.controls.outputtol
>>> xp.controls.omniformat
0