Variable#
- class Variable#
Represents an AMPL decision variable. Note that, in case of a scalar variable, all the properties of the variable instance can be accessed through methods like
value. The methods have the same name of the corresponding AMPL suffixes. See https://www.ampl.com/NEW/suffbuiltin.html for a list of the available suffixes.All these methods throw an error if called on an entity which has been deleted in the underlying intepreter.
To gain access to all the values in an entity (for all instances and all suffixes for that entities), see
getValuesand theDataFrameclass.
- Variable.value()#
Get the current value of this variable.
- Returns:
Value of the variable.
- Variable.integrality()#
Get the integrality type for this variable.
- Returns:
Integrality type of the variable (“C” - continuous, “B” - binary, “I” - integer).
- Return type:
str
- Variable.fix(value=NULL)#
Fix all instances of this variable to their current value, or to the specified value if provided.
- Parameters:
value (float) – The value the variable must be set to.
- Returns:
NULL.
- Variable.unfix()#
Unfix this variable instances.
- Returns:
NULL.
- Variable.setValue()#
Set the current value of this variable (does not fix it), equivalent to the AMPL command let
- Parameters:
value (float) – Value to be set.
- Returns:
NULL.
- Variable.astatus()#
Get the variable status (fixed, presolved, or substituted out).
- Returns:
Variable status.
- Return type:
str
- Variable.defeqn()#
Get the index in _con of “defining constraint” used to substitute variable out.
- Returns:
Index of the defining constraint.
- Return type:
int
- Variable.dual()#
Get the dual value on defining constraint of variable substituted out.
- Returns:
Dual value.
- Return type:
float
- Variable.init()#
Get the current initial guess.
- Returns:
The initial guess.
- Return type:
float
- Variable.init0()#
Get the original initial guess (set by := or`default` or by a data statement)
- Returns:
The original initial guess.
- Return type:
float
- Variable.lb()#
Returns the current lower bound. See Note on variables suffixes.
- Returns:
The current lower bound.
- Return type:
float
- Variable.ub()#
Returns the current upper bound. See Note on variables suffixes.
- Returns:
The current upper bound.
- Return type:
float
- Variable.lb0()#
Returns the initial lower bound, from the var declaration.
- Returns:
The intial lower bound.
- Return type:
float
- Variable.ub0()#
Returns the initial upper bound, from the var declaration.
- Returns:
The intial upper bound.
- Return type:
float
- Variable.lb1()#
Returns the weaker lower bound from AMPL’s presolve phase.
- Returns:
The weaker lower bound.
- Return type:
float
- Variable.ub1()#
Returns the weaker upper bound from AMPL’s presolve phase.
- Returns:
The weaker upper bound.
- Return type:
float
- Variable.lb2()#
Returns the stronger lower bound from AMPL’s presolve phase.
- Returns:
The stronger lower bound.
- Return type:
float
- Variable.ub2()#
Returns the stronger upper bound from AMPL’s presolve phase.
- Returns:
The stronger upper bound.
- Return type:
float
- Variable.lrc()#
Returns the reduced cost at lower bound.
- Returns:
The reduced cost at lower bound.
- Return type:
float
- Variable.urc()#
Returns the reduced cost at upper bound.
- Returns:
The reduced cost at upper bound.
- Return type:
float
- Variable.lslack()#
Returns the slack at lower bound (
val - lb). See Note on variables suffixes.- Returns:
The slack at lower bound.
- Return type:
float
- Variable.uslack()#
Returns the slack at upper bound (
ub - val). See Note on variables suffixes.- Returns:
The slack at upper bound.
- Return type:
float
- Variable.rc()#
Get the reduced cost (at the nearer bound).
- Returns:
The reduced cost.
- Return type:
float
- Variable.slack()#
Returns the bound slack which is the lesser of lslack() and uslack(). See Note on variables suffixes.
- Returns:
The smaller slack.
- Return type:
float
- Variable.sstatus()#
Solver status (basis status of variable).
- Returns:
The basis status of the variable.
- Return type:
str
- Variable.status()#
AMPL status if not in, otherwise solver status
- Returns:
The status of the variable.
- Return type:
str