class Entity

Infrastructure class to enable the inheriting classes type-safe access to instances.


Get the name of this entity.

Returns:The name of this entity.
Returns a string representation of this entity (its declaration).
Returns:The string representation of this entity.

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 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
Returns:The sum of the dimensions of the indexing sets or 0 if the entity is not indexed.

Check whether this entity is scalar. Equivalent to testing whether indexarity is equal to zero.

Returns:TRUE if the entity is scalar (not indexed over any set).

Get the number of instances in this entity.

Returns:The number of instances in this entity.

Get a list with the AMPL string representation of the sets on which this entity is indexed.

Returns:The string representation of the indexing sets for this entity or an empty list if the entity is scalar.

Get the principal values of this entity as a data.frame. The specific returned value depends on the type of entity (see list below).

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 getValues

Returns:A data.frame containing the values for all instances.

Get the specified suffixes value for all instances in a data.frame.

Parameters:suffixes (list) – Suffixes to get.
Returns:A data.frame containing the specified values.

Set the values of this entiy 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:


is semantically equivalent to the AMPL statement:

let {s in S} x[s] := y[s];
Parameters:data (data.frame) – The data to set the entity to.

Get the instance with the specified index. Throws an error if an instance with the specified index does not exist, if it has been deleted in the underlying AMPL interpreter, or if the index does not match the indexarity. Also works for scalar entities with an empty list as argument.

Parameters:index (tuple) – The list specifying the index.
Returns:The corresponding instance.

Searches the current entity for an instance with the specified index.

Returns:The wanted entity if found, or NULL otherwise.

Get all the instances of this entity.

Returns:A list with all the instances of this entity.