Follow us on Twitter and LinkedIn to get the latest updates from the dev team!
A SetInstance object stores the information regarding a specific instance of a set. The instances can be accessed through the function Set.get of the parent entity.
Set.get
The members of the set can be strings, double numbers or tuples.
tuples
Data can be assigned using Set.setValues or using AMPL.setData and a DataFrame object.
Set.setValues
AMPL.setData
DataFrame
All the accessors in this class throw a IllegalArgumentException if the instance has been deleted in the underlying AMPL interpreter.
IllegalArgumentException
Check contents of the set for members. The object to be found can be a String, a double, a Tuple or an array. In this last case, each element in the array is considered as elements of a Tuple to be found.
Tuple
i.e. the following are equivalent:
contains(new Tuple(1, "abc"));
and
contains(new Object[]{1, "abc});
o – Object to be found (double, String, Tuple or Object[] with the elements of a tuple)
True if the object is present.
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.
c
Example: considering the AMPL set declared as
set s := {(1, 'abc'), ('def', 2)};
the following is true:
List<Object> l = new LinkedList<Object>(); list.add(new Tuple("def", 2)); list.add(new Object[] { 1, "abc" }); ampl.getSet("s").get().containsAll(list);
c – A Collection of objects to be found. See above for the semantics of the objects.
True if all the specified objects are present
Get all the members of this set in a DataFrame
Assign values to the this set. The values can be strings, doubles, tuples or arrays of objects (which will be converted into tuples).
For example, to assign values to a set of tuples:
ampl.eval("set s dimen 2;"); Set s = ampl.getSet("s"); Object[] data = new Object[] { new Tuple(1, "abc"), new Tuple(2, "def") }; s.setValues(data);
or alternatively, using arrays of objects:
ampl.eval("set s dimen 2;"); Set s = ampl.getSet("s"); Object[] data = new Object[] {new Object[]{1, "abc"}, new Object{2, "def"}}; s.setValues(data);
objects – Values to be assigned to the set
An alternative way to assign values to a set of tuples of size n is to use a flattened array, in which every n elements are considered a Tuple. So, an equivalent formulation of the example above is:
ampl.eval("set s dimen 2;"); Set s = ampl.getSet("s"); Object[] data = new Object[] { 1, "abc", 2, "def" }; s.setValues(data);
objects –
Get the size
Cardinality of this set
Convert this set to an array.
Valid only for not indexed sets.
Convert this set to an java set.
previous
Set
next
Variable