.. java:import:: java.lang.reflect Method .. java:import:: java.util ArrayList .. java:import:: java.util Collection .. java:import:: java.util Collections .. java:import:: java.util LinkedHashMap .. java:import:: java.util List .. java:import:: java.util Map .. java:import:: java.util Set Entity ====== .. java:package:: com.ampl :noindex: .. java:type:: public abstract class Entity An AMPL entity such as a parameter or a variable. An entity can either represent a single instance of an AMPL algebraic entity or, if the corresponding declaration has an indexing expression, a mapping from keys to instances. In the derived classes, it has methods to access instance-level properties which can be used in case the represented entity is scalar. To gain access to all the values in an entity (for all instances and all suffixes for that entities), use :java:ref:`getValues`. Fields ------ ARE_DEPENDENCIES_VALID ^^^^^^^^^^^^^^^^^^^^^^ .. java:field:: static final int ARE_DEPENDENCIES_VALID :outertype: Entity Flag that specifies whether the entity's dependencies might have changed (so far just through normal "interpret") ENTITY_DELETED ^^^^^^^^^^^^^^ .. java:field:: static final int ENTITY_DELETED :outertype: Entity Flag that specifies whether the entity has been deleted (is invalid) IS_VALID ^^^^^^^^ .. java:field:: static final int IS_VALID :outertype: Entity Flag that specifies whether the entity contains valid (up to date) data. Initialization is performed lazily when the entity is first accessed except when it is done through the data statements. NO_DATA ^^^^^^^ .. java:field:: static final int NO_DATA :outertype: Entity Flag that specifies whether the entity doesn't contain any data. ampl ^^^^ .. java:field:: AMPL ampl :outertype: Entity declaration ^^^^^^^^^^^ .. java:field:: String declaration :outertype: Entity engine ^^^^^^ .. java:field:: Engine engine :outertype: Entity map ^^^ .. java:field:: Map map :outertype: Entity Key can be Double, String or Tuple. If this entity represents a single object, the entity contains at most one item and the key is null. name ^^^^ .. java:field:: String name :outertype: Entity type_ ^^^^^ .. java:field:: EntityType type_ :outertype: Entity Constructors ------------ Entity ^^^^^^ .. java:constructor:: Entity() :outertype: Entity Constructor Entity ^^^^^^ .. java:constructor:: Entity(AMPL ampl, Engine engine, String name, EntityType type) :outertype: Entity Constructor :param ampl: AMPL instance :param engine: Engine instance :param name: Entity's name Methods ------- addDependent ^^^^^^^^^^^^ .. java:method:: final void addDependent(Entity dep) :outertype: Entity areDependenciesUpdated ^^^^^^^^^^^^^^^^^^^^^^ .. java:method:: final boolean areDependenciesUpdated() :outertype: Entity checkDimensionOfKey ^^^^^^^^^^^^^^^^^^^ .. java:method:: boolean checkDimensionOfKey(Object t) :outertype: Entity checkForDeletion ^^^^^^^^^^^^^^^^ .. java:method:: boolean checkForDeletion() :outertype: Entity checkHasIndexing ^^^^^^^^^^^^^^^^ .. java:method:: void checkHasIndexing() :outertype: Entity clearNoData ^^^^^^^^^^^ .. java:method:: final void clearNoData() :outertype: Entity Clear the nodata flag displayEmbedded ^^^^^^^^^^^^^^^ .. java:method:: String displayEmbedded() :outertype: Entity Display the value(s) of the entity, using the embedded display routine :return: String visualization entrySet ^^^^^^^^ .. java:method:: public Set> entrySet() :outertype: Entity Get a set view of this entity. Each entry in the set contains the key (value of the indices) and the corresponding instance. For a scalar entity, a set with just one entry is returned, which has a null key and the only instance as value. The following example prints indices and values of the variable ``Buy`` indexed over the set ``FOOD`` (taken from the `diet model `_): .. parsed-literal:: for(Map.Entry e: ampl.getVariable("Buy").entrySet()) { Object food = e.getKey(); VariableInstance buy = e.getValue(); System.out.format("%s %g%n", food, buy.value()); } :return: An unmodifiable set containing all the entries of this entity. executeAMPLStatement ^^^^^^^^^^^^^^^^^^^^ .. java:method:: boolean executeAMPLStatement(String statement) :outertype: Entity fromMatlab ^^^^^^^^^^ .. java:method:: Object[] fromMatlab(double[] indices) :outertype: Entity fromMatlab ^^^^^^^^^^ .. java:method:: Object[] fromMatlab(J[] indices) :outertype: Entity get ^^^ .. java:method:: public abstract T get() :outertype: Entity Get the instance corresponding to a scalar entity. :throws UnsupportedOperationException: if the entity is not scalar. :throws IllegalStateException: if the entity has been deleted in the underlying AMPL interpreter :return: The corresponding instance. get ^^^ .. java:method:: public abstract T get(Object... key) :outertype: Entity Get the instance corresponding to the specified key. See :ref:`secAccessInstancesAndValues` for further information on how the key can be specified. :param key: Key of the instance to be found. :throws IllegalArgumentException: if trying to access an instance with the wrong number of keys (see :java:ref:`Entity.indexarity`) :throws IllegalStateException: if the entity has been deleted in the underlying AMPL interpreter :return: The instance corresponding to the key, or ``null`` if the specified key is not found. get ^^^ .. java:method:: public abstract T get(Tuple key) :outertype: Entity Get the instance corresponding to the specified tuple. See :ref:`secAccessInstancesAndValues` for further information on how the key can be specified. :param key: Key (in form of Tuple) of the instance to be found. :throws IllegalArgumentException: if trying to access an instance with the wrong number of keys (see :java:ref:`Entity.indexarity`) :throws IllegalStateException: if the entity has been deleted in the underlying AMPL interpreter :return: The instance corresponding to the key, or ``null`` if the specified key is not found. getAsDoubles ^^^^^^^^^^^^ .. java:method:: double[] getAsDoubles() :outertype: Entity Get value of all the instances in the current entity as doubles. Returns default suffixes: value for variables and objectives, body for constraints and the value of parameters. Casts the members of sets to doubles. :throws NumberFormatException: If the content of the entity cannot be represented by double numbers :return: Array of double numbers getAsDoubles ^^^^^^^^^^^^ .. java:method:: double[] getAsDoubles(String suffix) :outertype: Entity Get specific suffixes of the current entity as doubles :param suffix: The specific suffix to return :return: Array of double numbers getAsObjects ^^^^^^^^^^^^ .. java:method:: Object[] getAsObjects(String suffix) :outertype: Entity Get specific suffixes of the current entity as objects :param suffix: The specific suffix to return :return: Array of double numbers getDeclaration ^^^^^^^^^^^^^^ .. java:method:: String getDeclaration() :outertype: Entity Get the declaration of the AMPL entity represented by this Entity. :return: AMPL declaration of this entity. getDependents ^^^^^^^^^^^^^ .. java:method:: ArrayList> getDependents() :outertype: Entity getIndexingDummies ^^^^^^^^^^^^^^^^^^ .. java:method:: String getIndexingDummies() :outertype: Entity getIndexingSets ^^^^^^^^^^^^^^^ .. java:method:: public String[] getIndexingSets() :outertype: Entity Get the AMPL string representation of the sets on which this entity is indexed. :return: The string representation of the indexing sets for this entity or an empty array if the entity is scalar getIndices ^^^^^^^^^^ .. java:method:: public Set getIndices() :outertype: Entity Get all the keys in this entity. Not modifiable as a collection. :return: All the keys currently in the entity. getInstances ^^^^^^^^^^^^ .. java:method:: public Collection getInstances() :outertype: Entity Get all instances in this entity. Not modifiable as a collection :return: All instances currently generated for this entity. getMethod ^^^^^^^^^ .. java:method:: T getMethod(Object... key) throws AMPLException, IllegalArgumentException, UnsupportedOperationException :outertype: Entity getMethod ^^^^^^^^^ .. java:method:: T getMethod(Tuple key) throws AMPLException, IllegalArgumentException, UnsupportedOperationException :outertype: Entity getValues ^^^^^^^^^ .. java:method:: public DataFrame getValues() :outertype: Entity Get the principal values of this entity as a :java:ref:`DataFrame`. For variables and objectives it returns their suffix \ ``val``\ for parameters it returns their values for constraints it returns the suffix \ ``dual``\ for sets it returns all the members of the set :return: All instances getValues ^^^^^^^^^ .. java:method:: public DataFrame getValues(String... suffixes) :outertype: Entity Get all the specified values for this entity as a DataFrame object. The valid strings are all AMPL built-in suffixes for the entity under consideration. :param suffixes: A list of suffixes to be returned :throws IllegalArgumentException: if the specified suffix does not exist. :return: A :java:ref:`DataFrame` object with a column for each indexing set and a column for each one of the specified suffixes. hasData ^^^^^^^ .. java:method:: boolean hasData() :outertype: Entity hasIndexing ^^^^^^^^^^^ .. java:method:: @Deprecated public boolean hasIndexing() :outertype: Entity Check whether this entity is indexed over any set. Equivalent to testing whether :java:ref:`Entity.indexarity` is greater than zero. :return: True if the entity is not scalar (is indexed over a set) hasIndexingInstances ^^^^^^^^^^^^^^^^^^^^ .. java:method:: boolean hasIndexingInstances() :outertype: Entity indexarity ^^^^^^^^^^ .. java:method:: public int indexarity() :outertype: Entity Get the indexarity of this entity (sum of the dimensions of the indexing sets). This value indicates how many elements are to be passed to the method :java:ref:`Entity.get` in order to access an instance of this entity. See the following AMPL examples: .. parsed-literal:: var x; # indexarity = 0 var y {1..2}; # indexarity = 1 var z {1..2,3..4}; # indexarity = 2 var zz {{(1, 2)}}; # indexarity = 2 :return: The sum of the dimensions of the indexing sets or 0 if the entity is not indexed invalidate ^^^^^^^^^^ .. java:method:: void invalidate() :outertype: Entity invalidateDependencies ^^^^^^^^^^^^^^^^^^^^^^ .. java:method:: void invalidateDependencies() :outertype: Entity invalidateDependents ^^^^^^^^^^^^^^^^^^^^ .. java:method:: void invalidateDependents() :outertype: Entity isDeleted ^^^^^^^^^ .. java:method:: final boolean isDeleted() :outertype: Entity isScalar ^^^^^^^^ .. java:method:: public boolean isScalar() :outertype: Entity Check whether this entity is scalar. Equivalent to testing whether :java:ref:`Entity.indexarity` is equal to zero. :return: True if the entity is scalar (not indexed over any set) isValid ^^^^^^^ .. java:method:: final boolean isValid() :outertype: Entity name ^^^^ .. java:method:: public final String name() :outertype: Entity Get the AMPL name of this entity numInstances ^^^^^^^^^^^^ .. java:method:: public int numInstances() :outertype: Entity Get the number of instances in this entity onDelete ^^^^^^^^ .. java:method:: final void onDelete() :outertype: Entity printArguments ^^^^^^^^^^^^^^ .. java:method:: void printArguments(Object o) :outertype: Entity refreshDeclaration ^^^^^^^^^^^^^^^^^^ .. java:method:: boolean refreshDeclaration() :outertype: Entity Refresh the declaration (and sets) of this entity refreshInstances ^^^^^^^^^^^^^^^^ .. java:method:: abstract void refreshInstances() :outertype: Entity setDeclaration ^^^^^^^^^^^^^^ .. java:method:: abstract void setDeclaration(String declaration) :outertype: Entity setIndexArity ^^^^^^^^^^^^^ .. java:method:: void setIndexArity(int indexarity) :outertype: Entity setName ^^^^^^^ .. java:method:: final void setName(String name) :outertype: Entity setNoData ^^^^^^^^^ .. java:method:: final void setNoData() :outertype: Entity setSets ^^^^^^^ .. java:method:: void setSets(String[] sets) :outertype: Entity setValues ^^^^^^^^^ .. java:method:: public void setValues(DataFrame data) :outertype: Entity Set the values of this entiy to the correponding values of a DataFrame indexed over the same sets (or a subset). This function assigns the values in the first data column of the passed dataframe to the entity the function is called from. In particular, the statement:: x.setValues(y.getValues()); is semantically equivalent to the AMPL statement:: let {s in S} x[s] := y[s]; * :param data: setnewInstances ^^^^^^^^^^^^^^^ .. java:method:: @SuppressWarnings void setnewInstances(Instance[] newinstances) :outertype: Entity toString ^^^^^^^^ .. java:method:: @Override public String toString() :outertype: Entity Get a string representation of this entity; for all entity types, it returns the AMPL declaration. transformKey ^^^^^^^^^^^^ .. java:method:: Object transformKey(Object... key) :outertype: Entity update ^^^^^^ .. java:method:: final void update() :outertype: Entity Updates the entity if necessary by refreshing the instances updateDependenciesFlag ^^^^^^^^^^^^^^^^^^^^^^ .. java:method:: void updateDependenciesFlag() :outertype: Entity SetInstance dependencies valid flag validate ^^^^^^^^ .. java:method:: void validate() :outertype: Entity Flag this entity to valid xref ^^^^ .. java:method:: public List> xref() :outertype: Entity Get all the entities which depend on this one