Set¶
-
public class
Set
extends BasicEntity<SetInstance>¶ Represents an AMPL set. In case of not indexed sets, this class exposes functionalities of a Java Set for accessing its elements. The members of the set can be strings, double numbers or
tuples
. Moreover, the inheritedSet.getValues
can be used to get all the members inDataFrame
class.All these methods throw an
UnsupportedOperationException
if called for an indexed set.In case of indexed sets, use the method
Set.get
to obtain the objects of typeSetInstance
, from which to access all properties (see section Access to instances and values for further information on how to access set instances).Data can be assigned to the set using the methods
Set.setValues
, or usingAMPL.setData
and an object of classDataFrame
.
Methods¶
contains¶
-
public boolean
contains
(Object o)¶ Check contents.
See
SetInstance.contains
.Valid only for not indexed sets.
Parameters: - o – Tuple to be searched for
Returns: True if the object is present
containsAll¶
-
public boolean
containsAll
(double[] c)¶ Check if the sets contains all the elements in the collection c. Each element in the collection can be a double, a String, a Tuple or an array. In case of arrays, each array is considered as a Tuple.
Valid only for not indexed sets.
Parameters: - c – The collection containing the elements to find.
containsAll¶
-
public boolean
containsAll
(Collection<? extends Object> c)¶
get¶
-
public SetInstance
get
()¶ Get the set instance (for not indexed sets)
Throws: - UnsupportedOperationException – if the set is indexed
- IllegalStateException – If the entity has been deleted in the underlying AMPL interpreter.
get¶
-
public final SetInstance
get
(Object... key)¶ Get the set instance corresponding to the specified key. See Access to instances and values for further information on how the key can be specified.
Throws: - IllegalArgumentException – if trying to access an instance with the wrong number of keys (see
Entity.indexarity
) - IllegalStateException – if the entity has been deleted in the underlying AMPL interpreter
Returns: The instance corresponding to the specified key. Null if the specified key is not present.
- IllegalArgumentException – if trying to access an instance with the wrong number of keys (see
get¶
-
public final SetInstance
get
(Tuple key)¶ Get the set instance corresponding to the specified key (passed as a Tuple). See Access to instances and values for further information on how the key can be specified.
Parameters: - key – The indexing tuple of the instance to be found
Throws: - IllegalArgumentException – if trying to access an instance with the wrong number of keys (see
Entity.indexarity
) - IllegalStateException – if the entity has been deleted in the underlying AMPL interpreter
Returns: The instance corresponding to the specified key. Null if the specified key is not present.
getValues¶
isEmpty¶
-
public boolean
isEmpty
()¶ Return true if the set is empty.
Valid only for not indexed sets.
iterator¶
-
public Iterator<SetInstance>
iterator
()¶
members¶
-
public MemberRange
members
()¶ If the set is not indexed, get the iterator for this set, allowing easy access to its elements, as in:
ampl.eval("set A := {'a', 'b', 3};"); for (Object o : ampl.getSet("A")) { // ... }
Throws: - UnsupportedOperationException – if used on an indexed set
setValues¶
-
public void
setValues
(Tuple[] objects)¶ Assign values to the this set.
See
SetInstance.setValues
for the usage instructions.
size¶
-
public int
size
()¶ Get the size of the set (number of elements) (valid only for not indexed sets)
Throws: - UnsupportedOperationException – if used on an indexed set