VariableInstance

class ampl::VariableInstance : public ampl::BasicInstance<internal::VariableInstance>

A decision variable instance.

Each member of this class belongs to a single Variable. Note that accessors available here are replicated at Variable level for ease of use when dealing with scalar variables.

All AMPL suffixes for an algebraic variable are available through methods with the same name in this class. See http://www.ampl.com/NEW/suffbuiltin.html for a list of the available suffixes.

All the accessors in this class throw an std::runtime_error if the instance has been deleted in the underlying AMPL interpreter.

Public Functions

inline double value() const

Get the current value of this variable.

inline void fix()

Fix all instances of this variable to their current value.

inline void fix(double value)

Fix all instances of this variable to the specified value.

inline void unfix()

Unfix this variable instances.

inline void setValue(double value)

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

Parameters

value – Value to be set

inline std::string astatus() const

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

inline int defeqn() const

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

inline double dual() const

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

inline double init() const

Get the current initial guess.

inline double init0() const

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

inline double lb() const

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

inline double ub() const

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

inline double lb0() const

Returns the initial lower bounds, from the var declaration.

inline double ub0() const

Returns the initial upper bound, from the var declaration.

inline double lb1() const

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

inline double ub1() const

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

inline double lb2() const

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

inline double ub2() const

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

inline double lrc() const

Returns the reduced cost at lower bound.

inline double urc() const

Returns the reduced cost at upper bound.

inline double lslack() const

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

inline double uslack() const

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

Note on variables suffixes.

inline double rc() const

Get the reduced cost (at the nearer bound)

inline double slack() const

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

inline std::string sstatus() const

Solver status (basis status of variable)

inline std::string status() const

AMPL status if not in, otherwise solver status

inline std::string toString() const

Returns a string representation of this VariableInstance object.

The format is as follows:

'var' name attrs ';'

where name is the string returned by the VariableInstance::name() method and attrs represent attributes similar to those used in variable declarations.

If the lower bound (lb) is equal to the upper bound (ub), the attributes contain = lb.

If the lower bound is not equal to the upper bound and Double.NEGATIVE_INFINITY , the attributes contain >= lb.

If the upper bound is not equal to the lower bound and Double.POSITIVE_INFINITY, the attributes contain &lt;= ub.

If the variable is integer, the attributes contain integer.

If the variable is binary, the attributes contain binary.

inline Entity entity() const

Returns the entity that this instance is part of.

inline Tuple key() const

Returns the key of this instance.

inline std::string name() const

Returns the name of this instance.