Package com.hexaly.optimizer
Class HxExpression
- java.lang.Object
-
- com.hexaly.optimizer.HxExpression
-
public class HxExpression extends java.lang.Object
Mathematical modeling expression. Expressions are used to build the mathematical optimization model associated to Hexaly Optimizer. An expression is composed of an operator (which corresponds to its type) and its operands (which are other expressions of the model).- See Also:
HxModel
,HxOperator
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addOperand(double constant)
Adds the given constant operand to this expression.void
addOperand(long constant)
Adds the given constant operand to this expression.void
addOperand(HxExpression expr)
Adds the given operand to this expression.void
addOperands(double... operands)
Adds the given constant double operands to this expression.void
addOperands(long... operands)
Adds the given constant integer operands to this expression.void
addOperands(HxExpression... operands)
Adds the given operands to this expression.void
addOperands(java.lang.Iterable<HxExpression> operands)
Adds the given operands to this expression.boolean
equals(java.lang.Object obj)
HxArray
getArrayValue()
Gets the value of this expression in the best solution found by the optimizer.HxCollection
getCollectionValue()
Gets the value of this expression in the best solution found by the optimizer.double
getDoubleValue()
Gets the value of this expression in the best solution found by the optimizer.HxExternalContext
getExternalContext()
Gets the native function context of this expression.int
getIndex()
Gets the index of this expression in the model.HxInterval
getIntervalValue()
Gets the value of this expression in the best solution found by the optimizer.long
getIntValue()
Gets the value of this expression in the best solution found by the optimizer.HxModel
getModel()
java.lang.String
getName()
Gets the name of this expression or the empty String if no name has been set.int
getNbOperands()
Gets the number of operands of this expression.HxExpression
getOperand(int operandIndex)
Gets the operand with the given index.HxOperator
getOperator()
Gets the operator of this expression.HexalyOptimizer
getOptimizer()
long
getValue()
Gets the value of this expression in the best solution found by the optimizer.int
hashCode()
boolean
isArray()
Returns true if this expression is an array, false otherwise.boolean
isBool()
Returns true if this expression is a boolean (ie 0 or 1), false otherwise.boolean
isCollection()
Returns true if this expression is a collection (list or set), false otherwise.boolean
isConstant()
Returns true if this expression is typed as constant in the model, false otherwise.boolean
isConstraint()
Returns true if this expression is tagged as constraint in the model, false otherwise.boolean
isDecision()
Returns true if this expression is typed as decision in the model, false otherwise.boolean
isDouble()
Returns true if this expression is a double, false otherwise.boolean
isFunction()
Returns true if this expression is a function, false otherwise.boolean
isInt()
Returns true if this expression is an integer, false otherwise.boolean
isInterval()
Returns true if this expression is an interval, false otherwise.boolean
isNamed()
Returns true if this expression has a name, and false otherwise.boolean
isObjective()
Returns true if this expression is tagged as objective in the model, false otherwise.boolean
isUndefined()
Returns true if the given expression has an undefined value in the best solution found by the optimizer.boolean
isViolated()
Returns true if the given expression is violated in the best solution found by the optimizer.void
setDoubleValue(double value)
Sets the value of this expression in the current solution found by the optimizer.void
setIntervalValue(HxInterval value)
Sets the value of this expression in the current solution found by the optimizer.void
setIntValue(long value)
Sets the value of this expression in the current solution found by the optimizer.void
setName(java.lang.String name)
Sets the name of this expression.void
setOperand(int operandIndex, double constant)
Replaces the operand of the given index.void
setOperand(int operandIndex, long constant)
Replaces the operand of the given index.void
setOperand(int operandIndex, HxExpression operand)
Replaces the operand of the given index.void
setValue(double value)
Sets the value of this expression in the current solution found by the optimizer.void
setValue(long value)
Sets the value of this expression in the current solution found by the optimizer.void
setValue(HxInterval value)
Sets the value of this expression in the current solution found by the optimizer.java.lang.String
toString()
-
-
-
Method Detail
-
getModel
public HxModel getModel()
-
getOptimizer
public HexalyOptimizer getOptimizer()
-
getOperator
public HxOperator getOperator()
Gets the operator of this expression.- Returns:
- Operator.
-
getIndex
public int getIndex()
Gets the index of this expression in the model.- Returns:
- Index in the model.
-
isConstant
public boolean isConstant()
Returns true if this expression is typed as constant in the model, false otherwise.- Returns:
- True if typed as constant.
-
isDecision
public boolean isDecision()
Returns true if this expression is typed as decision in the model, false otherwise.- Returns:
- True if typed as decision.
-
isConstraint
public boolean isConstraint()
Returns true if this expression is tagged as constraint in the model, false otherwise.- Returns:
- True if tagged as constraint.
-
isObjective
public boolean isObjective()
Returns true if this expression is tagged as objective in the model, false otherwise.- Returns:
- True if tagged as objective.
-
isDouble
public boolean isDouble()
Returns true if this expression is a double, false otherwise. Only allowed in statesHxState.Paused
orHxState.Stopped
.- Returns:
- True if the expression is a double.
- Since:
- 3.0
-
isInt
public boolean isInt()
Returns true if this expression is an integer, false otherwise. Only allowed in statesHxState.Paused
orHxState.Stopped
. Note that a boolean is also an integer.- Returns:
- True if the expression is an integer.
- Since:
- 3.0
-
isBool
public boolean isBool()
Returns true if this expression is a boolean (ie 0 or 1), false otherwise. Only allowed in statesHxState.Paused
orHxState.Stopped
.- Returns:
- True if the expression is a boolean.
- Since:
- 3.0
-
isInterval
public boolean isInterval()
Returns true if this expression is an interval, false otherwise. Only allowed in statesHxState.Paused
orHxState.Stopped
.- Returns:
- True if the expression is an interval.
- Since:
- 12.0
-
isArray
public boolean isArray()
Returns true if this expression is an array, false otherwise. Only allowed in statesHxState.Paused
orHxState.Stopped
.- Returns:
- True if the expression is an array.
- Since:
- 3.1
-
isCollection
public boolean isCollection()
Returns true if this expression is a collection (list or set), false otherwise. Only allowed in statesHxState.Paused
orHxState.Stopped
.- Returns:
- True if the expression is a collection.
- Since:
- 5.5
-
isFunction
public boolean isFunction()
Returns true if this expression is a function, false otherwise. Only allowed in statesHxState.Paused
orHxState.Stopped
.- Returns:
- True if the expression is a function.
- Since:
- 6.0
-
addOperand
public void addOperand(HxExpression expr)
Adds the given operand to this expression. Only allowed in stateHxState.Modeling
.- Parameters:
expr
- Operand to add.
-
addOperand
public void addOperand(long constant)
Adds the given constant operand to this expression. Only allowed in stateHxState.Modeling
.- Parameters:
constant
- Constant operand to add.
-
addOperand
public void addOperand(double constant)
Adds the given constant operand to this expression. Only allowed in stateHxState.Modeling
.- Parameters:
constant
- Constant operand to add.
-
addOperands
public void addOperands(java.lang.Iterable<HxExpression> operands)
Adds the given operands to this expression. Only allowed in stateHxState.Modeling
.- Parameters:
operands
- The iterable collection of operands to be added.- Since:
- 5.5
-
addOperands
public void addOperands(long... operands)
Adds the given constant integer operands to this expression. Only allowed in stateHxState.Modeling
.- Parameters:
operands
- The constant integer operands to be added.- Since:
- 5.5
-
addOperands
public void addOperands(double... operands)
Adds the given constant double operands to this expression. Only allowed in stateHxState.Modeling
.- Parameters:
operands
- The constant double operands to be added.- Since:
- 5.5
-
addOperands
public void addOperands(HxExpression... operands)
Adds the given operands to this expression. Only allowed in stateHxState.Modeling
.- Parameters:
operands
- The operands to be added.- Since:
- 5.5
-
getOperand
public HxExpression getOperand(int operandIndex)
Gets the operand with the given index.- Parameters:
operandIndex
- Index of the operand.- Returns:
- Operand.
-
setOperand
public void setOperand(int operandIndex, HxExpression operand)
Replaces the operand of the given index.- Parameters:
operandIndex
- Index of the operand to changeoperand
- New operand
-
setOperand
public void setOperand(int operandIndex, long constant)
Replaces the operand of the given index.- Parameters:
operandIndex
- Index of the operand to change.constant
- New constant operand.
-
setOperand
public void setOperand(int operandIndex, double constant)
Replaces the operand of the given index.- Parameters:
operandIndex
- Index of the operand to change.constant
- New constant operand.- Since:
- 3.0
-
getNbOperands
public int getNbOperands()
Gets the number of operands of this expression.- Returns:
- Number of operands.
-
setValue
public void setValue(long value)
Sets the value of this expression in the current solution found by the optimizer. Only allowed for decisions. Only allowed in stateHxState.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. This method is a shortcut forHxSolution.setValue(HxExpression, long)
and has the same behavior assetIntValue(long)
.- Parameters:
value
- Value assigned to this expression.- See Also:
HxSolution.setValue(HxExpression, long)
,isInt()
,isBool()
-
setValue
public void setValue(double value)
Sets the value of this expression in the current solution found by the optimizer. Only allowed for decisions. 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. This method is a shortcut forHxSolution.setValue(HxExpression, double)
and has the same behavior assetDoubleValue(double)
.- Parameters:
value
- Value assigned to this expression.- See Also:
HxSolution.setValue(HxExpression expr, double value)
,isDouble()
-
setValue
public void setValue(HxInterval value)
Sets the value of this expression in the current solution found by the optimizer. Only allowed for decisions. Only allowed in stateHxState.Stopped
. Only allowed if this expression is an interval. If the optimizer was not launched, this value will be used as an initial value for the decision. This method is a shortcut forHxSolution.setValue(HxExpression, HxInterval)
and has the same behavior assetIntervalValue(HxInterval)
.- Parameters:
value
- Value assigned to this expression.- See Also:
HxSolution.setValue(HxExpression, long)
,isInterval()
-
setIntValue
public void setIntValue(long value)
Sets the value of this expression in the current solution found by the optimizer. Only allowed for decisions. Only allowed in stateHxState.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. This method is a shortcut forHxSolution.setValue(HxExpression, long)
.- Parameters:
value
- Value assigned to this expression.- Since:
- 3.0
- See Also:
HxSolution.setIntValue(HxExpression, long)
,isInt()
,isBool()
-
setDoubleValue
public void setDoubleValue(double value)
Sets the value of this expression in the current solution found by the optimizer. Only allowed for decisions. Only allowed in stateHxState.Stopped
. Only allowed if this expression is a double. If the optimizer was not launched, this value will be used as an initial value for the decision. This method is a shortcut forHxSolution.setValue(HxExpression, double)
.- Parameters:
value
- Value assigned to this expression.- Since:
- 3.0
- See Also:
HxSolution.setDoubleValue(HxExpression, double)
,isDouble()
-
setIntervalValue
public void setIntervalValue(HxInterval value)
Sets the value of this expression in the current solution found by the optimizer. Only allowed for decisions. Only allowed in stateHxState.Stopped
. Only allowed if this expression is an interval. If the optimizer was not launched, this value will be used as an initial value for the decision. This method is a shortcut forHxSolution.setValue(HxExpression, HxInterval)
.- Parameters:
value
- Value assigned to this expression.- Since:
- 3.0
- See Also:
HxSolution.setIntervalValue(HxExpression, HxInterval)
,isInterval()
-
getValue
public long getValue()
Gets the value of this expression in the best solution found by the optimizer. Only allowed in statesHxState.Paused
orHxState.Stopped
. Only allowed if this expression is an integer or a boolean. This method is a shortcut forHxSolution.getValue(HxExpression)
.- Returns:
- Value in the best solution.
- See Also:
HxSolution.getValue(HxExpression)
,isInt()
,isBool()
-
getIntValue
public long getIntValue()
Gets the value of this expression in the best solution found by the optimizer. Only allowed in statesHxState.Paused
orHxState.Stopped
. Only allowed if this expression is an integer or a boolean. This method is a shortcut forHxSolution.getIntValue(HxExpression)
.- Returns:
- Value in the best solution.
- Since:
- 3.0
- See Also:
HxSolution.getIntValue(HxExpression)
,isInt()
,isBool()
-
getDoubleValue
public double getDoubleValue()
Gets the value of this expression in the best solution found by the optimizer. Only allowed in statesHxState.Paused
orHxState.Stopped
. Only allowed if this expression is a double. This method is a shortcut forHxSolution.getDoubleValue(HxExpression)
.- Returns:
- Value in the best solution.
- Since:
- 3.0
- See Also:
HxSolution.getDoubleValue(HxExpression)
,isDouble()
-
getIntervalValue
public HxInterval getIntervalValue()
Gets the value of this expression in the best solution found by the optimizer. Only allowed in statesHxState.Paused
orHxState.Stopped
. Only allowed if this expression is an interval. This method is a shortcut forHxSolution.getIntervalValue(HxExpression)
.- Returns:
- Value in the best solution.
- Since:
- 12.0
- See Also:
HxSolution.getIntervalValue(HxExpression)
,isInterval()
-
getCollectionValue
public HxCollection getCollectionValue()
Gets the value of this expression in the best solution found by the optimizer. Only allowed in statesHxState.Paused
orHxState.Stopped
. Only allowed if this expression is a collection (list or set). This method is a shortcut forHxSolution.getCollectionValue(HxExpression)
.- Returns:
- Value in the best solution.
- Since:
- 5.5
- See Also:
HxSolution.getCollectionValue(HxExpression)
,isCollection()
-
getArrayValue
public HxArray getArrayValue()
Gets the value of this expression in the best solution found by the optimizer. Only allowed in statesHxState.Paused
orHxState.Stopped
. Only allowed if this expression is an array. This method is a shortcut forHxSolution.getArrayValue(HxExpression)
.- Returns:
- Value in the best solution.
- Since:
- 7.5
- See Also:
HxSolution.getArrayValue(HxExpression)
,isArray()
-
getExternalContext
public HxExternalContext getExternalContext()
Gets the native function context of this expression. Only allowed if this expression is a native function.- Returns:
- Context of the native function.
- Since:
- 9.5
- See Also:
HxExternalContext
-
isViolated
public boolean isViolated()
Returns true if the given expression is violated in the best solution found by the optimizer. 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).
HxState.Paused
orHxState.Stopped
. This method is a shortcut forHxSolution.isViolated(HxExpression)
.- Returns:
- True if this expression is violated in the best solution.
- Since:
- 5.5
-
isUndefined
public boolean isUndefined()
Returns true if the given expression has an undefined value in the best solution found by the optimizer. found by the optimizer. 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).
HxState.Paused
orHxState.Stopped
. This method is a shortcut forHxSolution.isUndefined(HxExpression)
.- Returns:
- True if this expression has an undefined value in the best solution.
- Since:
- 7.0
-
setName
public void setName(java.lang.String name)
Sets the name of this expression. Only allowed in stateHxState.Modeling
. The name cannot be empty. Two operators of the model cannot share the same name. Useful for debugging or logging purposes.- Parameters:
name
- Name.
-
isNamed
public boolean isNamed()
Returns true if this expression has a name, and false otherwise.- Returns:
- True if named.
-
getName
public java.lang.String getName()
Gets the name of this expression or the empty String if no name has been set.- Returns:
- Name.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
-