Variable¶
-
public class
Variable
extends BasicEntity<VariableInstance>¶ 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
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
UnsupportedOperationException
if called for an entity which is not scalar.Otherwise, use the method
Variable.get
to obtain the objects of typeVariableInstance
, from which to access all properties (corresponding to AMPL suffixes). See section Access to instances and values 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
Entity.getValues
and theDataFrame
class.
Constructors¶
Methods¶
defeqn¶
-
public int
defeqn
()¶ Get the index in
_con
of “defining constraint” used to substitute variable out
fix¶
-
public void
fix
()¶ Fix all instances of this variable to their current value, equivalent to:
fix varname;
fix¶
-
public void
fix
(double value)¶ (for scalar variables) fix the variable to the specified value, equivalent to:
fix varname := value;
get¶
-
public VariableInstance
get
()¶ Get the corresponding
VariableInstance
instance (for not indexed variables)Throws: - IllegalArgumentException – if the entity has been deleted in the underlying AMPL
- UnsupportedOperationException – if the entity is not scalar.
get¶
-
public final VariableInstance
get
(Object... key)¶ Get the variable instance corresponding to the specified key. See Access to instances and values for further information on how the key can be specified.
Parameters: - key – The key to be found
Throws: - IllegalArgumentException – if trying to access an instance with the wrong number of keys (see
Entity.indexarity
)
Returns: The instance corresponding to the specified key. Returns
null
if the specified key is not present.
get¶
-
public VariableInstance
get
(Tuple key)¶ Get the variable instance corresponding to the specified key, expressed as a Tuple. See Access to instances and values for further information on how the key can be specified.
Parameters: - key – The indexing Tuple of the instance to be found
Throws: - IllegalArgumentException – if trying to access an instance with the wrong indexarity (see
Entity.indexarity
)
Returns: The variable instance corresponding to the specified key. Returns
null
if the specified key is not present.
init0¶
-
public double
init0
()¶ Get the original initial guess (set by
:=
ordefault
or by a data statement)
integrality¶
-
public Integrality
integrality
()¶ Get the integrality status
Returns: Type of integrality (integer, binary, continuous)
iterator¶
-
public Iterator<VariableInstance>
iterator
()¶
lb¶
-
public double
lb
()¶ Returns the current lower bound. See Note on variables suffixes.
lslack¶
-
public double
lslack
()¶ Return the slack at lower bound (
val - lb
). See Note on variables suffixes.
setValue¶
-
public void
setValue
(double value)¶ Set the current value of this variable instance
Parameters: - value – Value to be set
Throws: - UnsupportedOperationException – if the entity is not scalar
slack¶
-
public double
slack
()¶ Returns the bound slack which is the lesser of
lslack
anduslack
. See Note on variables suffixes.
ub¶
-
public double
ub
()¶ Returns the current upper bound. See Note on variables suffixes.
unfix¶
-
public void
unfix
()¶ Unfix all instances of the current variable, equivalent to the AMPL code:
unfix varname;
uslack¶
-
public double
uslack
()¶ Return the slack at upper bound (
ub - val
). See Note on variables suffixes.