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 (params object[] index)#

Get the instance with the specified index.

override VariableInstance Get (Tuple t = null)

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

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)

string Status { get; set; }#

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

public int Defeqn { get { return Impl.defeqn(); } } /

/ Get the dual value on the defining constraint of this variable / (valid for scalar variables only) / public double Dual { get { return Impl.dual(); } } /

/ Get the current initial guess (valid for scalar variables only) / public double Init { get { return Impl.init(); } } /

/ Get the original initial guess (set by := or by a default instruction or / a data statement (valid for scalar variables only) / public double Init0 { get { return Impl.init0(); } } /

/ Get the current lower bound (valid for scalar variables only) / public double Lb { get { return Impl.lb(); } } /

/ Get the current upper bound (valid for scalar variables only) / public double Ub { get { return Impl.ub(); } } /

/ Get the initial upper bound (valid for scalar variables only) / public double Ub0 { get { return Impl.ub0(); } } /

/ Get the initial lower bound (valid for scalar variables only) / public double Lb0 { get { return Impl.lb0(); } } /

/ Get the weaker lower bound from AMPL’s presolve phase / (valid for scalar variables only) / public double Lb1 { get { return Impl.lb1(); } } /

/ Get the weaker upper bound from AMPL’s presolve phase / (valid for scalar variables only) / public double Ub1 { get { return Impl.ub1(); } } /

/ Get the stronger lower bound from AMPL’s presolve phase / (valid for scalar variables only) / public double Lb2 { get { return Impl.lb2(); } } /

/ Get the stronger upper bound from AMPL’s presolve phase / (valid for scalar variables only) / public double Ub2 { get { return Impl.ub2(); } } /

/ Get the reduced cost at lower bound / (valid for scalar variables only) / public double Lrc { get { return Impl.lrc(); } } /

/ Get the reduced cost at upper bound / (valid for scalar variables only) / public double Urc { get { return Impl.urc(); } } /

/ Get the slack at lower bound val - lb / (valid for scalar variables only) / public double Lslack { get { return Impl.lslack(); } } /

/ Get the slack at upper bound ub - val / (valid for scalar variables only) / public double Uslack { get { return Impl.uslack(); } } /

/ Get the reduced cost at the nearer bound / (valid for scalar variables only) / public double Rc { get { return Impl.rc(); } } /

/ Get the bound slack which is the lesser of :ampl.Entities.Variable.Lslack / or :ampl.Entities.Variable.Uslack (valid for scalar variables only) / public double Slack { get { return Impl.slack(); } } /

/ Solver status (basis status of variable). / Valid for scalar variables only. / public string Sstatus { get { return Impl.sstatus(); } } /

/ 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; }#