Variable

class amplpy.Variable(_impl)

Bases: Entity.

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 a TypeError if called for a non scalar objective and an RuntimeError 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 get_values() and the DataFrame class.

__setitem__(index, value)
value()

Get the current value of this variable.

fix(value=None)

Fix all instances of this variable to a value if provided or to their current value otherwise.

Args:

value: value to be set.

unfix()

Unfix all instances of this variable.

set_value(value)

Set the current value of this variable (does not fix it), equivalent to the AMPL command let.

Args:

value: value to be set.

astatus()

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

defeqn()

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

dual()

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

init()

Get the current initial guess.

init0()

Get the original initial guess (set by := or`default` or by a data statement).

lb()

Returns the current lower bound.

ub()

Returns the current upper bound.

lb0()

Returns the initial lower bounds, from the var declaration.

ub0()

Returns the initial upper bound, from the var declaration.

lb1()

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

ub1()

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

lb2()

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

ub2()

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

lrc()

Returns the reduced cost at lower bound.

urc()

Returns the reduced cost at upper bound.

lslack()

Return the slack at lower bound (val - lb).

uslack()

Return the slack at upper bound (ub - val).

rc()

Get the reduced cost (at the nearer bound).

slack()

Returns the bound slack which is the lesser of lslack() and uslack().

sstatus()

Solver status (basis status of variable).

status()

AMPL status if not in, otherwise solver status.

__annotations__ = {}