java.lang.Object
org.ojalgo.optimisation.ModelEntity<ME>
- Type Parameters:
ME- The concrete implementation type (for fluent interface returns)
- All Implemented Interfaces:
Comparable<ME>,Optimisation,Optimisation.Constraint,Optimisation.Objective
- Direct Known Subclasses:
Expression,Variable
public abstract class ModelEntity<ME extends ModelEntity<ME>>
extends Object
implements Optimisation.Constraint, Optimisation.Objective, 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 Variable for decision variables and Expression for linear and
quadratic expressions.
- Author:
- apete
-
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 -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedModelEntity(String name) protectedModelEntity(ME entityToCopy) -
Method Summary
Modifier and TypeMethodDescriptionabstract voidaddTo(Expression target, BigDecimal scale) final BigDecimaladjust(BigDecimal factor) protected voidappendLeftPart(StringBuilder builder, NumberContext display) protected voidappendMiddlePart(StringBuilder builder, NumberContext display) protected voidappendRightPart(StringBuilder builder, NumberContext display) protected voiddestroy()booleanprotected final intfinal doublefinal BigDecimalThe weight/factor by which this model entity's value contributes to the objective function - may return null.final BigDecimalThe lower limit/bound - may return null.final doublegetLowerLimit(boolean adjusted, double defaultValue) final BigDecimalgetLowerLimit(boolean adjusted, BigDecimal defaultValue) final StringgetName()final BigDecimalThe upper limit/bound - may return null.final doublegetUpperLimit(boolean adjusted, double defaultValue) final BigDecimalgetUpperLimit(boolean adjusted, BigDecimal defaultValue) inthashCode()final booleanThe Constraint has a lower or an upper limit actually set (possibly both) - it actually is constrained.final booleanfinal booleanThe Constraint has both a lower limit and an upper limit, and they are equal.abstract booleanIs this entity (all involved variables) integer?final booleanThe Constraint has a lower limit, and the upper limit (if it exists) is different.final booleanfinal booleanfinal booleanThe Constraint has an upper limit, and the lower limit (if it exists) is different.final booleanfinal MElevel(double level) final MElevel(long level) final MElevel(Comparable<?> level) final MElower(double lower) final MElower(long lower) lower(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.final BigDecimalreverseAdjustment(BigDecimal adjusted) Purely the reverse scaling part oftoUnadjusted(double, NumberContext)voidshift(BigDecimal shift) Add this shift to the lower/upper limits, if they exist.final doubletoAdjusted(BigDecimal unadjusted) Will convert aBigDecimalmodel parameter to a corresponingsolver parameter, in the process scaling it.invalid reference
doublefinal StringtoString()final BigDecimaltoUnadjusted(double adjusted, NumberContext context) The inverse oftoAdjusted(BigDecimal).final MEupper(double upper) final MEupper(long upper) upper(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(BigDecimal value, NumberContext context, BasicLogger appender) protected final booleanvalidate(BasicLogger appender) Validate model parameters, like lower and upper limits.final MEweight(double weight) final MEweight(long weight) final MEweight(Comparable<?> weight) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Comparable
compareTo
-
Constructor Details
-
ModelEntity
-
ModelEntity
-
-
Method Details
-
addTo
- Parameters:
target- The targetExpressionscale- The scaling factor
-
adjust
-
equals
-
getAdjustmentFactor
public final double getAdjustmentFactor()- Returns:
- Adjusted "1"
-
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
Description copied from interface:Optimisation.ConstraintThe lower limit/bound - may return null.- Specified by:
getLowerLimitin interfaceOptimisation.Constraint
-
getLowerLimit
-
getLowerLimit
public final double getLowerLimit(boolean adjusted, double defaultValue) -
getName
-
getUpperLimit
Description copied from interface:Optimisation.ConstraintThe upper limit/bound - may return null.- Specified by:
getUpperLimitin interfaceOptimisation.Constraint
-
getUpperLimit
-
getUpperLimit
public final double getUpperLimit(boolean adjusted, double defaultValue) -
hashCode
public int hashCode() -
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
- See Also:
-
level
-
level
-
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
-
lower
-
reverseAdjustment
Purely the reverse scaling part oftoUnadjusted(double, NumberContext) -
shift
Add this shift to the lower/upper limits, if they exist. -
toAdjusted
Will convert aBigDecimalmodel parameter to a corresponingsolver parameter, in the process scaling it. This operation is reversed byinvalid reference
doubletoUnadjusted(double, NumberContext)and/orreverseAdjustment(BigDecimal). -
toString
-
toUnadjusted
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
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
-
upper
-
weight
- See Also:
-
weight
-
weight
-
appendLeftPart
-
appendMiddlePart
-
appendRightPart
-
destroy
protected void destroy() -
getAdjustmentExponent
protected final int getAdjustmentExponent() -
validate
Validate model parameters, like lower and upper limits. Does not validate the solution/value. -
validate
-