Class ModelEntity<ME extends ModelEntity<ME>>

java.lang.Object
org.ojalgo.optimisation.ModelEntity<ME>
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>
Model entities are identified and compared by their names only. Any/all other members/attributes are NOT part of equals(), hashCode() or compareTo().
  • Field Details

    • LARGEST

      private static final BigDecimal LARGEST
    • SMALLEST

      private static final BigDecimal SMALLEST
    • PRINT

      static final NumberContext PRINT
    • RANGE

      static final int RANGE
      See Also:
    • myAdjustmentExponent

      private transient int myAdjustmentExponent
    • myContributionWeight

      private BigDecimal myContributionWeight
    • myLowerLimit

      private BigDecimal myLowerLimit
    • myName

      private final String myName
    • myUpperLimit

      private BigDecimal myUpperLimit
  • Constructor Details

    • ModelEntity

      private ModelEntity()
    • ModelEntity

      protected ModelEntity(ME entityToCopy)
    • ModelEntity

      protected ModelEntity(String name)
  • Method Details

    • deriveAdjustmentExponent

      static int deriveAdjustmentExponent(AggregatorFunction<BigDecimal> largest, AggregatorFunction<BigDecimal> smallest, int range)
    • isInfeasible

      static boolean isInfeasible(BigDecimal lower, BigDecimal upper)
    • toBigDecimal

      static BigDecimal toBigDecimal(Comparable<?> number)
    • 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 final boolean equals(Object obj)
      Overrides:
      equals in class Object
      See Also:
    • getAdjustmentFactor

      public final double getAdjustmentFactor()
      Returns:
      Adjusted "1"
    • 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 final 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)
      See Also:
    • 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)
      Purely the reverse scaling part of toUnadjusted(double, NumberContext)
    • shift

      public void shift(BigDecimal shift)
      Add this shift to the lower/upper limits, if they exist.
    • toAdjusted

      public final double toAdjusted(BigDecimal unadjusted)
      Will convert a BigDecimal model parameter to a corresponing
      invalid reference
      double
      solver parameter, in the process scaling it. 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). This will also enforce the lower and upper limits as well as the NumberContext. To "only" do the reverse adjustment 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)
      See Also:
    • weight

      public final ME weight(double weight)
    • weight

      public final ME weight(long weight)
    • getLower

      private BigDecimal getLower(boolean adjusted)
    • getUpper

      private BigDecimal getUpper(boolean adjusted)
    • 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)
    • appendToString

      final void appendToString(StringBuilder builder, NumberContext display)
    • deriveAdjustmentExponent

      abstract int deriveAdjustmentExponent()
    • doIntegerRounding

      abstract void doIntegerRounding()
      If necessary this method should first determine if this ModelEntity 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 BigDecimal getCompensatedLowerLimit(BigDecimal compensation)
    • getCompensatedLowerLimit

      final BigDecimal getCompensatedLowerLimit(BigDecimal compensation, NumberContext precision)
    • getCompensatedUpperLimit

      final BigDecimal getCompensatedUpperLimit(BigDecimal compensation)
    • getCompensatedUpperLimit

      final BigDecimal getCompensatedUpperLimit(BigDecimal compensation, NumberContext precision)
    • isClosedRange

      boolean isClosedRange(BigDecimal lower, 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()