ConstraintInstance#

class ConstraintInstance : public ampl::BasicInstance<internal::ConstraintInstance>#

This class represent an instance of a constraint.

In general, all AMPL suffixes for a constraint 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.

Note that, since this class represents instances of both algebraic and logical constraints, some suffixes might not be available for every instance. If a wrong suffix for the specific class of constraint is accessed, an std::logic_error is thrown.

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 void drop()#

Drop this constraint instance, corresponding to the AMPL code: drop constraintname;.

inline void restore()#

Restore this constraint instance, corresponding to the AMPL code: restore constraintname;.

inline double body() const#

Get the current value of the constraint’s body.

inline std::string astatus() const#

Get the current AMPL status (dropped, presolved, or substituted out)

inline int defvar() const#

Get the index in _var of “defined variable” substituted out by the constraint.

inline double dinit() const#

Get the current initial guess for the constraint’s dual variable.

inline double dinit0() const#

Get the original initial guess for the constraint’s dual variable.

inline double dual() const#

Get the current value of the constraint’s dual variable.

Note that dual values are often reset by the underlying AMPL interpreter by the presolve functionalities triggered by some methods. A possible workaround is to set the option presolve; to false (see setBoolOption).

inline double lb() const#

Get the current value of the constraint’s lower bound.

inline double ub() const#

Get the current value of the constraint’s upper bound.

inline double lbs() const#

Get the constraint lower bound sent to the solver (reflecting adjustment for fixed variables)

inline double ubs() const#

Get the constraint upper bound sent to the solver (reflecting adjustment for fixed variables)

inline double ldual() const#

Get the current dual value associated with the lower bound.

inline double udual() const#

Get the current dual value associated with the upper bounds.

inline double lslack() const#

Get the slack at lower bound body - lb

inline double uslack() const#

Get the slack at upper bound ub - body

inline double slack() const#

Constraint slack (the lesser of lslack and uslack)

inline std::string sstatus() const#

Get the solver status (basis status of constraint’s slack or artificial variable)

inline std::string status() const#

Get the AMPL status if not in, otherwise solver status.

inline void setDual(double dual)#

Set the value of the dual variable associated to this constraint.

Equivalent to the AMPL statement:

let c := dual;

Note that dual values are often reset by the underlying AMPL interpreter by the presolve functionalities triggered by some methods. A possible workaround is to set the option presolve to false (see setBoolOption).

Parameters:

dual – The value to be assigned to the dual variable

inline double val() const#

Get the AMPL val suffix.

Valid only for logical constraints.

Entity entity() const#

Returns the entity that this instance is part of.

inline Entity entity() const

Returns the entity that this instance is part of.

Tuple key() const#

Returns the key of this instance.

inline Tuple key() const

Returns the key of this instance.

std::string name() const#

Returns the name of this instance.

inline std::string name() const

Returns the name of this instance.

std::string toString() const#

Returns a string representation of this instance.

inline std::string toString() const

Returns a string representation of this instance.