Set#
- class ampl.Entities.Set : ampl.Entities.Entity<K>#
Represents an AMPL set.
In case of not indexed sets, this class exposes iterators for accessing its elements. The members of the set are tuples, represented by objects of class
ampl.Tuple
.All these methods throw an
ArgumentException
if called for an indexed set.In case of indexed sets, you can gain access to the instances (of class
ampl.SetInstance
) using the methodsampl.Set.Get
, using the indexing operator or via the iterators.Data can be assigned to the set using the methods
ampl.Set.SetValues
(for non-indexed sets only) or usingampl.AMPL.SetData
and an object of classampl.DataFrame
.Public Functions
- override IEnumerator<SetInstance> GetEnumerator ()#
- new SetInstance Get (params object[] index)#
- override SetInstance Get (Tuple t = null)
- bool Contains (ampl.Tuple t)#
Check whether this set contains the specified Tuple.
Valid only for non indexed sets.
- Param t:
Tuple to be found
- Return:
True if the tuple is contained in this set
- void SetValues (Tuple[] objects)#
Set the tuples in this set.
Valid only for non indexed sets.
- Param objects:
The tuples to assign to this set
- void SetValues (double[] objects)
Set the tuples to this set using a flattened array.
The size of the array must be a multiple of the arity of this set, and each
arity
elements in the array will be grouped into a Tuple. Valid only for non indexed sets.- Param objects:
An array of doubles to be grouped into tuples
- void SetValues (string[] objects)
Set the tuples in this set instance using a flattened array.
The size of the array must be a multiple of the arity of this set, and each
arity
elements in the array will be grouped into a Tuple. Valid only for non indexed sets.- Param objects:
An array of strings to be grouped into tuples
- new void SetValues (DataFrame data)
Set the values in this set to the indexing values of the passed DataFrame.The number of indexing columns of the parameter must be equal to the arity of this set instance.
For example, considering the following AMPL entities and corresponding objects::
set A := 1..2; param p { i in A } := i+10; set AA;
The following is valid::
Set A = ampl.getSet("A"), AA = ampl.GetSet("AA"); AA.setValues(A.GetValues()); // A has now the members {1, 2}
Valid only for non indexed sets.
- Param data:
The dataframe containing the values to be assigned
- override DataFrame GetValues ()#
Get all the tuples in this set in a DataFrame.
Valid only for non indexed sets.
- Return:
A DataFrame containing all the tuples in this set
- K[] AsArray ()#
- override string ToString ()#
Returns a textual representation of this entity.
Properties
- SetInstance this[Tuple t] {get;set;}
Get the instance with the specified index.
- SetInstance this[string t] {get;set;}
Get the instance at t.
- this[params object[] index { get; set; }#
Get the instance at index.
- int Arity { get; set; }#
The arity of s, or number of components in each member of this set.
- Return:
- Tuple > Members { get; set; }#
Get the members of this set.
Valid only for non indexed sets.
- int Size { get; set; }#
Get the number of tuples in this set.
Valid only for non indexed sets.
- 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.
SetMap#
- class ampl.Entities.SetMap : ampl.Entities.EntityMap<ENTITY>#
Enables iterable access to the sets.