# Entity Class¶

An AMPL entity such as a parameter or a variable.

An entity can either represent a single instance of an AMPL algebraic entity or, if the corresponding declaration has an indexing expression, a mapping from keys to instances.In the derived classes, it has methods to access instance-level properties which can be used in case the represented entity is scalar. To gain access to all the values in an entity (for all instances and all suffixes for that entities), use the function ampl.Entities.Entity.GetValues(). The algebraic entities which currenty have an equivalent class in the API are:

Variables (see ampl.Entities.Variable)

Constraints (see ampl.Entities.Constraint)

Objectives (see ampl.Entities.Objective)

Sets (see ampl.Entities.Set)

Parameters (see ampl.Entities.Parameter)

Namespace
ampl.Entities
Assemblies
• AMPL

## Syntax¶

public class Entity : IEnumerable

class ampl.Entities.Entity

## Methods¶

GetEnumerator()
Return type: System.Collections.IEnumerator
public virtual IEnumerator GetEnumerator()

GetValues()

Get the principal values of this entity as a DataFrame. 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 ampl.SetInstance.GetValues
Return type: ampl.DataFrame A DataFrame containing the values for all instances
public virtual DataFrame GetValues()

GetValues(System.String[])

Get the specified suffixes value for all instances in a DataFrame

Arguments: suffixes (System.String[]) – Suffixes to get ampl.DataFrame A DataFrame containing the specified values
public DataFrame GetValues(params string[] suffixes)

SetValues(ampl.DataFrame)

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:

x.SetValues(y.GetValues());


is semantically equivalent to the AMPL statement:

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

Arguments: data (ampl.DataFrame) – The data to set the entity to
public void SetValues(DataFrame data)

ToString()

Returns a textual representation of this entity

Return type: System.String
public override string ToString()


## Properties¶

Indexarity()

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.Entity.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

Return type: System.Int32
public int Indexarity { get; }

IndexingSets()

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

Return type: System.String[]
public string[] IndexingSets { get; }

IsScalar()

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)

Return type: System.Boolean
public bool IsScalar { get; }

Name()

Get the name of this entity

Return type: System.String
public string Name { get; }

NumInstances()

Get the number of instances in this entity

Return type: System.Int32
public int NumInstances { get; }