Package org.ojalgo.optimisation
Class ModelEntity<ME extends ModelEntity<ME>>
- java.lang.Object
-
- org.ojalgo.optimisation.ModelEntity<ME>
-
- 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>
Model entities are identified and compared by their names only. Any/all other members/attributes are NOT part of equals(), hashCode() or compareTo().
-
-
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.BigDecimal
LARGEST
private int
myAdjustmentExponent
private java.math.BigDecimal
myContributionWeight
private java.math.BigDecimal
myLowerLimit
private java.lang.String
myName
private java.math.BigDecimal
myUpperLimit
(package private) static NumberContext
PRINT
(package private) static int
RANGE
private static java.math.BigDecimal
SMALLEST
-
Constructor Summary
Constructors Modifier Constructor Description private
ModelEntity()
protected
ModelEntity(java.lang.String name)
protected
ModelEntity(ME entityToCopy)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
addTo(Expression target, java.math.BigDecimal scale)
java.math.BigDecimal
adjust(java.math.BigDecimal factor)
protected void
appendLeftPart(java.lang.StringBuilder builder, NumberContext display)
protected void
appendMiddlePart(java.lang.StringBuilder builder, NumberContext display)
protected void
appendRightPart(java.lang.StringBuilder builder, NumberContext display)
(package private) void
appendToString(java.lang.StringBuilder builder, NumberContext display)
(package private) abstract int
deriveAdjustmentExponent()
(package private) static int
deriveAdjustmentExponent(AggregatorFunction<java.math.BigDecimal> largest, AggregatorFunction<java.math.BigDecimal> smallest, int range)
protected void
destroy()
(package private) abstract void
doIntegerRounding()
If necessary this method should first determine if thisModelEntity
is "integer" or not.boolean
equals(java.lang.Object obj)
protected int
getAdjustmentExponent()
(package private) int
getAdjustmentExponentValue()
double
getAdjustmentFactor()
(package private) java.math.BigDecimal
getCompensatedLowerLimit(java.math.BigDecimal compensation)
(package private) java.math.BigDecimal
getCompensatedLowerLimit(java.math.BigDecimal compensation, NumberContext precision)
(package private) java.math.BigDecimal
getCompensatedUpperLimit(java.math.BigDecimal compensation)
(package private) java.math.BigDecimal
getCompensatedUpperLimit(java.math.BigDecimal compensation, NumberContext precision)
java.math.BigDecimal
getContributionWeight()
The weight/factor by which this model entity's value contributes to the objective function - may return null.private java.math.BigDecimal
getLower(boolean adjusted)
java.math.BigDecimal
getLowerLimit()
The lower limit/bound - may return null.double
getLowerLimit(boolean adjusted, double defaultValue)
java.math.BigDecimal
getLowerLimit(boolean adjusted, java.math.BigDecimal defaultValue)
java.lang.String
getName()
private java.math.BigDecimal
getUpper(boolean adjusted)
java.math.BigDecimal
getUpperLimit()
The upper limit/bound - may return null.double
getUpperLimit(boolean adjusted, double defaultValue)
java.math.BigDecimal
getUpperLimit(boolean adjusted, java.math.BigDecimal defaultValue)
int
hashCode()
(package private) boolean
isClosedRange(java.math.BigDecimal lower, java.math.BigDecimal upper)
boolean
isConstraint()
The Constraint has a lower or an upper limit actually set (possibly both) - it actually is constrained.boolean
isContributionWeightSet()
boolean
isEqualityConstraint()
The Constraint has both a lower limit and an upper limit, and they are equal.(package private) boolean
isInfeasible()
(package private) static boolean
isInfeasible(java.math.BigDecimal lower, java.math.BigDecimal upper)
abstract boolean
isInteger()
Is this entity (all involved variables) integer?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(double level)
ME
level(long level)
ME
level(java.lang.Comparable<?> level)
ME
lower(double lower)
ME
lower(long lower)
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
.java.math.BigDecimal
reverseAdjustment(java.math.BigDecimal adjusted)
Purely the reverse scaling part oftoUnadjusted(double, NumberContext)
void
shift(java.math.BigDecimal shift)
Add this shift to the lower/upper limits, if they exist.double
toAdjusted(java.math.BigDecimal unadjusted)
Will convert aBigDecimal
model parameter to a corresponingdouble
solver parameter, in the process scaling it.(package private) static java.math.BigDecimal
toBigDecimal(java.lang.Comparable<?> number)
java.lang.String
toString()
java.math.BigDecimal
toUnadjusted(double adjusted, NumberContext context)
The inverse oftoAdjusted(BigDecimal)
.ME
upper(double upper)
ME
upper(long upper)
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
.protected boolean
validate(java.math.BigDecimal value, NumberContext context, BasicLogger appender)
protected boolean
validate(BasicLogger appender)
Validate model parameters, like lower and upper limits.ME
weight(double weight)
ME
weight(long weight)
ME
weight(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 targetExpression
scale
- The scaling factor
-
adjust
public final java.math.BigDecimal adjust(java.math.BigDecimal factor)
-
equals
public final boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
- See Also:
Object.equals(java.lang.Object)
-
getAdjustmentFactor
public final double getAdjustmentFactor()
- Returns:
- Adjusted "1"
-
getContributionWeight
public final java.math.BigDecimal getContributionWeight()
Description copied from interface:Optimisation.Objective
The weight/factor by which this model entity's value contributes to the objective function - may return null.- Specified by:
getContributionWeight
in interfaceOptimisation.Objective
-
getLowerLimit
public final java.math.BigDecimal getLowerLimit()
Description copied from interface:Optimisation.Constraint
The lower limit/bound - may return null.- Specified by:
getLowerLimit
in 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.Constraint
The upper limit/bound - may return null.- Specified by:
getUpperLimit
in 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 final int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
isConstraint
public final boolean isConstraint()
Description copied from interface:Optimisation.Constraint
The Constraint has a lower or an upper limit actually set (possibly both) - it actually is constrained.- Specified by:
isConstraint
in interfaceOptimisation.Constraint
-
isContributionWeightSet
public final boolean isContributionWeightSet()
-
isEqualityConstraint
public final boolean isEqualityConstraint()
Description copied from interface:Optimisation.Constraint
The Constraint has both a lower limit and an upper limit, and they are equal.- Specified by:
isEqualityConstraint
in interfaceOptimisation.Constraint
-
isInteger
public abstract boolean isInteger()
Is this entity (all involved variables) integer?
-
isLowerConstraint
public final boolean isLowerConstraint()
Description copied from interface:Optimisation.Constraint
The Constraint has a lower limit, and the upper limit (if it exists) is different.- Specified by:
isLowerConstraint
in interfaceOptimisation.Constraint
-
isLowerLimitSet
public final boolean isLowerLimitSet()
-
isObjective
public final boolean isObjective()
- Specified by:
isObjective
in 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.Constraint
The Constraint has an upper limit, and the lower limit (if it exists) is different.- Specified by:
isUpperConstraint
in 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
.BigDecimal
values 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 aBigDecimal
model parameter to a corresponingdouble
solver parameter, in the process scaling it. This operation is reversed bytoUnadjusted(double, NumberContext)
and/orreverseAdjustment(BigDecimal)
.
-
toString
public final java.lang.String toString()
- Overrides:
toString
in 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
.BigDecimal
values 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 thisModelEntity
is "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()
-
-