Package localsolver
Class LSSolution
- java.lang.Object
-
- localsolver.LSSolution
-
public class LSSolution 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:
LSSolutionStatus
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clears the solution and set all decisions to zero.boolean
equals(java.lang.Object obj)
LSArray
getArrayValue(LSExpression expr)
Gets the value of this expression in the best solution found by the solver.LSCollection
getCollectionValue(LSExpression expr)
Returns the value of the given expression in this solution.double
getDoubleObjectiveBound(int objectiveIndex)
Returns the bound computed by the solver for the given objective.double
getDoubleValue(LSExpression expr)
Returns the value of the given expression in this solution.LSInterval
getIntervalValue(LSExpression expr)
Returns the value of the given expression in this solution.long
getIntObjectiveBound(int objectiveIndex)
Returns the bound computed by the solver for the given objective.long
getIntValue(LSExpression expr)
Returns the value of the given expression in this solution.LocalSolver
getLocalSolver()
Returns the LocalSolver object associated to this solution.long
getObjectiveBound(int objectiveIndex)
Returns the bound computed by the solver for the given objective.double
getObjectiveGap(int objectiveIndex)
Returns the gap computed by the solver for the given objective.LSSolutionStatus
getStatus()
Returns the status of the solution.long
getValue(LSExpression expr)
Returns the value of the given expression in this solution.int
hashCode()
boolean
isUndefined(LSExpression expr)
Returns true if the given expression has an undefined value in this solution.boolean
isViolated(LSExpression expr)
Returns true if the given expression is violated in this solution.void
setDoubleValue(LSExpression expr, double value)
Sets the value of the given expression in this solution.void
setIntervalValue(LSExpression expr, LSInterval value)
Sets the value of the given expression in this solution.void
setIntValue(LSExpression expr, long value)
Sets the value of the given expression in this solution.void
setValue(LSExpression expr, double value)
Sets the value of the given expression in this solution.void
setValue(LSExpression expr, long value)
Sets the value of the given expression in this solution.void
setValue(LSExpression expr, LSInterval value)
Sets the value of the given expression in this solution.
-
-
-
Method Detail
-
getLocalSolver
public LocalSolver getLocalSolver()
Returns the LocalSolver object associated to this solution.- Returns:
- LocalSolver object.
-
setValue
public void setValue(LSExpression expr, long value)
Sets the value of the given expression in this solution. Only decisions can be set. Only allowed in stateLSState.Stopped
. Only allowed if this expression is an integer or a boolean. If the solver was not launched, this value will be used as an initial value for the decision. This method has the same behavior assetIntValue(localsolver.LSExpression, long)
.- Parameters:
expr
- Decision.value
- Value assigned to the decision in this solution.- See Also:
LSExpression.isDecision()
,LSExpression.isInt()
,LSExpression.isBool()
-
setValue
public void setValue(LSExpression expr, double value)
Sets the value of the given expression in this solution. Only decisions can be set. Only allowed in stateLSState.Stopped
. Only allowed if this expression is a double. If the solver was not launched, this value will be used as an initial value for the decision. This method has the same behavior assetDoubleValue(localsolver.LSExpression, double)
.- Parameters:
expr
- Decision.value
- Value assigned to the decision in this solution.- See Also:
LSExpression.isDecision()
,LSExpression.isDouble()
-
setValue
public void setValue(LSExpression expr, LSInterval value)
Sets the value of the given expression in this solution. Only decisions can be set. Only allowed in stateLSState.Stopped
. Only allowed if this expression is an interval. If the solver was not launched, this value will be used as an initial value for the decision. This method has the same behavior assetIntervalValue(localsolver.LSExpression, localsolver.LSInterval)
.- Parameters:
expr
- Decision.value
- Value assigned to the decision in this solution.- See Also:
LSExpression.isDecision()
,LSExpression.isInterval()
-
setIntValue
public void setIntValue(LSExpression expr, long value)
Sets the value of the given expression in this solution. Only decisions can be set. Only allowed in stateLSState.Stopped
. Only allowed if this expression is an integer or a boolean. If the solver 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:
LSExpression.isDecision()
,LSExpression.isInt()
-
setDoubleValue
public void setDoubleValue(LSExpression expr, double value)
Sets the value of the given expression in this solution. Only decisions can be set. Only allowed in stateLSState.Stopped
. If the solver 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:
LSExpression.isDecision()
,LSExpression.isDouble()
-
setIntervalValue
public void setIntervalValue(LSExpression expr, LSInterval value)
Sets the value of the given expression in this solution. Only decisions can be set. Only allowed in stateLSState.Stopped
. If the solver 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:
LSExpression.isDecision()
,LSExpression.isInterval()
-
getValue
public long getValue(LSExpression expr)
Returns the value of the given expression in this solution. Only allowed in statesLSState.Paused
orLSState.Stopped
. Only allowed if this expression is an integer or a boolean. This method has the same behavior asgetIntValue(LSExpression)
.- Parameters:
expr
- Expression.- Returns:
- Value of the expression in this solution.
- See Also:
LSExpression.isInt()
,LSExpression.isBool()
-
getDoubleValue
public double getDoubleValue(LSExpression expr)
Returns the value of the given expression in this solution. Only allowed in statesLSState.Paused
orLSState.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:
LSExpression.isDouble()
-
getIntValue
public long getIntValue(LSExpression expr)
Returns the value of the given expression in this solution. Only allowed in statesLSState.Paused
orLSState.Stopped
. Only allowed if this expression is an integer or a boolean.- Parameters:
expr
- Expression.- Returns:
- Value of the expression in this solution.
- Since:
- 3.0
- See Also:
LSExpression.isInt()
,LSExpression.isBool()
-
getIntervalValue
public LSInterval getIntervalValue(LSExpression expr)
Returns the value of the given expression in this solution. Only allowed in statesLSState.Paused
orLSState.Stopped
. Only allowed if this expression is an interval.- Parameters:
expr
- Expression.- Returns:
- Value of the expression in this solution.
- Since:
- 12.0
- See Also:
LSExpression.isInterval()
-
getCollectionValue
public LSCollection getCollectionValue(LSExpression expr)
Returns the value of the given expression in this solution. Only allowed in statesLSState.Paused
orLSState.Stopped
. Only allowed if this expression is a collection (list or set). This method is a shortcut forgetCollectionValue(localsolver.LSExpression)
.- Parameters:
expr
- Expression.- Returns:
- Value of the expression in this solution.
- Since:
- 5.5
- See Also:
LSExpression.isCollection()
-
getArrayValue
public LSArray getArrayValue(LSExpression expr)
Gets the value of this expression in the best solution found by the solver. Only allowed in statesLSState.Paused
orLSState.Stopped
. Only allowed if this expression is an array. This method is a shortcut forgetArrayValue(localsolver.LSExpression)
.- Returns:
- Value in the best solution.
- Since:
- 7.5
- See Also:
LSExpression.isArray()
-
isViolated
public boolean isViolated(LSExpression expr)
Returns true if the given expression is violated in this solution. An expression can be violated in 3 cases:- It is a constraint and its value is 0.
- It is a double and its value is NaN (Not A Number).
- It is an integer or boolean with no valid value (arithmetic or out of bounds exception).
LSState.Paused
orLSState.Stopped
.- Parameters:
expr
- Expression.- Returns:
- True if this expression is violated in this solution.
- Since:
- 5.5
-
isUndefined
public boolean isUndefined(LSExpression expr)
Returns true if the given expression has an undefined value in this solution. An expression can be undefined in 4 cases:- It is a double and its value is NaN (Not a Number).
- It is an integer or boolean with no valid value (arithmetic or out of bounds exception).
- It is an interval with at least one undefined bound.
- It is the result of any ill-defined operation (at with out of bounds index or operations on undefined values for instance).
LSState.Paused
orLSState.Stopped
.- Parameters:
expr
- Expression.- Returns:
- True if this expression has an undefined value in this solution.
- Since:
- 7.0
-
getStatus
public LSSolutionStatus getStatus()
Returns the status of the solution. Only allowed in statesLSState.Paused
orLSState.Stopped
.- Returns:
- Status of the solution.
- See Also:
LSSolutionStatus
-
getObjectiveBound
public long getObjectiveBound(int objectiveIndex)
Returns the bound computed by the solver for the given objective. If the solver 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 statesLSState.Paused
orLSState.Stopped
. Only allowed if this expression is an integer or a boolean. This method has the same behavior asgetIntObjectiveBound(int)
.- Parameters:
objectiveIndex
- Index of the objective.- Returns:
- Bound of the given objective.
- Since:
- 8.5
- See Also:
LSExpression.isInt()
,LSExpression.isBool()
-
getIntObjectiveBound
public long getIntObjectiveBound(int objectiveIndex)
Returns the bound computed by the solver for the given objective. If the solver 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 statesLSState.Paused
orLSState.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:
LSExpression.isInt()
,LSExpression.isBool()
-
getDoubleObjectiveBound
public double getDoubleObjectiveBound(int objectiveIndex)
Returns the bound computed by the solver for the given objective. If the solver 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 statesLSState.Paused
orLSState.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:
LSExpression.isDouble()
-
getObjectiveGap
public double getObjectiveGap(int objectiveIndex)
Returns the gap computed by the solver for the given objective. It is defined as: |obj - bound| / max(1, |obj|, |bound|). Only allowed in statesLSState.Paused
orLSState.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 stateLSState.Stopped
.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
-