.. java:import:: java.util Collection .. java:import:: java.util HashSet .. java:import:: java.util Iterator .. java:import:: java.util NoSuchElementException SetInstance =========== .. java:package:: com.ampl :noindex: .. java:type:: public class SetInstance extends BasicInstance implements Iterable A SetInstance object stores the information regarding a specific instance of a set. The instances can be accessed through the function :java:ref:`Set.get` of the parent entity. The members of the set can be strings, double numbers or :java:ref:`tuples `. Data can be assigned using :java:ref:`Set.setValues` or using :java:ref:`AMPL.setData` and a :java:ref:`DataFrame` object. All the accessors in this class throw a :java:ref:`IllegalArgumentException` if the instance has been deleted in the underlying AMPL interpreter. Constructors ------------ SetInstance ^^^^^^^^^^^ .. java:constructor:: SetInstance(SetInstanceBase impl) :outertype: SetInstance Methods ------- contains ^^^^^^^^ .. java:method:: public boolean contains(Object o) :outertype: SetInstance Check contents of the set for members. The object to be found can be a String, a double, a :java:ref:`Tuple` or an array. In this last case, each element in the array is considered as elements of a Tuple to be found. i.e. the following are equivalent: .. parsed-literal:: contains(new Tuple(1, "abc")); and .. parsed-literal:: contains(new Object[]{1, "abc}); :param o: Object to be found (double, String, Tuple or Object[] with the elements of a tuple) :return: True if the object is present. containsAll ^^^^^^^^^^^ .. java:method:: public boolean containsAll(Collection c) :outertype: SetInstance 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. Example: considering the AMPL set declared as .. parsed-literal:: set s := {(1, 'abc'), ('def', 2)}; the following is true: .. parsed-literal:: List l = new LinkedList(); list.add(new Tuple("def", 2)); list.add(new Object[] { 1, "abc" }); ampl.getSet("s").get().containsAll(list); :param c: A Collection of objects to be found. See above for the semantics of the objects. :return: True if all the specified objects are present containsAll ^^^^^^^^^^^ .. java:method:: public boolean containsAll(double[] c) :outertype: SetInstance containsAll ^^^^^^^^^^^ .. java:method:: public boolean containsAll(int[] c) :outertype: SetInstance containsAll ^^^^^^^^^^^ .. java:method:: public boolean containsAll(String[] c) :outertype: SetInstance getValues ^^^^^^^^^ .. java:method:: public DataFrame getValues() :outertype: SetInstance Get all the members of this set in a DataFrame impl ^^^^ .. java:method:: SetInstanceBase impl() :outertype: SetInstance iterator ^^^^^^^^ .. java:method:: @Override public Iterator iterator() :outertype: SetInstance setValues ^^^^^^^^^ .. java:method:: public void setValues(Tuple[] objects) :outertype: SetInstance 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: .. parsed-literal:: 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: .. parsed-literal:: 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); :param objects: Values to be assigned to the set setValues ^^^^^^^^^ .. java:method:: public void setValues(Tuple value) :outertype: SetInstance setValues ^^^^^^^^^ .. java:method:: public void setValues(DataFrame data) :outertype: SetInstance setValuesFlattened ^^^^^^^^^^^^^^^^^^ .. java:method:: public void setValuesFlattened(double... objects) :outertype: SetInstance 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: .. parsed-literal:: ampl.eval("set s dimen 2;"); Set s = ampl.getSet("s"); Object[] data = new Object[] { 1, "abc", 2, "def" }; s.setValues(data); :param objects: setValuesFlattened ^^^^^^^^^^^^^^^^^^ .. java:method:: public void setValuesFlattened(String... objects) :outertype: SetInstance size ^^^^ .. java:method:: public int size() :outertype: SetInstance Get the size :return: Cardinality of this set toArray ^^^^^^^ .. java:method:: public Object[] toArray() :outertype: SetInstance Convert this set to an array. Valid only for not indexed sets. toSet ^^^^^ .. java:method:: public java.util.Set toSet() :outertype: SetInstance Convert this set to an java set. Valid only for not indexed sets.