.. java:import:: java.util Iterator Variable ======== .. java:package:: com.ampl :noindex: .. java:type:: public class Variable extends BasicEntity 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. Constructors ------------ Variable ^^^^^^^^ .. java:constructor:: public Variable(Entity entity) :outertype: Variable Constructor Variable ^^^^^^^^ .. java:constructor:: protected Variable(VariableBase impl) :outertype: Variable Methods ------- astatus ^^^^^^^ .. java:method:: public String astatus() :outertype: Variable Get the AMPL status (fixed, presolved, or substituted out) defeqn ^^^^^^ .. java:method:: public int defeqn() :outertype: Variable Get the index in \ ``_con``\ of "defining constraint" used to substitute variable out dual ^^^^ .. java:method:: public double dual() :outertype: Variable Get the dual value on defining constraint of variable substituted out fix ^^^ .. java:method:: public void fix() :outertype: Variable Fix all instances of this variable to their current value, equivalent to: .. parsed-literal:: fix varname; fix ^^^ .. 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; get ^^^ .. java:method:: public VariableInstance get() :outertype: Variable Get the corresponding :java:ref:`VariableInstance` instance (for not indexed variables) :throws IllegalArgumentException: if the entity has been deleted in the underlying AMPL :throws UnsupportedOperationException: if the entity is not scalar. get ^^^ .. java:method:: 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`) :return: The instance corresponding to the specified key. Returns ``null`` if the specified key is not present. get ^^^ .. java:method:: @Override 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`) :return: The variable instance corresponding to the specified key. Returns ``null`` if the specified key is not present. impl ^^^^ .. java:method:: VariableBase impl() :outertype: Variable init ^^^^ .. java:method:: public double init() :outertype: Variable Get the current initial guess init0 ^^^^^ .. java:method:: public double init0() :outertype: Variable Get the original initial guess (set by \ ``:=``\ or \ ``default``\ or by a data statement) integrality ^^^^^^^^^^^ .. java:method:: public Integrality integrality() :outertype: Variable Get the integrality status :return: Type of integrality (integer, binary, continuous) iterator ^^^^^^^^ .. java:method:: @Override public Iterator iterator() :outertype: Variable lb ^^ .. java:method:: public double lb() :outertype: Variable Returns the current lower bound. See :ref:`secVariableSuffixesNotes`. lb0 ^^^ .. java:method:: public double lb0() :outertype: Variable Returns the initial lower bounds, from the var declaration lb1 ^^^ .. java:method:: public double lb1() :outertype: Variable Returns the weaker lower bound from AMPL's presolve phase lb2 ^^^ .. java:method:: public double lb2() :outertype: Variable Returns the stronger lower bound from AMPL's presolve phase lrc ^^^ .. java:method:: public double lrc() :outertype: Variable Returns the reduced cost at lower bound lslack ^^^^^^ .. java:method:: public double lslack() :outertype: Variable Return the slack at lower bound (\ ``val - lb``\ ). See :ref:`secVariableSuffixesNotes`. rc ^^ .. java:method:: public double rc() :outertype: Variable Get the reduced cost (at the nearer bound) setValue ^^^^^^^^ .. 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 slack ^^^^^ .. java:method:: public double slack() :outertype: Variable Returns the bound slack which is the lesser of :java:ref:`lslack` and :java:ref:`uslack`. See :ref:`secVariableSuffixesNotes`. sstatus ^^^^^^^ .. java:method:: public String sstatus() :outertype: Variable Solver status (basis status of variable) status ^^^^^^ .. java:method:: public String status() :outertype: Variable AMPL status if not \ ``in``\ , otherwise solver status ub ^^ .. java:method:: public double ub() :outertype: Variable Returns the current upper bound. See :ref:`secVariableSuffixesNotes`. ub0 ^^^ .. java:method:: public double ub0() :outertype: Variable Returns the initial upper bound, from the var declaration ub1 ^^^ .. java:method:: public double ub1() :outertype: Variable Returns the weaker upper bound from AMPL's presolve phase ub2 ^^^ .. java:method:: public double ub2() :outertype: Variable Returns the stronger upper bound from AMPL's presolve phase unfix ^^^^^ .. java:method:: public void unfix() :outertype: Variable Unfix all instances of the current variable, equivalent to the AMPL code: .. parsed-literal:: unfix varname; urc ^^^ .. java:method:: public double urc() :outertype: Variable Returns the reduced cost at upper bound uslack ^^^^^^ .. java:method:: public double uslack() :outertype: Variable Return the slack at upper bound (\ ``ub - val``\ ). See :ref:`secVariableSuffixesNotes`. value ^^^^^ .. java:method:: public double value() :outertype: Variable Get the current value of this variable instance