Class Expression
- All Implemented Interfaces:
Comparable<Expression>
,Optimisation
,Optimisation.Constraint
,Optimisation.Objective
Think of an Expression as one constraint or a component to the objective function. An expression becomes a linear expression as soon as you set a linear factor. Setting a quadratic factor turns it into a quadratic expression. If you set both linear and quadratic factors it is a compound expression, and if you set neither it is an empty expression. Currently the solvers supplied by ojAlgo can only handle linear constraint expressions. The objective function can be linear, quadratic or compound. Empty expressions makes no sense...
An expression is turned into a constraint by setting a lower and/or upper limit. Use ModelEntity.lower(Comparable), ModelEntity.upper(Comparable) or ModelEntity.level(Comparable). An expression is made part of (contributing to) the objective function by setting a contribution weight. Use ModelEntity.weight(Comparable). The contribution weight can be set to anything except zero (0.0). Often you may just want to set it to one (1.0). Other values can be used to balance multiple expressions contributing to the objective function.
-
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
FieldsModifier and TypeFieldDescriptionprivate BigDecimal
private boolean
private Boolean
private final Map
<Structure1D.IntIndex, BigDecimal> private final ExpressionsBasedModel
private final Map
<Structure2D.IntRowColumn, BigDecimal> private boolean
private final boolean
A shallow copy (typically created by presolver or integer solver) shares the Map:s holding the paramaters with other Expressions.Fields inherited from class org.ojalgo.optimisation.ModelEntity
PRINT, RANGE
-
Constructor Summary
ConstructorsModifierConstructorDescription(package private)
Expression
(String name, ExpressionsBasedModel model) private
Expression
(Expression entityToCopy) protected
Expression
(Expression expressionToCopy, ExpressionsBasedModel destinationModel, boolean deep) -
Method Summary
Modifier and TypeMethodDescriptionadd
(int index, double value) add
(int row, int column, double value) add
(int row, int column, long value) add
(int row, int column, Comparable<?> value) add
(int index, long value) add
(int index, Comparable<?> value) add
(Variable variable, Comparable<?> value) Will add the value to this variable's factor.add
(Variable variable1, Variable variable2, Comparable<?> value) (package private) void
addObjectiveConstant
(BigDecimal value) void
addTo
(Expression target, BigDecimal scale) protected void
appendMiddlePart
(StringBuilder builder, Access1D<BigDecimal> solution, NumberContext display) (package private) void
appendToString
(StringBuilder builder, Access1D<BigDecimal> solution, NumberContext display) (package private) BigDecimal
Calculates this expression's value - the subset variables' part of this expression.int
compareTo
(Expression obj) compensate
(Set<Structure1D.IntIndex> fixedVariables) Will return an Expression with factors corresponding to fixed variables removed, and lower/upper limits compensated for the fixed part of the expression.private BigDecimal
convert
(BigDecimal value, boolean adjusted) (package private) Expression
copy
(ExpressionsBasedModel destinationModel, boolean deep) (package private) long
(package private) int
(package private) int
(package private) int
protected void
destroy()
private Expression
doAdd
(Structure1D.IntIndex key, BigDecimal value) private Expression
doAdd
(Structure2D.IntRowColumn key, BigDecimal value) (package private) void
Assumes at least 1 variable, and all variables integer!(package private) void
doIntegerRounding
(Set<Structure1D.IntIndex> remaining, BigDecimal lower, BigDecimal upper) (package private) Expression
(package private) Expression
doSet
(Structure1D.IntIndex key, BigDecimal value) (package private) Expression
doSet
(Structure2D.IntRowColumn key, BigDecimal value) double
doubleValue
(Structure1D.IntIndex key, boolean adjusted) double
doubleValue
(Structure2D.IntRowColumn key, boolean adjusted) void
enforce
(NumberContext enforcer) evaluate
(Access1D<BigDecimal> point) get
(Structure1D.IntIndex key) get
(Structure1D.IntIndex key, boolean adjusted) get
(Structure2D.IntRowColumn key, boolean adjusted) getAdjustedGradient
(Access1D<?> point) getBinaryVariables
(Set<Structure1D.IntIndex> subset) private BigDecimal
(package private) Map
<Structure1D.IntIndex, BigDecimal> (package private) ExpressionsBasedModel
getModel()
(package private) Map
<Structure2D.IntRowColumn, BigDecimal> (package private) boolean
boolean
boolean
(package private) boolean
boolean
boolean
boolean
boolean
(package private) boolean
boolean
Is this entity (all involved variables) integer?boolean
boolean
boolean
boolean
(package private) boolean
isNegativeOn
(Set<Structure1D.IntIndex> subset) (package private) boolean
isPositiveOn
(Set<Structure1D.IntIndex> subset) (package private) boolean
private AffineFunction
<Double> private ConstantFunction
<Double> private PureQuadraticFunction
<Double> private QuadraticFunction
<Double> (package private) Variable
resolve
(Structure1D.IntIndex index) set
(int index, double value) set
(int row, int column, double value) set
(int row, int column, long value) set
(int row, int column, Comparable<?> value) set
(int index, long value) set
(int index, Comparable<?> value) set
(Variable variable, Comparable<?> value) Will set (replace) the variable's factor to this valueset
(Variable variable1, Variable variable2, Comparable<?> value) void
setCompoundFactorsOffset
(List<Variable> variables, Access1D<?> point) Will set the quadratic and linear factors to an expression that measures (the square of) the distance from the given point.(package private) void
setConstant
(double value) (package private) void
setConstant
(long value) (package private) void
setConstant
(Comparable<?> value) (package private) void
(package private) void
void
setLinearFactors
(List<Variable> variables, Access1D<?> factors) void
setLinearFactorsSimple
(List<Variable> variables) Will set the linear factors to a simple sum expression - all factors equal 1.0.void
setQuadraticFactors
(List<Variable> variables, Access2D<?> factors) (package private) void
void
tighten()
Will attempt to exploit integer property to tighten the lower and/or upper limits (integer rounding).private Structure1D.IntIndex
toIntIndex
(int index) private Structure1D.IntIndex
toIntIndex
(Variable variable) private Structure2D.IntRowColumn
toIntRowColumn
(int row, int column) private Structure2D.IntRowColumn
toIntRowColumn
(Variable variable1, Variable variable2) private BigDecimal
toPositiveFraction
(BigDecimal noninteger) Methods inherited from class org.ojalgo.optimisation.ModelEntity
adjust, appendLeftPart, appendMiddlePart, appendRightPart, appendToString, deriveAdjustmentExponent, equals, getAdjustmentExponent, getAdjustmentExponentValue, getAdjustmentFactor, getCompensatedLowerLimit, getCompensatedLowerLimit, getCompensatedUpperLimit, getCompensatedUpperLimit, getContributionWeight, getLowerLimit, getLowerLimit, getLowerLimit, getName, getUpperLimit, getUpperLimit, getUpperLimit, hashCode, isClosedRange, isConstraint, isContributionWeightSet, isEqualityConstraint, isInfeasible, isLowerConstraint, isLowerLimitSet, isObjective, isUpperConstraint, isUpperLimitSet, level, level, level, lower, lower, lower, reverseAdjustment, shift, toAdjusted, toBigDecimal, toString, toUnadjusted, upper, upper, upper, validate, validate, weight, weight, weight
-
Field Details
-
myConstant
-
myInfeasible
private transient boolean myInfeasible -
myInteger
-
myLinear
-
myModel
-
myQuadratic
-
myRedundant
private transient boolean myRedundant -
myShallowCopy
private final boolean myShallowCopyA shallow copy (typically created by presolver or integer solver) shares the Map:s holding the paramaters with other Expressions. They will only differ on the lower/upper limits and on meta data like flags indicating redundancy or infeasibility.
-
-
Constructor Details
-
Expression
-
Expression
protected Expression(Expression expressionToCopy, ExpressionsBasedModel destinationModel, boolean deep) -
Expression
Expression(String name, ExpressionsBasedModel model)
-
-
Method Details
-
add
- See Also:
-
add
- See Also:
-
add
- See Also:
-
add
- See Also:
-
add
- See Also:
-
add
- See Also:
-
add
Will add the value to this variable's factor. -
add
- See Also:
-
add
- See Also:
-
add
- See Also:
-
add
- See Also:
-
add
- See Also:
-
addTo
Description copied from class:ModelEntity
- Specified by:
addTo
in classModelEntity<Expression>
- Parameters:
target
- The targetExpression
scale
- The scaling factor
-
compareTo
-
compensate
Will return an Expression with factors corresponding to fixed variables removed, and lower/upper limits compensated for the fixed part of the expression. Factors corresponding to bilinear variables, where one is fixed and the other is not, are linearized.- Parameters:
fixedVariables
- A set of (by the presolver) fixed variable indices- Returns:
- The reduced/modified expression
-
doubleValue
-
doubleValue
-
enforce
-
evaluate
-
get
-
get
-
get
-
get
-
get
-
getAdjustedGradient
-
getAdjustedHessian
-
getLinearEntrySet
-
getLinearKeySet
-
getQuadraticEntrySet
-
getQuadraticKeySet
-
isAnyLinearFactorNonZero
public boolean isAnyLinearFactorNonZero() -
isAnyQuadraticFactorNonZero
public boolean isAnyQuadraticFactorNonZero() -
isFunctionConstant
public boolean isFunctionConstant() -
isFunctionLinear
public boolean isFunctionLinear() -
isFunctionPureQuadratic
public boolean isFunctionPureQuadratic() -
isFunctionQuadratic
public boolean isFunctionQuadratic() -
isInteger
public boolean isInteger()Description copied from class:ModelEntity
Is this entity (all involved variables) integer?- Specified by:
isInteger
in classModelEntity<Expression>
-
isLinearAndAllBinary
public boolean isLinearAndAllBinary()- Returns:
- Are all the (linear) variables binary
-
isLinearAndAllInteger
public boolean isLinearAndAllInteger()- Returns:
- Are all the (linear) variables integer
-
isLinearAndAnyBinary
public boolean isLinearAndAnyBinary()- Returns:
- Are any of the (linear) variables binary
-
isLinearAndAnyInteger
public boolean isLinearAndAnyInteger()- Returns:
- Are any of the (linear) variables integer
-
set
- See Also:
-
set
- See Also:
-
set
- See Also:
-
set
- See Also:
-
set
- See Also:
-
set
- See Also:
-
set
Will set (replace) the variable's factor to this value -
set
- See Also:
-
set
- See Also:
-
set
- See Also:
-
set
- See Also:
-
set
- See Also:
-
setCompoundFactorsOffset
Will set the quadratic and linear factors to an expression that measures (the square of) the distance from the given point.- Parameters:
variables
- The relevant variablespoint
- The point to measure from
-
setLinearFactors
-
setLinearFactorsSimple
Will set the linear factors to a simple sum expression - all factors equal 1.0.- Parameters:
variables
- The relevant variables
-
setQuadraticFactors
-
tighten
public void tighten()Will attempt to exploit integer property to tighten the lower and/or upper limits (integer rounding). -
toFunction
-
convert
-
doAdd
-
doAdd
-
getConstant
-
makeAffineFunction
-
makeConstantFunction
-
makePureQuadraticFunction
-
makeQuadraticFunction
-
toIntIndex
-
toIntIndex
-
toIntRowColumn
-
toIntRowColumn
-
toPositiveFraction
-
appendMiddlePart
protected void appendMiddlePart(StringBuilder builder, Access1D<BigDecimal> solution, NumberContext display) -
destroy
protected void destroy()- Overrides:
destroy
in classModelEntity<Expression>
-
addObjectiveConstant
-
appendToString
-
calculateSetValue
Calculates this expression's value - the subset variables' part of this expression. Will never return null. -
copy
-
countIntegerFactors
long countIntegerFactors() -
countLinearFactors
int countLinearFactors() -
countQuadraticFactors
int countQuadraticFactors() -
deriveAdjustmentExponent
int deriveAdjustmentExponent()- Specified by:
deriveAdjustmentExponent
in classModelEntity<Expression>
-
doIntegerRounding
void doIntegerRounding()Assumes at least 1 variable, and all variables integer!- Specified by:
doIntegerRounding
in classModelEntity<Expression>
- See Also:
-
doIntegerRounding
-
doMixedIntegerRounding
Expression doMixedIntegerRounding() -
doSet
-
doSet
-
getBinaryVariables
-
getLinear
Map<Structure1D.IntIndex,BigDecimal> getLinear() -
getModel
ExpressionsBasedModel getModel() -
getQuadratic
Map<Structure2D.IntRowColumn,BigDecimal> getQuadratic() -
includes
-
isConstantSet
boolean isConstantSet() -
isInfeasible
boolean isInfeasible()- Overrides:
isInfeasible
in classModelEntity<Expression>
-
isNegativeOn
- Parameters:
subset
- The indices of a variable subset- Returns:
- true if none of the variables in the subset can make a positve contribution to the expression value
-
isPositiveOn
- Parameters:
subset
- The indices of a variable subset- Returns:
- true if none of the variables in the subset can make a negative contribution to the expression value
-
isRedundant
boolean isRedundant() -
resolve
-
setConstant
-
setConstant
void setConstant(double value) -
setConstant
void setConstant(long value) -
setInfeasible
void setInfeasible() -
setInteger
void setInteger() -
setRedundant
void setRedundant()
-