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
- Assemblies
AMPL
Inheritance Hierarchy¶
System.Object
ampl.Entities.Entity{ConstraintInstance}
Syntax¶
[ClassInterface(ClassInterfaceType.None)]
public class Constraint : Entity<ConstraintInstance>, IEnumerable<ConstraintInstance>, IEnumerable, IConstraint
- class ampl.Entities.Constraint
Properties¶
- ampl.Entities.Constraint.Astatus¶
Get the current AMPL status (dropped, presolved, or substituted out)
- Return type
System.String
public string Astatus { get; }
- ampl.Entities.Constraint.Body¶
Get the current value of the constraint's body
- Return type
System.Double
public double Body { get; }
- ampl.Entities.Constraint.Defvar¶
Get the index in
_var
of "defined variable" substituted out by the constraint- Return type
System.Int32
public int Defvar { get; }
- ampl.Entities.Constraint.Dinit¶
Get the current initial guess for the constraint's public dual variable
- Return type
System.Double
public double Dinit { get; }
- ampl.Entities.Constraint.Dinit0¶
Get the original initial guess for the constraint's public dual variable
- Return type
System.Double
public double Dinit0 { get; }
- ampl.Entities.Constraint.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; }
- ampl.Entities.Constraint.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; }
- ampl.Entities.Constraint.Lb¶
Get the current value of the constraint's lower bound
- Return type
System.Double
public double Lb { get; }
- ampl.Entities.Constraint.Lbs¶
Get the constraint lower bound sent to the solver (reflecting adjustment for fixed variables)
- Return type
System.Double
public double Lbs { get; }
- ampl.Entities.Constraint.Ldual¶
Get the current public dual value associated with the lower bound
- Return type
System.Double
public double Ldual { get; }
- ampl.Entities.Constraint.Lslack¶
Get the slack at lower bound
body - lb
- Return type
System.Double
public double Lslack { get; }
- ampl.Entities.Constraint.Slack¶
Constraint slack (the lesser of lslack and uslack)
- Return type
System.Double
public double Slack { get; }
- ampl.Entities.Constraint.Sstatus¶
Get the solver status (basis status of constraint's %slack or artificial variable)
- Return type
System.String
public string Sstatus { get; }
- ampl.Entities.Constraint.Status¶
Get the AMPL status if not
in
, otherwise solver status- Return type
System.String
public string Status { get; }
- ampl.Entities.Constraint.Ub¶
Get the current value of the constraint's upper bound
- Return type
System.Double
public double Ub { get; }
- ampl.Entities.Constraint.Ubs¶
Get the constraint upper bound sent to the solver (reflecting adjustment for fixed variables)
- Return type
System.Double
public double Ubs { get; }
- ampl.Entities.Constraint.Udual¶
Get the current public dual value associated with the upper bounds
- Return type
System.Double
public double Udual { get; }
- ampl.Entities.Constraint.Uslack¶
Get the slack at upper bound
ub - body
- Return type
System.Double
public double Uslack { get; }
- ampl.Entities.Constraint.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
public ConstraintInstance Get(params object[] index)
- Get(ampl.Tuple)
- Return type
public override ConstraintInstance Get(Tuple t = null)
- GetEnumerator()¶
- Return type
System.Collections.Generic.IEnumerator<ConstraintInstance>
public override IEnumerator<ConstraintInstance> GetEnumerator()
- Restore()¶
Restore all instances in this constraint entity, corresponding to the AMPL code:
restore constraintname;
public void Restore()