Set¶

class
amplpy.
Set
(_impl)¶ 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. All these methods throw a TypeError if called for an indexed set.
In case of indexed sets, you can gain access to the instances using the operator [].
All the accessors in this class throw an RuntimeError if the instance has been deleted in the underlying AMPL interpreter.
Data can be assigned to the set using the methods
setValues()
(for nonindexed sets only) or usingsetData()
and an object of classDataFrame
.
__init__
(_impl)¶ x.__init__(…) initializes x; see help(type(x)) for signature

instances
()¶ Get an iterator to iterate over all the instances in a Set.

arity
()¶ The arity of the set, or number of components in each member of this set.

getValues
()¶ Get values of this set in a DataFrame. Valid only for nonindexed sets.

members
()¶ Get members (tuples) of this Set. Valid only for nonindexed sets.

size
()¶ Get the number of tuples in this set. Valid only for nonindexed sets.

contains
(t)¶ Check wether this set instance contains the specified Tuple. Valid only for nonindexed sets.
 Args:
 t: Tuple to be found.

setValues
(values)¶ Set the tuples in this set. Valid only for nonindexed sets.
 Args:
 values: A list of tuples or a
DataFrame
.
In the case of a
DataFrame
, the number of indexing columns of the must be equal to the arity of the set. In the case of a list of tuples, the arity of each tuple must be equal to the arity of the set.For example, considering the following AMPL entities and corresponding Python objects:
set A := 1..2; param p{i in A} := i+10; set AA;
The following is valid:
A, AA = ampl.getSet('A'), ampl.getSet('AA') AA.setValues(A.getValues()) # AA has now the members {1, 2}

__module__
= 'amplpy.set'¶
