- java.lang.Object
-
- org.ojalgo.optimisation.ModelEntity<Variable>
-
- org.ojalgo.optimisation.Variable
-
- All Implemented Interfaces:
java.lang.Comparable<Variable>,Optimisation,Optimisation.Constraint,Optimisation.Objective
public final class Variable extends ModelEntity<Variable>
Variable represents a decision variable in an optimization model.Each variable has a unique index in the model and can have:
- Lower and upper bounds (constraints)
- A contribution weight in the objective function
- An integer or continuous domain
- A current value
Variables can be configured as:
- Binary (0-1 integer variables)
- Integer (whole number values only)
- Continuous (any value within bounds)
- Fixed (equal lower and upper bounds)
- Unbounded (no effective limits)
As a subclass of ModelEntity, a Variable can function both as a constraint (through lower/upper bounds) and as an objective function component (through its contribution weight).
Variables are typically created and managed through
ExpressionsBasedModel, which assigns their indices and incorporates them into the optimization problem.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.ojalgo.optimisation.Optimisation
Optimisation.Constraint, Optimisation.ConstraintType, Optimisation.Integration<M extends Optimisation.Model,S extends Optimisation.Solver>, Optimisation.Model, Optimisation.Objective, Optimisation.Options, Optimisation.ProblemStructure, Optimisation.Result, Optimisation.Sense, Optimisation.Solver, Optimisation.State
-
-
Field Summary
Fields Modifier and Type Field Description private Structure1D.IntIndexmyIndexprivate booleanmyIntegerprivate booleanmyUnboundedprivate java.math.BigDecimalmyValue-
Fields inherited from class org.ojalgo.optimisation.ModelEntity
PRINT, RANGE
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddTo(Expression target, java.math.BigDecimal scale)protected voidappendMiddlePart(java.lang.StringBuilder builder, NumberContext display)private voidassertFixedValue()Variablebinary()SeeisBinary().intcompareTo(Variable obj)(package private) Variablecopy()Internal copy that includes the index(package private) intderiveAdjustmentExponent()protected voiddestroy()(package private) voiddoIntegerRounding()If necessary this method should first determine if thisModelEntityis "integer" or not.booleanequals(java.lang.Object obj)(package private) Structure1D.IntIndexgetIndex()java.math.BigDecimalgetLowerSlack()java.math.BigDecimalgetUpperSlack()java.math.BigDecimalgetValue()inthashCode()Variableinteger()Variableinteger(boolean integer)SeeisInteger().booleanisBinary()Variable can only be 0 or 1.(package private) booleanisFixed()booleanisInteger()Is this entity (all involved variables) integer?booleanisNegative()The range includes something < 0.0booleanisPositive()The range includes something > 0.0(package private) booleanisUnbounded()booleanisValueSet()Variablelower(java.lang.Comparable<?> lower)Extremely large (absolute value) values are treated as "no limit" (null) and extremely small values are treated as exactly 0.0, unless the input number type isBigDecimal.java.math.BigDecimalquantifyContribution()Variablerelax()(package private) voidsetFixed(java.math.BigDecimal value)voidsetInteger(boolean integer)(package private) voidsetUnbounded(boolean uncorrelated)voidsetValue(java.lang.Comparable<?> value)Variableupper(java.lang.Comparable<?> upper)Extremely large (absolute value) values are treated as "no limit" (null) and extremely small values are treated as exactly 0.0, unless the input number type isBigDecimal.protected booleanvalidate(java.math.BigDecimal value, NumberContext context, BasicLogger appender)(package private) booleanvalidate(java.math.BigDecimal value, NumberContext context, BasicLogger appender, boolean relaxed)Variablevalue(java.math.BigDecimal value)-
Methods inherited from class org.ojalgo.optimisation.ModelEntity
adjust, appendLeftPart, appendRightPart, appendToString, deriveAdjustmentExponent, getAdjustmentExponent, getAdjustmentExponentValue, getAdjustmentFactor, getCompensatedLowerLimit, getCompensatedLowerLimit, getCompensatedUpperLimit, getCompensatedUpperLimit, getContributionWeight, getLowerLimit, getLowerLimit, getLowerLimit, getName, getUpperLimit, getUpperLimit, getUpperLimit, isClosedRange, isConstraint, isContributionWeightSet, isEqualityConstraint, isInfeasible, isInfeasible, isLowerConstraint, isLowerLimitSet, isObjective, isUpperConstraint, isUpperLimitSet, level, level, level, lower, lower, reverseAdjustment, shift, toAdjusted, toBigDecimal, toString, toUnadjusted, upper, upper, validate, weight, weight, weight
-
-
-
-
Field Detail
-
myIndex
private final Structure1D.IntIndex myIndex
-
myInteger
private boolean myInteger
-
myUnbounded
private transient boolean myUnbounded
-
myValue
private java.math.BigDecimal myValue
-
-
Constructor Detail
-
Variable
Variable(java.lang.String name, int index)
-
Variable
Variable(Variable variableToCopy)
-
-
Method Detail
-
addTo
public void addTo(Expression target, java.math.BigDecimal scale)
Description copied from class:ModelEntity- Specified by:
addToin classModelEntity<Variable>- Parameters:
target- The targetExpressionscale- The scaling factor
-
binary
public Variable binary()
SeeisBinary().- See Also:
ModelEntity.getUpperLimit(),isInteger(),isBinary()
-
compareTo
public int compareTo(Variable obj)
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classModelEntity<Variable>
-
getLowerSlack
public java.math.BigDecimal getLowerSlack()
-
getUpperSlack
public java.math.BigDecimal getUpperSlack()
-
getValue
public java.math.BigDecimal getValue()
-
hashCode
public int hashCode()
- Overrides:
hashCodein classModelEntity<Variable>
-
integer
public Variable integer()
-
integer
public Variable integer(boolean integer)
SeeisInteger().
-
isBinary
public boolean isBinary()
Variable can only be 0 or 1.
-
isInteger
public boolean isInteger()
Description copied from class:ModelEntityIs this entity (all involved variables) integer?- Specified by:
isIntegerin classModelEntity<Variable>- Returns:
- true if this is an integer variable, otherwise false
-
isNegative
public boolean isNegative()
The range includes something < 0.0
-
isPositive
public boolean isPositive()
The range includes something > 0.0
-
isValueSet
public boolean isValueSet()
-
lower
public Variable lower(java.lang.Comparable<?> lower)
Description copied from class:ModelEntityExtremely large (absolute value) values are treated as "no limit" (null) and extremely small values are treated as exactly 0.0, unless the input number type isBigDecimal.BigDecimalvalues are always used as they are.- Overrides:
lowerin classModelEntity<Variable>
-
quantifyContribution
public java.math.BigDecimal quantifyContribution()
-
relax
public Variable relax()
-
setInteger
public void setInteger(boolean integer)
-
setValue
public void setValue(java.lang.Comparable<?> value)
-
upper
public Variable upper(java.lang.Comparable<?> upper)
Description copied from class:ModelEntityExtremely large (absolute value) values are treated as "no limit" (null) and extremely small values are treated as exactly 0.0, unless the input number type isBigDecimal.BigDecimalvalues are always used as they are.- Overrides:
upperin classModelEntity<Variable>
-
value
public Variable value(java.math.BigDecimal value)
-
assertFixedValue
private void assertFixedValue()
-
appendMiddlePart
protected void appendMiddlePart(java.lang.StringBuilder builder, NumberContext display)- Overrides:
appendMiddlePartin classModelEntity<Variable>
-
destroy
protected void destroy()
- Overrides:
destroyin classModelEntity<Variable>
-
validate
protected boolean validate(java.math.BigDecimal value, NumberContext context, BasicLogger appender)- Overrides:
validatein classModelEntity<Variable>
-
copy
Variable copy()
Internal copy that includes the index
-
deriveAdjustmentExponent
int deriveAdjustmentExponent()
- Specified by:
deriveAdjustmentExponentin classModelEntity<Variable>
-
doIntegerRounding
void doIntegerRounding()
Description copied from class:ModelEntityIf necessary this method should first determine if thisModelEntityis "integer" or not.If it is, then verify if all variable factors are integers or if there exists a simple scalar that will make it so. If so, the lower/upper limits are "integer rounded".
- Specified by:
doIntegerRoundingin classModelEntity<Variable>
-
getIndex
Structure1D.IntIndex getIndex()
-
isFixed
boolean isFixed()
-
isUnbounded
boolean isUnbounded()
-
setFixed
void setFixed(java.math.BigDecimal value)
-
setUnbounded
void setUnbounded(boolean uncorrelated)
-
validate
boolean validate(java.math.BigDecimal value, NumberContext context, BasicLogger appender, boolean relaxed)
-
-