Module ojalgo

Class Variable

  • All Implemented Interfaces:
    java.lang.Comparable<Variable>, Optimisation, Optimisation.Constraint, Optimisation.Objective

    public final class Variable
    extends ModelEntity<Variable>
    Variable represents a decision variable in an optimization model.

    Each variable has a unique index in the model and can have:

    • Lower and upper bounds (constraints)
    • A contribution weight in the objective function
    • An integer or continuous domain
    • A current value

    Variables can be configured as:

    • Binary (0-1 integer variables)
    • Integer (whole number values only)
    • Continuous (any value within bounds)
    • Fixed (equal lower and upper bounds)
    • Unbounded (no effective limits)

    As a subclass of ModelEntity, a Variable can function both as a constraint (through lower/upper bounds) and as an objective function component (through its contribution weight).

    Variables are typically created and managed through ExpressionsBasedModel, which assigns their indices and incorporates them into the optimization problem.

    • Field Detail

      • myInteger

        private boolean myInteger
      • myUnbounded

        private transient boolean myUnbounded
      • myValue

        private java.math.BigDecimal myValue
    • Constructor Detail

      • Variable

        Variable​(java.lang.String name,
                 int index)
      • Variable

        Variable​(Variable variableToCopy)
    • Method Detail

      • compareTo

        public int compareTo​(Variable obj)
      • getLowerSlack

        public java.math.BigDecimal getLowerSlack()
      • getUpperSlack

        public java.math.BigDecimal getUpperSlack()
      • getValue

        public java.math.BigDecimal getValue()
      • isBinary

        public boolean isBinary()
        Variable can only be 0 or 1.
      • isInteger

        public boolean isInteger()
        Description copied from class: ModelEntity
        Is this entity (all involved variables) integer?
        Specified by:
        isInteger in class ModelEntity<Variable>
        Returns:
        true if this is an integer variable, otherwise false
      • isNegative

        public boolean isNegative()
        The range includes something < 0.0
      • isPositive

        public boolean isPositive()
        The range includes something > 0.0
      • isValueSet

        public boolean isValueSet()
      • lower

        public Variable lower​(java.lang.Comparable<?> lower)
        Description copied from class: ModelEntity
        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.
        Overrides:
        lower in class ModelEntity<Variable>
      • quantifyContribution

        public java.math.BigDecimal quantifyContribution()
      • setInteger

        public void setInteger​(boolean integer)
      • setValue

        public void setValue​(java.lang.Comparable<?> value)
      • upper

        public Variable upper​(java.lang.Comparable<?> upper)
        Description copied from class: ModelEntity
        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.
        Overrides:
        upper in class ModelEntity<Variable>
      • value

        public Variable value​(java.math.BigDecimal value)
      • assertFixedValue

        private void assertFixedValue()
      • copy

        Variable copy()
        Internal copy that includes the index
      • doIntegerRounding

        void doIntegerRounding()
        Description copied from class: ModelEntity
        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".

        Specified by:
        doIntegerRounding in class ModelEntity<Variable>
      • isFixed

        boolean isFixed()
      • isUnbounded

        boolean isUnbounded()
      • setFixed

        void setFixed​(java.math.BigDecimal value)
      • setUnbounded

        void setUnbounded​(boolean uncorrelated)
      • validate

        boolean validate​(java.math.BigDecimal value,
                         NumberContext context,
                         BasicLogger appender,
                         boolean relaxed)