Variable ======== .. java:package:: com.ampl :noindex: .. java:type:: public class Variable extends Entity Represents an AMPL decision variable. Note that, in case of a scalar variable, all the properties of the variable instance can be accessed through methods like :java:ref:`Variable.value`. The methods have the same name of the corresponding AMPL suffixes. See http://www.ampl.com/NEW/suffbuiltin.html for a list of the available suffixes. All these methods throw an :java:ref:`UnsupportedOperationException` if called for an entity which is not scalar. Otherwise, use the method :java:ref:`Variable.get` to obtain the objects of type :java:ref:`VariableInstance`, from which to access all properties (corresponding to AMPL suffixes). See section :ref:`secAccessInstancesAndValues` for further information on how to access set instances. To gain access to all the values in an entity (for all instances and all suffixes for that entities), see :java:ref:`Entity.getValues` and the :java:ref:`DataFrame` class. Methods ------- .. java:method:: public String astatus() :outertype: Variable Get the AMPL status (fixed, presolved, or substituted out) .. java:method:: public int defeqn() :outertype: Variable Get the index in \ ``_con``\ of "defining constraint" used to substitute variable out .. java:method:: public double dual() :outertype: Variable Get the dual value on defining constraint of variable substituted out .. java:method:: public void fix() :outertype: Variable Fix all instances of this variable to their current value, equivalent to: .. parsed-literal:: fix varname; .. java:method:: public void fix(double value) :outertype: Variable (for scalar variables) fix the variable to the specified value, equivalent to: .. parsed-literal:: fix varname := value; .. java:method:: @Override public VariableInstance get() :outertype: Variable Get the corresponding :java:ref:`VariableInstance` instance (for not indexed variables) :throws UnsupportedOperationException: if the entity is not scalar. :throws IllegalStateException: if the entity has been deleted in the underlying AMPL .. java:method:: @Override public final VariableInstance get(Object... key) throws IllegalArgumentException :outertype: Variable Get the variable instance corresponding to the specified key. See :ref:`secAccessInstancesAndValues` for further information on how the key can be specified. :param key: The key 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 specified key. Returns ``null`` if the specified key is not present. .. java:method:: public VariableInstance get(Tuple key) :outertype: Variable Get the variable instance corresponding to the specified key, expressed as a Tuple. See :ref:`secAccessInstancesAndValues` for further information on how the key can be specified. :param key: The indexing Tuple of the instance to be found :throws IllegalArgumentException: if trying to access an instance with the wrong indexarity (see :java:ref:`Entity.indexarity`) :throws IllegalStateException: if the entity has been deleted in the underlying AMPL interpreter :return: The variable instance corresponding to the specified key. Returns ``null`` if the specified key is not present. .. java:method:: public double init() :outertype: Variable Get the current initial guess .. java:method:: public double init0() :outertype: Variable Get the original initial guess (set by \ ``:=``\ or \ ``default``\ or by a data statement) .. java:method:: public Integrality integrality() :outertype: Variable Get the integrality status :return: Type of integrality (integer, binary, continuous) .. java:method:: public double lb() :outertype: Variable Returns the current lower bound .. java:method:: public double lb0() :outertype: Variable Returns the initial lower bounds, from the var declaration .. java:method:: public double lb1() :outertype: Variable Returns the weaker lower bound from AMPL's presolve phase .. java:method:: public double lb2() :outertype: Variable Returns the stronger lower bound from AMPL's presolve phase .. java:method:: public double lrc() :outertype: Variable Returns the reduced cost at lower bound .. java:method:: public double lslack() :outertype: Variable Return the slack at lower bound (\ ``val - lb``\ ) .. java:method:: public double rc() :outertype: Variable Get the reduced cost (at the nearer bound) .. java:method:: public void setValue(double value) :outertype: Variable Set the current value of this variable instance :param value: Value to be set :throws UnsupportedOperationException: if the entity is not scalar .. java:method:: public double slack() :outertype: Variable Returns the bound slack which is the lesser of :java:ref:`lslack` and :java:ref:`uslack`. .. java:method:: public String sstatus() :outertype: Variable Solver status (basis status of variable) .. java:method:: public String status() :outertype: Variable AMPL status if not \ ``in``\ , otherwise solver status .. java:method:: @Override public String toString() :outertype: Variable Returns a string representation of this variable. Equivalent to the AMPL statement .. parsed-literal:: show variableName; .. java:method:: public double ub() :outertype: Variable Returns the current upper bound. .. java:method:: public double ub0() :outertype: Variable Returns the initial upper bound, from the var declaration .. java:method:: public double ub1() :outertype: Variable Returns the weaker upper bound from AMPL's presolve phase .. java:method:: public double ub2() :outertype: Variable Returns the stronger upper bound from AMPL's presolve phase .. java:method:: public void unfix() :outertype: Variable Unfix all instances of the current variable, equivalent to the AMPL code: .. parsed-literal:: unfix varname; .. java:method:: public double urc() :outertype: Variable Returns the reduced cost at upper bound .. java:method:: public double uslack() :outertype: Variable Return the slack at upper bound (\ ``ub - val``\ ) .. java:method:: public double value() :outertype: Variable Get the current value of this variable instance