Package cplex :: Package _internal :: Module _subinterfaces :: Class AdvancedVariablesInterface
 

Class AdvancedVariablesInterface


Methods for advanced operations on variables.
Instance Methods
 
__init__(self, parent)
Creates a new AdvancedVariablesInterface.
 
protect(self, *args)
Prevents variables from being aggregated during presolve.
 
get_protected(self)
Returns the currently protected variables.
 
tighten_lower_bounds(self, *args)
Tightens the lower bounds on the specified variables.
 
tighten_upper_bounds(self, *args)
Tightens the upper bounds on the specified variables.

Inherited from _baseinterface.BaseInterface: get_indices

Method Details

__init__(self, parent)
(Constructor)

 

Creates a new AdvancedVariablesInterface.

The advanced variables interface is exposed by the top-level Cplex class as Cplex.variables.advanced. This constructor is not meant to be used externally.

Overrides: _baseinterface.BaseInterface.__init__

protect(self, *args)

 

Prevents variables from being aggregated during presolve.

protect may be called with either a single variable identifier or a sequence of variable identifiers. A variable identifier is either an index or a name of a variable.

Note
Subsequent calls to protect will replace previously protected variables with the new set of protected variables.
Note
If presolve can fix a variable to a value, it will be removed from the problem even if it has been protected.
>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(names = ["a", "b", "c", "d"])
>>> c.variables.advanced.protect("a")
>>> c.variables.advanced.protect(["b", "d"])

get_protected(self)

 

Returns the currently protected variables.

Example usage:

>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(names = ["a", "b", "c", "d"])
>>> c.variables.advanced.protect("a")
>>> c.variables.advanced.get_protected()
[0]
>>> c.variables.advanced.protect(["b", "d"])
>>> c.variables.advanced.get_protected()
[1, 3]

tighten_lower_bounds(self, *args)

 

Tightens the lower bounds on the specified variables.

There are two forms by which variables.advanced.tighten_lower_bounds may be called.

variables.advanced.tighten_lower_bounds(i, lb)
i must be a variable name or index and lb must be a real number. Sets the lower bound of the variable whose index or name is i to lb.
variables.advanced.tighten_lower_bounds(seq_of_pairs)
seq_of_pairs must be a list or tuple of (i, lb) pairs, each of which consists of a variable name or index and a real number. Sets the lower bound of the specified variables to the corresponding values. Equivalent to [variables.advanced.tighten_lower_bounds(pair[0], pair[1]) for pair in seq_of_pairs].
>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(names = ["x0", "x1", "x2"])
>>> c.variables.advanced.tighten_lower_bounds(0, 1.0)
>>> c.variables.get_lower_bounds()
[1.0, 0.0, 0.0]
>>> c.variables.advanced.tighten_lower_bounds([(2, 3.0), ("x1", -1.0)])
>>> c.variables.get_lower_bounds()
[1.0, -1.0, 3.0]

tighten_upper_bounds(self, *args)

 

Tightens the upper bounds on the specified variables.

There are two forms by which variables.advanced.tighten_upper_bounds may be called.

variables.advanced.tighten_upper_bounds(i, lb)
i must be a variable name or index and lb must be a real number. Sets the upper bound of the variable whose index or name is i to lb.
variables.advanced.tighten_upper_bounds(seq_of_pairs)
seq_of_pairs must be a list or tuple of (i, lb) pairs, each of which consists of a variable name or index and a real number. Sets the upper bound of the specified variables to the corresponding values. Equivalent to [variables.advanced.tighten_upper_bounds(pair[0], pair[1]) for pair in seq_of_pairs].
>>> import cplex
>>> c = cplex.Cplex()
>>> indices = c.variables.add(names = ["x0", "x1", "x2"])
>>> c.variables.advanced.tighten_upper_bounds(0, 1.0)
>>> c.variables.advanced.tighten_upper_bounds([(2, 3.0), ("x1", 10.0)])
>>> c.variables.get_upper_bounds()
[1.0, 10.0, 3.0]