Class ModelEntity<ME extends ModelEntity<ME>>

java.lang.Object
org.ojalgo.optimisation.ModelEntity<ME>
Type Parameters:
ME - The concrete subclass type, enabling a fluent API
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>
Abstract base for Variable and Expression. A ModelEntity can act as a constraint (via lower/upper limits) and/or contribute to the objective function (via a contribution weight).
Author:
apete
  • Constructor Details

    • ModelEntity

      protected ModelEntity(ME entityToCopy)
    • ModelEntity

      protected ModelEntity(String name)
  • Method Details

    • addTo

      public abstract void addTo(Expression target, BigDecimal scale)
      Add this (Variable or Expression) to another Expression, scaled by a factor.
      Parameters:
      target - The target Expression
      scale - The scaling factor
    • adjust

      public final BigDecimal adjust(BigDecimal factor)
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • getAdjustmentFactor

      public final double getAdjustmentFactor()
      Returns:
      The scaling factor (10^exponent) used to adjust model parameters for numerical stability
    • getConstraintType

      public final Optimisation.ConstraintType getConstraintType()
      Specified by:
      getConstraintType in interface Optimisation.Constraint
    • getContributionWeight

      public final 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 interface Optimisation.Objective
    • getLowerLimit

      public final BigDecimal getLowerLimit()
      Description copied from interface: Optimisation.Constraint
      The lower limit/bound - may return null.
      Specified by:
      getLowerLimit in interface Optimisation.Constraint
    • getLowerLimit

      public final BigDecimal getLowerLimit(boolean adjusted, BigDecimal defaultValue)
    • getLowerLimit

      public final double getLowerLimit(boolean adjusted, double defaultValue)
    • getName

      public final String getName()
    • getUpperLimit

      public final BigDecimal getUpperLimit()
      Description copied from interface: Optimisation.Constraint
      The upper limit/bound - may return null.
      Specified by:
      getUpperLimit in interface Optimisation.Constraint
    • getUpperLimit

      public final BigDecimal getUpperLimit(boolean adjusted, BigDecimal defaultValue)
    • getUpperLimit

      public final double getUpperLimit(boolean adjusted, double defaultValue)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class 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 interface Optimisation.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 interface Optimisation.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 interface Optimisation.Constraint
    • isLowerLimitSet

      public final boolean isLowerLimitSet()
    • isObjective

      public final boolean isObjective()
      Specified by:
      isObjective in interface Optimisation.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 interface Optimisation.Constraint
    • isUpperLimitSet

      public final boolean isUpperLimitSet()
    • level

      public final ME level(Comparable<?> level)
      Set both the lower and upper limits to the same value, creating an equality constraint.
    • level

      public final ME level(double level)
    • level

      public final ME level(long level)
    • lower

      public ME 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 is BigDecimal. 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 BigDecimal reverseAdjustment(BigDecimal adjusted)
      Reverses the scaling applied by toAdjusted(BigDecimal), without enforcing limits or context.
    • shift

      public void shift(BigDecimal shift)
      Adds the given shift to the lower and/or upper limits, if they are set.
    • toAdjusted

      public final double toAdjusted(BigDecimal unadjusted)
      Converts a BigDecimal model parameter to a corresponding double solver parameter, scaling it in the process. This operation is reversed by toUnadjusted(double, NumberContext) and/or reverseAdjustment(BigDecimal).
    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • toUnadjusted

      public final BigDecimal toUnadjusted(double adjusted, NumberContext context)
      The inverse of toAdjusted(BigDecimal). Also enforces the lower/upper limits and the NumberContext. To reverse only the scaling, call reverseAdjustment(BigDecimal).
    • upper

      public ME 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 is BigDecimal. 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(Comparable<?> weight)
      Set the contribution weight for the objective function. A zero weight is treated as "no weight" (null).
    • weight

      public final ME weight(double weight)
    • weight

      public final ME weight(long weight)
    • appendLeftPart

      protected void appendLeftPart(StringBuilder builder, NumberContext display)
    • appendMiddlePart

      protected void appendMiddlePart(StringBuilder builder, NumberContext display)
    • appendRightPart

      protected void appendRightPart(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(BigDecimal value, NumberContext context, BasicLogger appender)