Constraint¶
- class amplpy.Constraint(_impl)¶
Bases:
Entity
.This class represents an algebraic or logical constraint. In case the constraint is scalar, its values can be accessed via functions like
body()
anddual()
. All the AMPL suffixes for constraints (see http://www.ampl.com/NEW/suffbuiltin.html) are available through methods of this class with the same name (and methods of ConstraintInstance for indexed constraints).Note that, since this class represents both algebraic and logical constraints, some suffixes might not be available for every entity.
An TypeError is thrown if one of such methods is called for a non-scalar constraint and if a method corresponding to a suffix which is not supported by the type of the constraint is called. A runtime error is thrown if any property of an entity which has been deleted from the underlying interpreter is accessed.
To gain access to all the values in an entity (for all instances and all suffixes for that entities), see
get_values()
and theDataFrame
class.- __setitem__(index, value)¶
- is_logical()¶
Check if the constraint is a logical constraint. Returns True if logical. The available suffixes differ between logical and non logical constraints. See http://www.ampl.com/NEW/suffbuiltin.html for a list of the available suffixes for algebraic constraints. The suffixes available for logical constraints are marked on the method description by “Valid only for logical constraints”.
- drop()¶
Drop all instances in this constraint entity, corresponding to the AMPL code: drop constraintname;.
- restore()¶
Restore all instances in this constraint entity, corresponding to the AMPL code: restore constraintname;.
- body()¶
Get the current value of the constraint’s body.
- astatus()¶
Get the current AMPL status (dropped, presolved, or substituted out).
- defvar()¶
Get the index in _var of “defined variable” substituted out by the constraint.
- dinit()¶
Get the current initial guess for the constraint’s dual variable.
- dinit0()¶
Get the original initial guess for the constraint’s dual variable.
- dual()¶
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
setOption()
).
- lb()¶
Get the current value of the constraint’s lower bound.
- ub()¶
Get the current value of the constraint’s upper bound.
- lbs()¶
Get the constraint lower bound sent to the solver (reflecting adjustment for fixed variables).
- ubs()¶
Get the constraint upper bound sent to the solver (reflecting adjustment for fixed variables).
- ldual()¶
Get the current dual value associated with the lower bound.
- udual()¶
Get the current dual value associated with the upper bounds.
- lslack()¶
Get the slack at lower bound body - lb.
- uslack()¶
Get the slack at upper bound ub - body.
- slack()¶
Constraint slack (the lesser of lslack and uslack).
- sstatus()¶
Get the solver status (basis status of constraint’s slack or artificial variable).
- status()¶
Get the AMPL status if not in, otherwise solver status.
- set_dual(dual)¶
Set the value of the dual variable associated to this constraint (valid only if the constraint is scalar). 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
setOption()
).- Args:
dual: The value to be assigned to the dual variable.
- val()¶
Get the AMPL val suffix. Valid only for logical constraints.