Constraint#

class ampl.Entities.Constraint : ampl.Entities.Entity<K>#

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.

Public Functions

override IEnumerator<ConstraintInstance> GetEnumerator ()#
new ConstraintInstance Get (params object[] index)#
override ConstraintInstance Get (Tuple t = null)
void Drop ()#

Drop all instances in this constraint entity, corresponding to the AMPL code: drop constraintname;

void Restore ()#

Restore all instances in this constraint entity, corresponding to the AMPL code: restore constraintname;

K[] AsArray ()#
override string ToString ()#

Returns a textual representation of this entity.

DataFrame GetValues ()#

Get the principal values of this entity as a DataFrame.

The specific returned value depends on the type of entity. For:

Variables and Objectives it returns the suffix val

Parameters it returns their values

Constraints it returns the suffix dual

Sets it returns all the members of the set, Note that it does not apply to indexed sets. See ampl.SetInstance.GetValues

Return:

A DataFrame containing the values for all instances

DataFrame GetValues (params string[] suffixes)

Get the specified suffixes value for all instances in a DataFrame.

Param suffixes:

Suffixes to get

Return:

A DataFrame containing the specified values

void SetValues (DataFrame data)#

Set the values of this entity to the correponding values of a DataFrame indexed over the same sets(or a subset).

This function assigns the values in the first data column of the passed dataframe to the entity the function is called from. In particular, the statement::

 `x.SetValues(y.GetValues());`

is semantically equivalent to the AMPL statement::

 `let { s in S } x[s] := y[s];`

Param data:

The data to set the entity to

Properties

ConstraintInstance this[Tuple t] {get;set;}

Get the instance with the specified index.

ConstraintInstance this[string t] {get;set;}

Get the instance at t.

this[params object[] index { get; set; }#

Get the instance at index.

bool IsLogical { get; set; }#

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:

True if logical

double Body { get; set; }#

Get the current value of the constraint’s body.

string Astatus { get; set; }#

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

int Defvar { get; set; }#

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

double Dinit { get; set; }#

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

double Dinit0 { get; set; }#

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

double Dual { get; set; }#

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 option presolve; to false (see AMPL.SetOption).

double Lb { get; set; }#

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

double Ub { get; set; }#

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

double Lbs { get; set; }#

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

double Ubs { get; set; }#

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

double Ldual { get; set; }#

Get the current public dual value associated with the lower bound.

double Udual { get; set; }#

Get the current public dual value associated with the upper bounds.

double Lslack { get; set; }#

Get the slack at lower bound body - lb

double Uslack { get; set; }#

Get the slack at upper bound ub - body

double Slack { get; set; }#

Constraint slack (the lesser of lslack and uslack)

string Sstatus { get; set; }#

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

string Status { get; set; }#

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

double Val { get; set; }#

Get the AMPL val suffix.

Valid only for logical constraints.

string Name { get; set; }#

Get the name of this entity.

int Indexarity { get; set; }#

Get the indexarity of this entity (sum of the dimensions of the indexing sets).

This value indicates the arity of the tuple to be passed to the method ampl.Entities.EntityBase.Get in order to access an instance of this entity. See the following AMPL examples::

  var x;               # indexarity = 0
  var y {1..2};        # indexarity = 1
  var z {1..2,3..4};   # indexarity = 2
  var zz {{ (1, 2)} };   # indexarity = 2

Get the sum of the dimensions of the indexing sets or 0 if the entity is not indexed

bool IsScalar { get; set; }#

Check whether this entity is scalar.

Equivalent to testing whether indexarity is equal to zero, is true if the entity is scalar (not indexed over any set)

int NumInstances { get; set; }#

Get the number of instances in this entity.

string[] IndexingSets { get; set; }#

Get the AMPL string representation of the sets on which this entity is indexed.The obtained vector can be modified without any effect to the entity.

Is equal to the string representation of the indexing sets for this entity or an empty array if the entity is scalar

string[] XRef { get; set; }#

Get the names of all entities which depend on this one.

ConstraintMap#

class ampl.Entities.ConstraintMap : ampl.Entities.EntityMap<ENTITY>#

Enables iterable access to the constraints.

Public Functions

override IEnumerator<Constraint> GetEnumerator ()#
ENTITY[] AsArray ()#

Properties

new Constraint this[string name] {get;set;}
override int Size { get; set; }#