Variable#

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

Represents an AMPL variable.

Note that, in case of a scalar variable, all the properties (corresponding to AMPL suffixes) of the variable instance can be accessed through corresponding properties on the Variable itself. The properties have the same name of the corresponding AMPL suffixes. See http://www.ampl.com/NEW/suffbuiltin.html for a list of the available suffixes. An ArgumentException is thrown if one of such methods is called for a non-scalar variable. 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.VariableInstance can be accessed via the indexing operator, via the method ampl.Entities.Variable.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<VariableInstance> GetEnumerator ()#

Get an enumerator to iterate through the instances in this entity.

Return:

new VariableInstance Get (Tuple t = null)#

Get the instance with the specified index.

override VariableInstance Get (params object[] index)

Get the instance with the specified index.

void Fix ()#

Fix all instances of this variable to their current value.

void Fix (double value)

Fix this variable to the specified value (valid for scalar variables only).

Param value:

Value to fix the variable to

void Unfix ()#

Unfix all instances of this variable.

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

void SetSuffixes (DataFrame data)#

Set suffix values for all instances of this entity from a DataFrame.

The DataFrame must have index columns matching the entity’s indexing sets and one data column per suffix to set.

Param data:

A DataFrame containing the suffix values to assign

void SetSuffix (string suffix, double value)#

Set a numeric suffix value for this scalar entity.

Equivalent to the AMPL statement: let entityName.suffix := value;

Param suffix:

Name of the suffix to set.

Param value:

Numeric value to assign.

void SetSuffix (string suffix, string value)

Set a string suffix value for this scalar entity.

Equivalent to the AMPL statement: let entityName.suffix := value;

Param suffix:

Name of the suffix to set.

Param value:

String value to assign.

string GetExpand ()#

Get the expand message of this entity.

Equivalent to the AMPL statement: expand entityName;

Return:

A string with the expand message of this entity.

Properties

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

Get the instance with the specified index.

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

Get the instance at t.

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

Get the instance at index.

double Value { get; set; }#

Get or set the current value of this variable (valid for scalar variables only).

string Astatus { get; set; }#

Get the AMPL status of this variable (fixed, presolved or substituted) (valid for scalar variables only).

int Defeqn { get; set; }#

Get the index in _con of “definining constraint” used to substitute this variable out (valid for scalar variables only).

double Dual { get; set; }#

Get the dual value on the defining constraint of this variable (valid for scalar variables only).

double Init { get; set; }#

Get the current initial guess (valid for scalar variables only).

double Init0 { get; set; }#

Get the original initial guess (set by := or by a default instruction or a data statement (valid for scalar variables only).

double Lb { get; set; }#

Get the current lower bound (valid for scalar variables only).

double Ub { get; set; }#

Get the current upper bound (valid for scalar variables only).

double Ub0 { get; set; }#

Get the initial upper bound (valid for scalar variables only).

double Lb0 { get; set; }#

Get the initial lower bound (valid for scalar variables only).

double Lb1 { get; set; }#

Get the weaker lower bound from AMPL’s presolve phase (valid for scalar variables only).

double Ub1 { get; set; }#

Get the weaker upper bound from AMPL’s presolve phase (valid for scalar variables only).

double Lb2 { get; set; }#

Get the stronger lower bound from AMPL’s presolve phase (valid for scalar variables only).

double Ub2 { get; set; }#

Get the stronger upper bound from AMPL’s presolve phase (valid for scalar variables only).

double Lrc { get; set; }#

Get the reduced cost at lower bound (valid for scalar variables only).

double Urc { get; set; }#

Get the reduced cost at upper bound (valid for scalar variables only).

double Lslack { get; set; }#

Get the slack at lower bound val - lb (valid for scalar variables only).

double Uslack { get; set; }#

Get the slack at upper bound ub - val (valid for scalar variables only).

double Rc { get; set; }#

Get the reduced cost at the nearer bound (valid for scalar variables only).

double Slack { get; set; }#

Get the bound slack which is the lesser of :ampl.Entities.Variable.Lslack or :ampl.Entities.Variable.Uslack (valid for scalar variables only).

string Sstatus { get; set; }#

Solver status (basis status of variable).

Valid for scalar variables only.

string Status { get; set; }#

AMPL status if not in, otherwise solver status (valid for scalar variables only).

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.

VariableMap#

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

Enables iterable access to the variables.

Public Functions

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

Properties

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