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 http://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 getValues and the DataFrame class.

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). 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. 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. NULL.
Variable.astatus()

Get the variable status (fixed, presolved, or substituted out).

Returns: Variable status. str
Variable.defeqn()

Get the index in _con of “defining constraint” used to substitute variable out.

Returns: Index of the defining constraint. int
Variable.dual()

Get the dual value on defining constraint of variable substituted out.

Returns: Dual value. float
Variable.init()

Get the current initial guess.

Returns: The initial guess. float
Variable.init0()

Get the original initial guess (set by := ordefault or by a data statement)

Returns: The original initial guess. float
Variable.lb()

Returns the current lower bound. See Note on variables suffixes.

Returns: The current lower bound. float
Variable.ub()

Returns the current upper bound. See Note on variables suffixes.

Returns: The current upper bound. float
Variable.lb0()

Returns the initial lower bound, from the var declaration.

Returns: The intial lower bound. float
Variable.ub0()

Returns the initial upper bound, from the var declaration.

Returns: The intial upper bound. float
Variable.lb1()

Returns the weaker lower bound from AMPL’s presolve phase.

Returns: The weaker lower bound. float
Variable.ub1()

Returns the weaker upper bound from AMPL’s presolve phase.

Returns: The weaker upper bound. float
Variable.lb2()

Returns the stronger lower bound from AMPL’s presolve phase.

Returns: The stronger lower bound. float
Variable.ub2()

Returns the stronger upper bound from AMPL’s presolve phase.

Returns: The stronger upper bound. float
Variable.lrc()

Returns the reduced cost at lower bound.

Returns: The reduced cost at lower bound. float
Variable.urc()

Returns the reduced cost at upper bound.

Returns: The reduced cost at upper bound. float
Variable.lslack()

Returns the slack at lower bound (val - lb). See Note on variables suffixes.

Returns: The slack at lower bound. float
Variable.uslack()

Returns the slack at upper bound (ub - val). See Note on variables suffixes.

Returns: The slack at upper bound. float
Variable.rc()

Get the reduced cost (at the nearer bound).

Returns: The reduced cost. float
Variable.slack()

Returns the bound slack which is the lesser of lslack() and uslack(). See Note on variables suffixes.

Returns: The smaller slack. float
Variable.sstatus()

Solver status (basis status of variable).

Returns: The basis status of the variable. str
Variable.status()

AMPL status if not in, otherwise solver status

Returns: The status of the variable. str