Set Class

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 methods ampl.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 using ampl.AMPL.SetData and an object of class ampl.DataFrame.

Namespace
ampl.Entities
Assemblies
  • AMPL

Inheritance Hierarchy

Syntax

public class Set : Entity<SetInstance>, IEnumerable<SetInstance>, IEnumerable
class ampl.Entities.Set

Properties

Arity()

The arity of s, or number of components in each member of this set

Return type:System.Int32
public int Arity { get; }
Members()

Get the members of this set. Valid only for non indexed sets.

Return type:System.Collections.Generic.IEnumerable<System.Collections.Generic.IEnumerable`1>{ampl.Tuple<ampl.Tuple>}
public IEnumerable<Tuple> Members { get; }
Size()

Get the number of tuples in this set. Valid only for non indexed sets.

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

Methods

Contains(ampl.Tuple)

Check whether this set contains the specified Tuple. Valid only for non indexed sets.

Arguments:
  • t (ampl.Tuple) – Tuple to be found
Return type:

System.Boolean

Returns:

True if the tuple is contained in this set

public bool Contains(Tuple t)
Get(System.Object[])
Return type:ampl.SetInstance
public SetInstance Get(params object[] index)
Get(ampl.Tuple)
Return type:ampl.SetInstance
public override SetInstance Get(Tuple t = null)
GetEnumerator()
Return type:System.Collections.Generic.IEnumerator<System.Collections.Generic.IEnumerator`1>{ampl.SetInstance<ampl.SetInstance>}
public override IEnumerator<SetInstance> GetEnumerator()
GetValues()

Get all the tuples in this set in a DataFrame. Valid only for non indexed sets.

Return type:ampl.DataFrame
Returns:A DataFrame containing all the tuples in this set
public override DataFrame GetValues()
SetValues(System.Double[])

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.

Arguments:
  • objects (System.Double<System.Double>[]) – An array of doubles to be grouped into tuples
public void SetValues(double[] objects)
SetValues(System.String[])

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.

Arguments:
  • objects (System.String<System.String>[]) – An array of strings to be grouped into tuples
public void SetValues(string[] objects)
SetValues(ampl.DataFrame)

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 C++ 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.

Arguments:
  • data (ampl.DataFrame) – The dataframe containing the values to be assigned
public void SetValues(DataFrame data)
SetValues(ampl.Tuple[])

Set the tuples in this set. Valid only for non indexed sets.

Arguments:
  • objects (ampl.Tuple<ampl.Tuple>[]) – The tuples to assign to this set
public void SetValues(Tuple[] objects)