Class HxSolution


  • public class HxSolution
    extends java.lang.Object
    Solution to the optimization model. A solution carries the values of all expressions in the model. It is used to retrieve the values of all expressions (getting the solution), or to set the values of some decisions (setting the solution).
    See Also:
    HxSolutionStatus
    • Method Detail

      • getOptimizer

        public HexalyOptimizer getOptimizer()
        Returns the Hexaly Optimizer object associated to this solution.
        Returns:
        Hexaly Optimizer object.
      • setIntValue

        public void setIntValue​(HxExpression expr,
                                long value)
        Sets the value of the given expression in this solution. Only decisions can be set. Only allowed in state HxState.Stopped. Only allowed if this expression is an integer or a boolean. If the optimizer was not launched, this value will be used as an initial value for the decision.
        Parameters:
        expr - Decision.
        value - Value assigned to the decision in this solution.
        Since:
        3.0
        See Also:
        HxExpression.isDecision(), HxExpression.isInt()
      • setDoubleValue

        public void setDoubleValue​(HxExpression expr,
                                   double value)
        Sets the value of the given expression in this solution. Only decisions can be set. Only allowed in state HxState.Stopped. If the optimizer was not launched, this value will be used as an initial value for the decision. Only allowed if this expression is a double.
        Parameters:
        expr - Decision.
        value - Value assigned to the decision in this solution.
        Since:
        3.0
        See Also:
        HxExpression.isDecision(), HxExpression.isDouble()
      • setIntervalValue

        public void setIntervalValue​(HxExpression expr,
                                     HxInterval value)
        Sets the value of the given expression in this solution. Only decisions can be set. Only allowed in state HxState.Stopped. If the optimizer was not launched, this value will be used as an initial value for the decision. Only allowed if this expression is an interval.
        Parameters:
        expr - Decision.
        value - Value assigned to the decision in this solution.
        Since:
        3.0
        See Also:
        HxExpression.isDecision(), HxExpression.isInterval()
      • getDoubleValue

        public double getDoubleValue​(HxExpression expr)
        Returns the value of the given expression in this solution. Only allowed in states HxState.Paused or HxState.Stopped. Only allowed if this expression is a double.
        Parameters:
        expr - Expression.
        Returns:
        Value of the expression in this solution.
        Since:
        3.0
        See Also:
        HxExpression.isDouble()
      • isViolated

        public boolean isViolated​(HxExpression expr)
        Returns true if the given expression is violated in this solution. An expression can be violated in 3 cases:
        1. It is a constraint and its value is 0.
        2. It is a double and its value is NaN (Not A Number).
        3. It is an integer or boolean with no valid value (arithmetic or out of bounds exception).
        Only allowed in states HxState.Paused or HxState.Stopped.
        Parameters:
        expr - Expression.
        Returns:
        True if this expression is violated in this solution.
        Since:
        5.5
      • isUndefined

        public boolean isUndefined​(HxExpression expr)
        Returns true if the given expression has an undefined value in this solution. An expression can be undefined in 4 cases:
        1. It is a double and its value is NaN (Not a Number).
        2. It is an integer or boolean with no valid value (arithmetic or out of bounds exception).
        3. It is an interval with at least one undefined bound.
        4. It is the result of any ill-defined operation (at with out of bounds index or operations on undefined values for instance).
        Only allowed in states HxState.Paused or HxState.Stopped.
        Parameters:
        expr - Expression.
        Returns:
        True if this expression has an undefined value in this solution.
        Since:
        7.0
      • getObjectiveBound

        public long getObjectiveBound​(int objectiveIndex)
        Returns the bound computed by the optimizer for the given objective. If the optimizer has never been launched, this method returns Long.MIN_VALUE or Long.MAX_VALUE depending on the optimization direction of the objective. Only allowed in states HxState.Paused or HxState.Stopped. Only allowed if this expression is an integer or a boolean. This method has the same behavior as getIntObjectiveBound(int).
        Parameters:
        objectiveIndex - Index of the objective.
        Returns:
        Bound of the given objective.
        Since:
        8.5
        See Also:
        HxExpression.isInt(), HxExpression.isBool()
      • getIntObjectiveBound

        public long getIntObjectiveBound​(int objectiveIndex)
        Returns the bound computed by the optimizer for the given objective. If the optimizer has never been launched, this method returns Long.MIN_VALUE or Long.MAX_VALUE depending on the optimization direction of the objective. Only allowed in states HxState.Paused or HxState.Stopped. Only allowed if this expression is an integer or a boolean.
        Parameters:
        objectiveIndex - Index of the objective.
        Returns:
        Bound of the given objective.
        Since:
        8.5
        See Also:
        HxExpression.isInt(), HxExpression.isBool()
      • getDoubleObjectiveBound

        public double getDoubleObjectiveBound​(int objectiveIndex)
        Returns the bound computed by the optimizer for the given objective. If the optimizer has never been launched, this method returns Double.NEGATIVE_INFINITY or Double.POSITIVE_INFINITY depending on the optimization direction of the objective. Only allowed in states HxState.Paused or HxState.Stopped. Only allowed if this expression is a double.
        Parameters:
        objectiveIndex - Index of the objective.
        Returns:
        Bound of the given objective.
        Since:
        8.5
        See Also:
        HxExpression.isDouble()
      • getObjectiveGap

        public double getObjectiveGap​(int objectiveIndex)
        Returns the gap computed by the optimizer for the given objective. The gap for feasible solutions is defined as: |obj - bound| / max(1, |obj|, |bound|). Infeasible solutions have an infinite gap. Only allowed in states HxState.Paused or HxState.Stopped.
        Parameters:
        objectiveIndex - Index of the objective.
        Returns:
        Gap of the given objective.
      • clear

        public void clear()
        Clears the solution and set all decisions to zero. Only allowed in state HxState.Stopped.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object