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
set_values()
(for non-indexed sets only) or using
set_data()
and an object of class
DataFrame
.
-
__setitem__(index, value)
-
__iter__()
-
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.
-
get_values()
Get values of this set in a DataFrame. Valid only for non-indexed sets.
-
members()
Get members (tuples) of this Set. Valid only for non-indexed sets.
-
size()
Get the number of tuples in this set. Valid only for non-indexed sets.
-
contains(t)
Check wether this set instance contains the specified Tuple.
Valid only for non-indexed sets.
- Args:
t: Tuple to be found.
-
set_values(values)
Set the tuples in this set. Valid only for non-indexed 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}
-
__annotations__ = {}