Constraint Class¶
This class represents an algebraic or logical constraint. In case the
constraint is scalar, its values can be accessed via properties like
ampl.Entities.Constraint.Body
and ampl.Entities.Constraint.Dual
.
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 ampl.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 ArgumentException
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.
An ArgumentOutOfRangeException
is thrown if any property of an entity which has been
deleted from the underlying interpreter is accessed.
The instances, represented by the class ampl.ConstraintInstance
can be accessed
via the indexing operator, via the method ampl.Entities.Constraint.Get
or via the iterator provided.
To gain access to all the values in an entity (for all instances and all
suffixes for that entities), see ampl.Entities.Entity.GetValues()
and the
ampl.DataFrame
class.
- Namespace
ampl.Entities
- Assemblies
- AMPL
Inheritance Hierarchy¶
System.Object
ampl.Entities.Entity
ampl.Entities.Entity{ampl.ConstraintInstance}
ampl.Entities.Constraint
Syntax¶
public class Constraint : Entity<ConstraintInstance>, IEnumerable<ConstraintInstance>, IEnumerable
-
class
ampl.Entities.
Constraint
Properties¶
-
Astatus
()¶ Get the current AMPL status (dropped, presolved, or substituted out)
Return type: System.String public string Astatus { get; }
-
Body
()¶ Get the current value of the constraint’s body
Return type: System.Double public double Body { get; }
-
Defvar
()¶ Get the index in
_var
of “defined variable” substituted out by the constraintReturn type: System.Int32 public int Defvar { get; }
-
Dinit
()¶ Get the current initial guess for the constraint’s public dual variable
Return type: System.Double public double Dinit { get; }
-
Dinit0
()¶ Get the original initial guess for the constraint’s public dual variable
Return type: System.Double public double Dinit0 { get; }
-
Dual
()¶ Get and set the current value of the constraint’s public dual variable. Setting this property is 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 optionpresolve;
tofalse
(see AMPL.SetOption).Return type: System.Double public double Dual { get; set; }
-
IsLogical
()¶ Check if the constraint is a logical constraint. 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”.
Return type: System.Boolean Returns: True if logical public bool IsLogical { get; }
-
Lb
()¶ Get the current value of the constraint’s lower bound
Return type: System.Double public double Lb { get; }
-
Lbs
()¶ Get the constraint lower bound sent to the solver (reflecting adjustment for fixed variables)
Return type: System.Double public double Lbs { get; }
-
Ldual
()¶ Get the current public dual value associated with the lower bound
Return type: System.Double public double Ldual { get; }
-
Lslack
()¶ Get the slack at lower bound
body - lb
Return type: System.Double public double Lslack { get; }
-
Slack
()¶ Constraint slack (the lesser of lslack and uslack)
Return type: System.Double public double Slack { get; }
-
Sstatus
()¶ Get the solver status (basis status of constraint’s %slack or artificial variable)
Return type: System.String public string Sstatus { get; }
-
Status
()¶ Get the AMPL status if not
in
, otherwise solver statusReturn type: System.String public string Status { get; }
-
Ub
()¶ Get the current value of the constraint’s upper bound
Return type: System.Double public double Ub { get; }
-
Ubs
()¶ Get the constraint upper bound sent to the solver (reflecting adjustment for fixed variables)
Return type: System.Double public double Ubs { get; }
-
Udual
()¶ Get the current public dual value associated with the upper bounds
Return type: System.Double public double Udual { get; }
-
Uslack
()¶ Get the slack at upper bound
ub - body
Return type: System.Double public double Uslack { get; }
-
Val
()¶ Get the AMPL val suffix. Valid only for logical constraints.
Return type: System.Double public double Val { get; }
-
Methods¶
-
Drop
()¶ Drop all instances in this constraint entity, corresponding to the AMPL code:
drop constraintname;
public void Drop()
-
Get
(System.Object[])¶ Return type: ampl.ConstraintInstance public ConstraintInstance Get(params object[] index)
-
Get
(ampl.Tuple) Return type: ampl.ConstraintInstance public override ConstraintInstance Get(Tuple t = null)
-
GetEnumerator
()¶ Return type: System.Collections.Generic.IEnumerator<System.Collections.Generic.IEnumerator`1>{ampl.ConstraintInstance<ampl.ConstraintInstance>} public override IEnumerator<ConstraintInstance> GetEnumerator()
-
Restore
()¶ Restore all instances in this constraint entity, corresponding to the AMPL code:
restore constraintname;
public void Restore()
-