Initializing help system before first use

xpress.vars

xpress.vars


Purpose
Creates an indexed set or map of variables. Similar to the creation of a single variable with xpress.var, vars allows for using one or more index sets, specified as sets, lists, range objects, or any iterable object. Specifying a number k as an argument is equivalent to range(k) but can be used to create NumPy multiarrays of variables, and allows for more efficient creation. The result is otherwise a Python dictionary of variables, whose keys are tuple of indices. A collection of variables x that is created with vars can be indexed, for instance, as x[i,j] where i and j are indices in the lists provided.
Synopsis
x = xpress.vars(*indices, name="x", lb=0, ub=xpress.infinity, threshold=0, vartype=xpress.continuous)
Arguments
indices 
One or more lists, sets, ranges, or iterable objects to be combined; in alternative, one can specify one or more numbers k to signify the range 0..k-1. Using only numbers as argument will yield a NumPy multiarray with the dimensions as specified by the arguments themselves.
name 
Prefix name for each variable, to be amended with the tuple of indices.
lb 
Lower bound for all variables in the map.
ub 
Upper bound for all variables in the map.
threshold 
Threshold for all variables in the map; only used if the variables are partially integer.
vartype 
Type of all variables in the map, similar to the definition of single variables.
Example
The following creates a variable map with 6 variables whose indices vary in the set {(0,'a'),(0,'b'),(0,'c'),(1,'a'),(1,'b'),(1,'c')}:
x = xpress.vars([0,1],['a','b','c'])
The following creates a variable map with 6 variables whose indices vary in the set {(0,0),(0,1),(0,2),(1,0),(1,1),(1,2)}:
x = xpress.vars(2,3)
The code below creates a variable map with 5 integer variables with names 'y(a)', 'y(b)', 'y(c)', 'y(d)', 'y(e)' and creates a constraint to bound their sum:
x = xpress.vars(['a','b','c','d','e'],
name='y', vartype=xpress.integer)
con1 = xpress.Sum(x) <= 4
The code below creates a variable map using the range operator in Python:
x = xpress.vars(range(5),
name='y', vartype=xpress.integer)
con1 = xpress.Sum(x) <= 4
The following example creates a Numpy multiarray of dimensions 3,7,4 with default (i.e., interface-provided) names:
x = xpress.vars(3,7,4, name="", lb=-1, ub=1)
Note that specifying anything other than a number yields a dictionary rather than a Numpy multiarray. The above mode can be used when creating large arrays of variables because specifying name="" allows for more efficient creation.
Finally, the following creates a variable indexed by the set defined right before:
S = set()
S.add('john')
S.add('cleese')
x = xpress.vars(S, name='y', vartype=xpress.integer)
Further information
All lists must contain non-repeated elements to avoid having variables with equal names. If a list in the argument is, for instance, ['a','b','a'], an error is returned.
Related topics
xpress.var