public final class Expression extends Object
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(Number), ModelEntity.upper(Number) or ModelEntity.level(Number). An expression is made part of (contributing to) the objective function by setting a contribution weight. Use ModelEntity.weight(Number). 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.
Optimisation.Constraint, Optimisation.Integration<M extends Optimisation.Model,S extends Optimisation.Solver>, Optimisation.Model, Optimisation.Objective, Optimisation.Options, Optimisation.Result, Optimisation.Solver, Optimisation.State
Modifier | Constructor and Description |
---|---|
protected |
Expression(Expression expressionToCopy,
ExpressionsBasedModel destinationModel,
boolean deep) |
Modifier and Type | Method and Description |
---|---|
Expression |
add(Structure1D.IntIndex key,
Number value) |
Expression |
add(Structure2D.IntRowColumn key,
Number value) |
protected void |
appendLeftPart(StringBuilder builder) |
protected void |
appendMiddlePart(StringBuilder builder) |
protected void |
appendMiddlePart(StringBuilder builder,
Access1D<BigDecimal> currentSolution) |
protected void |
appendRightPart(StringBuilder builder) |
int |
compareTo(Expression obj) |
Expression |
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.
|
protected void |
destroy() |
protected void |
doIntegerRounding() |
boolean |
equals(Object obj) |
BigDecimal |
evaluate(Access1D<BigDecimal> point) |
BigDecimal |
get(Structure1D.IntIndex key) |
BigDecimal |
get(Structure2D.IntRowColumn key) |
BigDecimal |
get(Variable variable) |
MatrixStore<Double> |
getAdjustedGradient(Access1D<?> point) |
MatrixStore<Double> |
getAdjustedHessian() |
double |
getAdjustedLinearFactor(int aVar) |
double |
getAdjustedLinearFactor(Structure1D.IntIndex key) |
double |
getAdjustedLinearFactor(Variable aVar) |
double |
getAdjustedLowerLimit() |
double |
getAdjustedQuadraticFactor(int aVar1,
int aVar2) |
double |
getAdjustedQuadraticFactor(Structure2D.IntRowColumn key) |
double |
getAdjustedQuadraticFactor(Variable aVar1,
Variable aVar2) |
double |
getAdjustedUpperLimit() |
protected int |
getAdjustmentExponent() |
double |
getAdjustmentFactor() |
BigDecimal |
getContributionWeight()
The weight/factor by which this model entity's value contributes to the objective function - may
return null.
|
Set<Map.Entry<Structure1D.IntIndex,BigDecimal>> |
getLinearEntrySet() |
Set<Structure1D.IntIndex> |
getLinearKeySet() |
BigDecimal |
getLowerLimit()
The lower limit/bound - may return null.
|
String |
getName() |
Set<Map.Entry<Structure2D.IntRowColumn,BigDecimal>> |
getQuadraticEntrySet() |
Set<Structure2D.IntRowColumn> |
getQuadraticKeySet() |
double |
getUnadjustedLowerLimit() |
double |
getUnadjustedUpperLimit() |
BigDecimal |
getUpperLimit()
The upper limit/bound - may return null.
|
int |
hashCode() |
boolean |
isAnyLinearFactorNonZero() |
boolean |
isAnyQuadraticFactorNonZero() |
boolean |
isConstraint()
The Constraint has a lower or an upper limit actually set (possibly both) - it actually is
constained.
|
boolean |
isContributionWeightSet() |
boolean |
isEqualityConstraint()
The Constraint has both a lower limit and an upper limit, and they are equal.
|
boolean |
isFunctionCompound() |
boolean |
isFunctionLinear() |
boolean |
isFunctionQuadratic() |
boolean |
isFunctionZero() |
boolean |
isLinearAndAllBinary() |
boolean |
isLinearAndAllInteger() |
boolean |
isLinearAndAnyBinary() |
boolean |
isLinearAndAnyInteger() |
boolean |
isLowerConstraint()
The Constraint has a lower limit, and the upper limit (if it exists) is different.
|
boolean |
isLowerLimitSet() |
boolean |
isObjective() |
boolean |
isUpperConstraint()
The Constraint has an upper limit, and the lower limit (if it exists) is different.
|
boolean |
isUpperLimitSet() |
ME |
level(Number level) |
ME |
lower(Number 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 is
BigDecimal . |
Expression |
set(int row,
int column,
Number value) |
Expression |
set(int index,
Number value) |
Expression |
set(Structure1D.IntIndex key,
Number value) |
Expression |
set(Structure1D.IntIndex row,
Structure1D.IntIndex column,
Number value) |
Expression |
set(Structure2D.IntRowColumn key,
Number value) |
Expression |
set(Variable variable,
Number value) |
Expression |
set(Variable variable1,
Variable variable2,
Number 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.
|
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) |
MultiaryFunction.TwiceDifferentiable<Double> |
toFunction() |
String |
toString() |
ME |
upper(Number 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 is
BigDecimal . |
protected boolean |
validate(BasicLogger.Printer appender)
Validate model parameters, like lower and upper limits.
|
protected boolean |
validate(BigDecimal value,
NumberContext context,
BasicLogger.Printer appender) |
ME |
weight(Number weight) |
protected Expression(Expression expressionToCopy, ExpressionsBasedModel destinationModel, boolean deep)
public Expression add(Structure1D.IntIndex key, Number value)
public Expression add(Structure2D.IntRowColumn key, Number value)
public int compareTo(Expression obj)
public Expression compensate(Set<Structure1D.IntIndex> fixedVariables)
fixedVariables
- A set of (by the presolver) fixed variable indicespublic BigDecimal evaluate(Access1D<BigDecimal> point)
public BigDecimal get(Structure1D.IntIndex key)
public BigDecimal get(Structure2D.IntRowColumn key)
public BigDecimal get(Variable variable)
public MatrixStore<Double> getAdjustedGradient(Access1D<?> point)
public MatrixStore<Double> getAdjustedHessian()
public double getAdjustedLinearFactor(int aVar)
public double getAdjustedLinearFactor(Structure1D.IntIndex key)
public double getAdjustedLinearFactor(Variable aVar)
public double getAdjustedQuadraticFactor(int aVar1, int aVar2)
public double getAdjustedQuadraticFactor(Structure2D.IntRowColumn key)
public Set<Map.Entry<Structure1D.IntIndex,BigDecimal>> getLinearEntrySet()
public Set<Structure1D.IntIndex> getLinearKeySet()
public Set<Map.Entry<Structure2D.IntRowColumn,BigDecimal>> getQuadraticEntrySet()
public Set<Structure2D.IntRowColumn> getQuadraticKeySet()
public boolean isAnyLinearFactorNonZero()
public boolean isAnyQuadraticFactorNonZero()
public boolean isFunctionCompound()
public boolean isFunctionLinear()
public boolean isFunctionQuadratic()
public boolean isFunctionZero()
public boolean isLinearAndAllBinary()
public boolean isLinearAndAllInteger()
public boolean isLinearAndAnyBinary()
public boolean isLinearAndAnyInteger()
public Expression set(int row, int column, Number value)
public Expression set(int index, Number value)
public Expression set(Structure1D.IntIndex row, Structure1D.IntIndex column, Number value)
public Expression set(Structure1D.IntIndex key, Number value)
public Expression set(Structure2D.IntRowColumn key, Number value)
public Expression set(Variable variable, Number value)
public Expression set(Variable variable1, Variable variable2, Number value)
public void setCompoundFactorsOffset(List<Variable> variables, Access1D<?> point)
variables
- The relevant variablespoint
- The point to measure frompublic void setLinearFactorsSimple(List<Variable> variables)
variables
- The relevant variablespublic MultiaryFunction.TwiceDifferentiable<Double> toFunction()
protected void appendMiddlePart(StringBuilder builder, Access1D<BigDecimal> currentSolution)
protected void destroy()
protected void doIntegerRounding()
public final boolean equals(Object obj)
equals
in class Object
Object.equals(java.lang.Object)
public final double getAdjustedLowerLimit()
public final double getAdjustedUpperLimit()
public final double getAdjustmentFactor()
public final BigDecimal getContributionWeight()
Optimisation.Objective
getContributionWeight
in interface Optimisation.Objective
public final BigDecimal getLowerLimit()
Optimisation.Constraint
getLowerLimit
in interface Optimisation.Constraint
public final String getName()
public final double getUnadjustedLowerLimit()
public final double getUnadjustedUpperLimit()
public final BigDecimal getUpperLimit()
Optimisation.Constraint
getUpperLimit
in interface Optimisation.Constraint
public final boolean isConstraint()
Optimisation.Constraint
isConstraint
in interface Optimisation.Constraint
public final boolean isContributionWeightSet()
public final boolean isEqualityConstraint()
Optimisation.Constraint
isEqualityConstraint
in interface Optimisation.Constraint
public final boolean isLowerConstraint()
Optimisation.Constraint
isLowerConstraint
in interface Optimisation.Constraint
public final boolean isLowerLimitSet()
public final boolean isObjective()
isObjective
in interface Optimisation.Objective
public final boolean isUpperConstraint()
Optimisation.Constraint
isUpperConstraint
in interface Optimisation.Constraint
public final boolean isUpperLimitSet()
public final ME level(Number level)
getLowerLimit()
,
getUpperLimit()
public ME lower(Number lower)
BigDecimal
. BigDecimal
values
are always used as they are.public ME upper(Number upper)
BigDecimal
. BigDecimal
values
are always used as they are.public final ME weight(Number weight)
getContributionWeight()
protected void appendLeftPart(StringBuilder builder)
protected void appendMiddlePart(StringBuilder builder)
protected void appendRightPart(StringBuilder builder)
protected final int getAdjustmentExponent()
protected final boolean validate(BasicLogger.Printer appender)
protected boolean validate(BigDecimal value, NumberContext context, BasicLogger.Printer appender)
Copyright © 2019 Optimatika. All rights reserved.