- java.lang.Object
-
- org.ojalgo.optimisation.ModelEntity<ME>
-
- Type Parameters:
ME- The concrete implementation type (for fluent interface returns)
- All Implemented Interfaces:
java.lang.Comparable<ME>,Optimisation,Optimisation.Constraint,Optimisation.Objective
- Direct Known Subclasses:
Expression,Variable
public abstract class ModelEntity<ME extends ModelEntity<ME>> extends java.lang.Object implements Optimisation.Constraint, Optimisation.Objective, java.lang.Comparable<ME>
ModelEntity is the abstract base class for optimization model components such as variables and expressions in ojAlgo's optimization framework.A ModelEntity can serve as both a constraint and an objective function component:
- As a constraint: Define feasible values using lower/upper bounds
- As an objective: Contribute to the objective function with a weight
The class provides methods to:
- Set and get lower/upper limits for constraints
- Set and get contribution weights for objective functions
- Handle integer restrictions
- Validate constraint satisfaction
- Apply scaling adjustments for numerical stability
Implementations include
Variablefor decision variables andExpressionfor linear and quadratic expressions.
-
-
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 static java.math.BigDecimalLARGESTprivate intmyAdjustmentExponentprivate java.math.BigDecimalmyContributionWeightprivate java.math.BigDecimalmyLowerLimitprivate java.lang.StringmyNameprivate java.math.BigDecimalmyUpperLimit(package private) static NumberContextPRINT(package private) static intRANGEprivate static java.math.BigDecimalSMALLEST
-
Constructor Summary
Constructors Modifier Constructor Description privateModelEntity()protectedModelEntity(java.lang.String name)protectedModelEntity(ME entityToCopy)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidaddTo(Expression target, java.math.BigDecimal scale)java.math.BigDecimaladjust(java.math.BigDecimal factor)protected voidappendLeftPart(java.lang.StringBuilder builder, NumberContext display)protected voidappendMiddlePart(java.lang.StringBuilder builder, NumberContext display)protected voidappendRightPart(java.lang.StringBuilder builder, NumberContext display)(package private) voidappendToString(java.lang.StringBuilder builder, NumberContext display)(package private) abstract intderiveAdjustmentExponent()(package private) static intderiveAdjustmentExponent(AggregatorFunction<java.math.BigDecimal> largest, AggregatorFunction<java.math.BigDecimal> smallest, int range)protected voiddestroy()(package private) abstract voiddoIntegerRounding()If necessary this method should first determine if thisModelEntityis "integer" or not.booleanequals(java.lang.Object obj)protected intgetAdjustmentExponent()(package private) intgetAdjustmentExponentValue()doublegetAdjustmentFactor()(package private) java.math.BigDecimalgetCompensatedLowerLimit(java.math.BigDecimal compensation)(package private) java.math.BigDecimalgetCompensatedLowerLimit(java.math.BigDecimal compensation, NumberContext precision)(package private) java.math.BigDecimalgetCompensatedUpperLimit(java.math.BigDecimal compensation)(package private) java.math.BigDecimalgetCompensatedUpperLimit(java.math.BigDecimal compensation, NumberContext precision)java.math.BigDecimalgetContributionWeight()The weight/factor by which this model entity's value contributes to the objective function - may return null.private java.math.BigDecimalgetLower(boolean adjusted)java.math.BigDecimalgetLowerLimit()The lower limit/bound - may return null.doublegetLowerLimit(boolean adjusted, double defaultValue)java.math.BigDecimalgetLowerLimit(boolean adjusted, java.math.BigDecimal defaultValue)java.lang.StringgetName()private java.math.BigDecimalgetUpper(boolean adjusted)java.math.BigDecimalgetUpperLimit()The upper limit/bound - may return null.doublegetUpperLimit(boolean adjusted, double defaultValue)java.math.BigDecimalgetUpperLimit(boolean adjusted, java.math.BigDecimal defaultValue)inthashCode()(package private) booleanisClosedRange(java.math.BigDecimal lower, java.math.BigDecimal upper)booleanisConstraint()The Constraint has a lower or an upper limit actually set (possibly both) - it actually is constrained.booleanisContributionWeightSet()booleanisEqualityConstraint()The Constraint has both a lower limit and an upper limit, and they are equal.(package private) booleanisInfeasible()(package private) static booleanisInfeasible(java.math.BigDecimal lower, java.math.BigDecimal upper)abstract booleanisInteger()Is this entity (all involved variables) integer?booleanisLowerConstraint()The Constraint has a lower limit, and the upper limit (if it exists) is different.booleanisLowerLimitSet()booleanisObjective()booleanisUpperConstraint()The Constraint has an upper limit, and the lower limit (if it exists) is different.booleanisUpperLimitSet()MElevel(double level)MElevel(long level)MElevel(java.lang.Comparable<?> level)MElower(double lower)MElower(long lower)MElower(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.BigDecimalreverseAdjustment(java.math.BigDecimal adjusted)Purely the reverse scaling part oftoUnadjusted(double, NumberContext)voidshift(java.math.BigDecimal shift)Add this shift to the lower/upper limits, if they exist.doubletoAdjusted(java.math.BigDecimal unadjusted)Will convert aBigDecimalmodel parameter to a corresponingdoublesolver parameter, in the process scaling it.(package private) static java.math.BigDecimaltoBigDecimal(java.lang.Comparable<?> number)java.lang.StringtoString()java.math.BigDecimaltoUnadjusted(double adjusted, NumberContext context)The inverse oftoAdjusted(BigDecimal).MEupper(double upper)MEupper(long upper)MEupper(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)protected booleanvalidate(BasicLogger appender)Validate model parameters, like lower and upper limits.MEweight(double weight)MEweight(long weight)MEweight(java.lang.Comparable<?> weight)
-
-
-
Field Detail
-
LARGEST
private static final java.math.BigDecimal LARGEST
-
SMALLEST
private static final java.math.BigDecimal SMALLEST
-
PRINT
static final NumberContext PRINT
-
RANGE
static final int RANGE
- See Also:
- Constant Field Values
-
myAdjustmentExponent
private transient int myAdjustmentExponent
-
myContributionWeight
private java.math.BigDecimal myContributionWeight
-
myLowerLimit
private java.math.BigDecimal myLowerLimit
-
myName
private final java.lang.String myName
-
myUpperLimit
private java.math.BigDecimal myUpperLimit
-
-
Constructor Detail
-
ModelEntity
private ModelEntity()
-
ModelEntity
protected ModelEntity(ME entityToCopy)
-
ModelEntity
protected ModelEntity(java.lang.String name)
-
-
Method Detail
-
deriveAdjustmentExponent
static int deriveAdjustmentExponent(AggregatorFunction<java.math.BigDecimal> largest, AggregatorFunction<java.math.BigDecimal> smallest, int range)
-
isInfeasible
static boolean isInfeasible(java.math.BigDecimal lower, java.math.BigDecimal upper)
-
toBigDecimal
static java.math.BigDecimal toBigDecimal(java.lang.Comparable<?> number)
-
addTo
public abstract void addTo(Expression target, java.math.BigDecimal scale)
- Parameters:
target- The targetExpressionscale- The scaling factor
-
adjust
public final java.math.BigDecimal adjust(java.math.BigDecimal factor)
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
getAdjustmentFactor
public final double getAdjustmentFactor()
- Returns:
- Adjusted "1"
-
getContributionWeight
public final java.math.BigDecimal getContributionWeight()
Description copied from interface:Optimisation.ObjectiveThe weight/factor by which this model entity's value contributes to the objective function - may return null.- Specified by:
getContributionWeightin interfaceOptimisation.Objective
-
getLowerLimit
public final java.math.BigDecimal getLowerLimit()
Description copied from interface:Optimisation.ConstraintThe lower limit/bound - may return null.- Specified by:
getLowerLimitin interfaceOptimisation.Constraint
-
getLowerLimit
public final java.math.BigDecimal getLowerLimit(boolean adjusted, java.math.BigDecimal defaultValue)
-
getLowerLimit
public final double getLowerLimit(boolean adjusted, double defaultValue)
-
getName
public final java.lang.String getName()
-
getUpperLimit
public final java.math.BigDecimal getUpperLimit()
Description copied from interface:Optimisation.ConstraintThe upper limit/bound - may return null.- Specified by:
getUpperLimitin interfaceOptimisation.Constraint
-
getUpperLimit
public final java.math.BigDecimal getUpperLimit(boolean adjusted, java.math.BigDecimal defaultValue)
-
getUpperLimit
public final double getUpperLimit(boolean adjusted, double defaultValue)
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
isConstraint
public final boolean isConstraint()
Description copied from interface:Optimisation.ConstraintThe Constraint has a lower or an upper limit actually set (possibly both) - it actually is constrained.- Specified by:
isConstraintin interfaceOptimisation.Constraint
-
isContributionWeightSet
public final boolean isContributionWeightSet()
-
isEqualityConstraint
public final boolean isEqualityConstraint()
Description copied from interface:Optimisation.ConstraintThe Constraint has both a lower limit and an upper limit, and they are equal.- Specified by:
isEqualityConstraintin interfaceOptimisation.Constraint
-
isInteger
public abstract boolean isInteger()
Is this entity (all involved variables) integer?
-
isLowerConstraint
public final boolean isLowerConstraint()
Description copied from interface:Optimisation.ConstraintThe Constraint has a lower limit, and the upper limit (if it exists) is different.- Specified by:
isLowerConstraintin interfaceOptimisation.Constraint
-
isLowerLimitSet
public final boolean isLowerLimitSet()
-
isObjective
public final boolean isObjective()
- Specified by:
isObjectivein interfaceOptimisation.Objective- Returns:
- true if this Objective has a non zero contribution weight - it actually is contributing to the objective function.
-
isUpperConstraint
public final boolean isUpperConstraint()
Description copied from interface:Optimisation.ConstraintThe Constraint has an upper limit, and the lower limit (if it exists) is different.- Specified by:
isUpperConstraintin interfaceOptimisation.Constraint
-
isUpperLimitSet
public final boolean isUpperLimitSet()
-
level
public final ME level(java.lang.Comparable<?> level)
- See Also:
getLowerLimit(),getUpperLimit()
-
level
public final ME level(double level)
-
level
public final ME level(long level)
-
lower
public ME lower(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.BigDecimalvalues are always used as they are.
-
lower
public final ME lower(double lower)
-
lower
public final ME lower(long lower)
-
reverseAdjustment
public final java.math.BigDecimal reverseAdjustment(java.math.BigDecimal adjusted)
Purely the reverse scaling part oftoUnadjusted(double, NumberContext)
-
shift
public void shift(java.math.BigDecimal shift)
Add this shift to the lower/upper limits, if they exist.
-
toAdjusted
public final double toAdjusted(java.math.BigDecimal unadjusted)
Will convert aBigDecimalmodel parameter to a corresponingdoublesolver parameter, in the process scaling it. This operation is reversed bytoUnadjusted(double, NumberContext)and/orreverseAdjustment(BigDecimal).
-
toString
public final java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toUnadjusted
public final java.math.BigDecimal toUnadjusted(double adjusted, NumberContext context)The inverse oftoAdjusted(BigDecimal). This will also enforce the lower and upper limits as well as theNumberContext. To "only" do the reverse adjustment callreverseAdjustment(BigDecimal).
-
upper
public ME upper(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.BigDecimalvalues are always used as they are.
-
upper
public final ME upper(double upper)
-
upper
public final ME upper(long upper)
-
weight
public final ME weight(java.lang.Comparable<?> weight)
- See Also:
getContributionWeight()
-
weight
public final ME weight(double weight)
-
weight
public final ME weight(long weight)
-
getLower
private java.math.BigDecimal getLower(boolean adjusted)
-
getUpper
private java.math.BigDecimal getUpper(boolean adjusted)
-
appendLeftPart
protected void appendLeftPart(java.lang.StringBuilder builder, NumberContext display)
-
appendMiddlePart
protected void appendMiddlePart(java.lang.StringBuilder builder, NumberContext display)
-
appendRightPart
protected void appendRightPart(java.lang.StringBuilder builder, NumberContext display)
-
destroy
protected void destroy()
-
getAdjustmentExponent
protected final int getAdjustmentExponent()
-
validate
protected final boolean validate(BasicLogger appender)
Validate model parameters, like lower and upper limits. Does not validate the solution/value.
-
validate
protected boolean validate(java.math.BigDecimal value, NumberContext context, BasicLogger appender)
-
appendToString
final void appendToString(java.lang.StringBuilder builder, NumberContext display)
-
deriveAdjustmentExponent
abstract int deriveAdjustmentExponent()
-
doIntegerRounding
abstract void doIntegerRounding()
If 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".
-
getAdjustmentExponentValue
final int getAdjustmentExponentValue()
-
getCompensatedLowerLimit
final java.math.BigDecimal getCompensatedLowerLimit(java.math.BigDecimal compensation)
-
getCompensatedLowerLimit
final java.math.BigDecimal getCompensatedLowerLimit(java.math.BigDecimal compensation, NumberContext precision)
-
getCompensatedUpperLimit
final java.math.BigDecimal getCompensatedUpperLimit(java.math.BigDecimal compensation)
-
getCompensatedUpperLimit
final java.math.BigDecimal getCompensatedUpperLimit(java.math.BigDecimal compensation, NumberContext precision)
-
isClosedRange
boolean isClosedRange(java.math.BigDecimal lower, java.math.BigDecimal upper)- Returns:
- true if both the lower and upper limits are defined, and the range is defined by lower and upper.
-
isInfeasible
boolean isInfeasible()
-
-