Variable¶
-
public class
Variable
extends Entity<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.
Methods¶
-
public int
defeqn
()¶ Get the index in
_con
of “defining constraint” used to substitute variable out
-
public double
dual
()¶ Get the dual value on defining constraint of variable substituted out
-
public void
fix
()¶ Fix all instances of this variable to their current value, equivalent to:
fix varname;
-
public void
fix
(double value)¶ (for scalar variables) fix the variable to the specified value, equivalent to:
fix varname := value;
-
public VariableInstance
get
()¶ Get the corresponding
VariableInstance
instance (for not indexed variables)Throws: - UnsupportedOperationException – if the entity is not scalar.
- IllegalStateException – if the entity has been deleted in the underlying AMPL
-
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
) - IllegalStateException – if the entity has been deleted in the underlying AMPL interpreter
Returns: The instance corresponding to the specified key. Returns
null
if the specified key is not present.
-
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
) - IllegalStateException – if the entity has been deleted in the underlying AMPL interpreter
Returns: The variable instance corresponding to the specified key. Returns
null
if the specified key is not present.
-
public double
init
()¶ Get the current initial guess
-
public double
init0
()¶ Get the original initial guess (set by
:=
ordefault
or by a data statement)
-
public Integrality
integrality
()¶ Get the integrality status
Returns: Type of integrality (integer, binary, continuous)
-
public double
lb
()¶ Returns the current lower bound
-
public double
lb0
()¶ Returns the initial lower bounds, from the var declaration
-
public double
lb1
()¶ Returns the weaker lower bound from AMPL’s presolve phase
-
public double
lb2
()¶ Returns the stronger lower bound from AMPL’s presolve phase
-
public double
lrc
()¶ Returns the reduced cost at lower bound
-
public double
lslack
()¶ Return the slack at lower bound (
val - lb
)
-
public double
rc
()¶ Get the reduced cost (at the nearer bound)
-
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
-
public String
toString
()¶ Returns a string representation of this variable. Equivalent to the AMPL statement
show variableName;
-
public double
ub
()¶ Returns the current upper bound.
-
public double
ub0
()¶ Returns the initial upper bound, from the var declaration
-
public double
ub1
()¶ Returns the weaker upper bound from AMPL’s presolve phase
-
public double
ub2
()¶ Returns the stronger upper bound from AMPL’s presolve phase
-
public void
unfix
()¶ Unfix all instances of the current variable, equivalent to the AMPL code:
unfix varname;
-
public double
urc
()¶ Returns the reduced cost at upper bound
-
public double
uslack
()¶ Return the slack at upper bound (
ub - val
)
-
public double
value
()¶ Get the current value of this variable instance