Class ModelEntity<ME extends ModelEntity<ME>>
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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface Optimisation
Optimisation.Constraint, Optimisation.ConstraintType, Optimisation.Integration<M,S>, Optimisation.Model, Optimisation.Objective, Optimisation.Options, Optimisation.ProblemStructure, Optimisation.Result, Optimisation.Sense, Optimisation.Solver, Optimisation.State -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final BigDecimalprivate intprivate BigDecimalprivate BigDecimalprivate final Stringprivate BigDecimal(package private) static final NumberContext(package private) static final intprivate static final BigDecimal -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateprotectedModelEntity(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) (package private) final voidappendToString(StringBuilder builder, NumberContext display) (package private) abstract int(package private) static intderiveAdjustmentExponent(AggregatorFunction<BigDecimal> largest, AggregatorFunction<BigDecimal> smallest, int range) protected voiddestroy()(package private) abstract voidIf necessary this method should first determine if thisModelEntityis "integer" or not.booleanprotected final int(package private) final intfinal double(package private) final BigDecimalgetCompensatedLowerLimit(BigDecimal compensation) (package private) final BigDecimalgetCompensatedLowerLimit(BigDecimal compensation, NumberContext precision) (package private) final BigDecimalgetCompensatedUpperLimit(BigDecimal compensation) (package private) final BigDecimalgetCompensatedUpperLimit(BigDecimal compensation, NumberContext precision) final BigDecimalThe weight/factor by which this model entity's value contributes to the objective function - may return null.private BigDecimalgetLower(boolean adjusted) final BigDecimalThe lower limit/bound - may return null.final doublegetLowerLimit(boolean adjusted, double defaultValue) final BigDecimalgetLowerLimit(boolean adjusted, BigDecimal defaultValue) final StringgetName()private BigDecimalgetUpper(boolean adjusted) final BigDecimalThe upper limit/bound - may return null.final doublegetUpperLimit(boolean adjusted, double defaultValue) final BigDecimalgetUpperLimit(boolean adjusted, BigDecimal defaultValue) inthashCode()(package private) booleanisClosedRange(BigDecimal lower, BigDecimal upper) 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.(package private) boolean(package private) static booleanisInfeasible(BigDecimal lower, BigDecimal upper) 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
double(package private) static BigDecimaltoBigDecimal(Comparable<?> number) final 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 interface Comparable
compareTo
-
Field Details
-
LARGEST
-
SMALLEST
-
PRINT
-
RANGE
static final int RANGE- See Also:
-
myAdjustmentExponent
private transient int myAdjustmentExponent -
myContributionWeight
-
myLowerLimit
-
myName
-
myUpperLimit
-
-
Constructor Details
-
ModelEntity
private ModelEntity() -
ModelEntity
-
ModelEntity
-
-
Method Details
-
deriveAdjustmentExponent
static int deriveAdjustmentExponent(AggregatorFunction<BigDecimal> largest, AggregatorFunction<BigDecimal> smallest, int range) -
isInfeasible
-
toBigDecimal
-
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
-
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
-
getLower
-
getUpper
-
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
-
appendToString
-
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
-
getCompensatedLowerLimit
-
getCompensatedUpperLimit
-
getCompensatedUpperLimit
-
isClosedRange
- Returns:
- true if both the lower and upper limits are defined, and the range is defined by lower and upper.
-
isInfeasible
boolean isInfeasible()
-