- java.lang.Object
-
- org.chocosolver.solver.variables.impl.AbstractVariable
-
- org.chocosolver.solver.variables.impl.RealVarImpl
-
- All Implemented Interfaces:
java.lang.Comparable<Variable>
,CArExpression
,Identity
,RealVar
,Variable
,RealInterval
public class RealVarImpl extends AbstractVariable implements RealVar
An implementation of RealVar, variable for continuous constraints (solved using IBEX).- Since:
- 18/07/12
- Author:
- Charles Prud'homme
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.chocosolver.solver.expression.continuous.arithmetic.CArExpression
CArExpression.Operator
-
-
Constructor Summary
Constructors Constructor Description RealVarImpl(java.lang.String name, double lb, double ub, double precision, Model model)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
collectVariables(java.util.TreeSet<RealVar> set)
Collects real variables involved in this expression and add them into 'set'.void
createDelta()
Create a delta, if necessary, in order to observe removed values of a this.protected EvtScheduler
createScheduler()
NoDelta
getDelta()
Return the delta domain of thisdouble
getLB()
Retrieves the lower bound of the variabledouble
getPrecision()
int
getTypeAndKind()
Return a MASK composed of 2 main information: TYPE and KIND.double
getUB()
Retrieves the upper bound of the variablevoid
init()
Initializes this expression when this serves as input ofPropEquation
.void
intersect(double l, double u, ICause cause)
Modifies the bounds for intersecting with the specified interval.boolean
isInstantiated()
Indicates whetherthis
is instantiated (see implementations to know what instantiation means).boolean
isolate(RealVar var, java.util.List<CArExpression> wx, java.util.List<CArExpression> wox)
Considering 'var' and this expression, fills 'wx' with sub-expressions involving 'var' and fills 'wox' with sub-expressions not involving 'var'.void
project(ICause cause)
Projects computed bounds to the sub expressions.void
silentlyAssign(double lb, double ub)
void
silentlyAssign(RealInterval bounds)
void
subExps(java.util.List<CArExpression> list)
Collects sub-expressions composing this expression and add them to 'list'.void
tighten()
Computes the narrowest bounds with respect to sub terms.java.lang.String
toString()
boolean
updateBounds(double lowerbound, double upperbound, ICause cause)
Updates the bounds of the domain ofthis
tovalue
.boolean
updateLowerBound(double value, ICause cause)
Updates the lower bound of the domain ofthis
tovalue
.boolean
updateUpperBound(double value, ICause cause)
Updates the upper bound of the domain ofthis
tovalue
.-
Methods inherited from class org.chocosolver.solver.variables.impl.AbstractVariable
addMonitor, asBoolVar, asIntVar, asRealVar, asSetVar, clearEvents, compareTo, contradiction, equals, forEachPropagator, getCause, getEvtScheduler, getId, getMask, getModel, getName, getNbProps, getNbViews, getView, hashCode, instantiationWorldIndex, isAConstant, isBool, isScheduled, link, notifyMonitors, notifyPropagators, notifyViews, recordWorldIndex, removeMonitor, schedule, schedulePropagators, storeEvents, streamPropagators, subscribeView, swapOnPassivate, unlink, unschedule
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.chocosolver.solver.expression.continuous.arithmetic.CArExpression
abs, acos, acosh, add, add, asin, asinh, atan, atan2, atan2, atanh, cbrt, cos, cosh, cub, div, div, eq, eq, exp, ge, ge, getModel, gt, gt, le, le, ln, lt, lt, max, max, min, min, mul, mul, neg, pow, pow, sin, sinh, sqr, sqrt, sub, sub, tan, tanh
-
Methods inherited from interface org.chocosolver.util.objects.RealInterval
intersect
-
Methods inherited from interface org.chocosolver.solver.variables.RealVar
getDomainSize, realVar
-
Methods inherited from interface org.chocosolver.solver.variables.Variable
addMonitor, asBoolVar, asIntVar, asRealVar, asSetVar, clearEvents, contradiction, forEachPropagator, getCause, getEnvironment, getEvtScheduler, getMask, getModel, getName, getNbProps, getNbViews, getView, instantiationWorldIndex, isAConstant, isScheduled, link, notifyMonitors, notifyPropagators, notifyViews, recordWorldIndex, removeMonitor, schedule, schedulePropagators, storeEvents, streamPropagators, subscribeView, swapOnPassivate, unlink, unschedule
-
-
-
-
Constructor Detail
-
RealVarImpl
public RealVarImpl(java.lang.String name, double lb, double ub, double precision, Model model)
-
-
Method Detail
-
getPrecision
public double getPrecision()
- Specified by:
getPrecision
in interfaceRealVar
-
silentlyAssign
public void silentlyAssign(RealInterval bounds)
- Specified by:
silentlyAssign
in interfaceRealVar
-
silentlyAssign
public void silentlyAssign(double lb, double ub)
- Specified by:
silentlyAssign
in interfaceRealVar
-
getLB
public double getLB()
Description copied from interface:RealInterval
Retrieves the lower bound of the variable- Specified by:
getLB
in interfaceRealInterval
- Returns:
- the lower bound
-
getUB
public double getUB()
Description copied from interface:RealInterval
Retrieves the upper bound of the variable- Specified by:
getUB
in interfaceRealInterval
- Returns:
- the upper bound
-
intersect
public void intersect(double l, double u, ICause cause) throws ContradictionException
Description copied from interface:RealInterval
Modifies the bounds for intersecting with the specified interval.- Specified by:
intersect
in interfaceRealInterval
- Parameters:
l
- lower boundu
- upper boundcause
- who launches the intersection- Throws:
ContradictionException
- if a failure occurs
-
updateLowerBound
public boolean updateLowerBound(double value, ICause cause) throws ContradictionException
Description copied from interface:RealVar
Updates the lower bound of the domain ofthis
tovalue
. The instruction comes frompropagator
.- If
value
is smaller than the lower bound of the domain, nothing is done and the return value isfalse
, - if updating the lower bound to
value
leads to a dead-end (domain wipe-out), aContradictionException
is thrown, - otherwise, if updating the lower bound to
value
can be done safely, the event type is created (the original event can be promoted) and observers are notified and the return value istrue
- Specified by:
updateLowerBound
in interfaceRealVar
- Parameters:
value
- new lower bound (included)cause
- updating releaser- Returns:
- true if the lower bound has been updated, false otherwise
- Throws:
ContradictionException
- if the domain become empty due to this action
- If
-
updateUpperBound
public boolean updateUpperBound(double value, ICause cause) throws ContradictionException
Description copied from interface:RealVar
Updates the upper bound of the domain ofthis
tovalue
. The instruction comes frompropagator
.- If
value
is greater than the upper bound of the domain, nothing is done and the return value isfalse
, - if updating the upper bound to
value
leads to a dead-end (domain wipe-out), aContradictionException
is thrown, - otherwise, if updating the upper bound to
value
can be done safely, the event type is created (the original event can be promoted) and observers are notified and the return value istrue
- Specified by:
updateUpperBound
in interfaceRealVar
- Parameters:
value
- new upper bound (included)cause
- update releaser- Returns:
- true if the upper bound has been updated, false otherwise
- Throws:
ContradictionException
- if the domain become empty due to this action
- If
-
updateBounds
public boolean updateBounds(double lowerbound, double upperbound, ICause cause) throws ContradictionException
Description copied from interface:RealVar
Updates the bounds of the domain ofthis
tovalue
. The instruction comes frompropagator
.- If the interval defined by [
lowerbound
,upperbound
] includes the domain of this, nothing is done and the return value isfalse
, - if updating the domain leads to a dead-end (domain wipe-out),
a
ContradictionException
is thrown, - otherwise, if updating the domain be done safely,
the event type is created (the original event can be promoted) and observers are notified
and the return value is
true
- Specified by:
updateBounds
in interfaceRealVar
- Parameters:
lowerbound
- new lower bound (included)upperbound
- new upper bound (included)cause
- update releaser- Returns:
- true if the upper bound has been updated, false otherwise
- Throws:
ContradictionException
- if the domain become empty due to this action
- If the interval defined by [
-
isInstantiated
public boolean isInstantiated()
Description copied from interface:Variable
Indicates whetherthis
is instantiated (see implementations to know what instantiation means).- Specified by:
isInstantiated
in interfaceVariable
- Returns:
true
ifthis
is instantiated
-
getDelta
public NoDelta getDelta()
Description copied from interface:Variable
Return the delta domain of this
-
createDelta
public void createDelta()
Description copied from interface:Variable
Create a delta, if necessary, in order to observe removed values of a this. If the delta already exists, has no effect.- Specified by:
createDelta
in interfaceVariable
-
getTypeAndKind
public int getTypeAndKind()
Description copied from interface:Variable
Return a MASK composed of 2 main information: TYPE and KIND.
TYPE is defined in the 3 first bits : VAR ( 1 << 0), CSTE (1 << 1) or VIEW (1 << 2)
KIND is defined on the other bits : INT (1 << 3), BOOL (INT + 1 << 4), GRAPH (1 << 5) or META (1 << 6) To get the TYPE of a variable:int type = var.getTypeAndKind() & Variable.TYPE;
To get the KIND of a variable:int kind = var.getTypeAndKind() & Variable.KIND;
To check a specific type or kind of a variable:boolean isVar = (var.getTypeAndKind() & Variable.VAR) !=0; boolean isInt = (var.getTypeAndKind() & Variable.INT) !=0;
- Specified by:
getTypeAndKind
in interfaceVariable
- Returns:
- an int representing the type and kind of the variable
-
createScheduler
protected EvtScheduler createScheduler()
- Specified by:
createScheduler
in classAbstractVariable
-
toString
public java.lang.String toString()
- Overrides:
toString
in classAbstractVariable
-
tighten
public void tighten()
Description copied from interface:CArExpression
Computes the narrowest bounds with respect to sub terms.- Specified by:
tighten
in interfaceCArExpression
-
project
public void project(ICause cause) throws ContradictionException
Description copied from interface:CArExpression
Projects computed bounds to the sub expressions.- Specified by:
project
in interfaceCArExpression
- Parameters:
cause
- reference to the instance ofPropEquation
involving this- Throws:
ContradictionException
-
collectVariables
public void collectVariables(java.util.TreeSet<RealVar> set)
Description copied from interface:CArExpression
Collects real variables involved in this expression and add them into 'set'.- Specified by:
collectVariables
in interfaceCArExpression
- Parameters:
set
- an ordered set of involved real variables
-
subExps
public void subExps(java.util.List<CArExpression> list)
Description copied from interface:CArExpression
Collects sub-expressions composing this expression and add them to 'list'.- Specified by:
subExps
in interfaceCArExpression
- Parameters:
list
- list of sub-expressions of this.
-
isolate
public boolean isolate(RealVar var, java.util.List<CArExpression> wx, java.util.List<CArExpression> wox)
Description copied from interface:CArExpression
Considering 'var' and this expression, fills 'wx' with sub-expressions involving 'var' and fills 'wox' with sub-expressions not involving 'var'.- Specified by:
isolate
in interfaceCArExpression
- Parameters:
var
- a real variablewx
- list of sub-expressions involving 'var'wox
- list of sub-expressions not involving 'var'- Returns:
- 'true' if this expression involves 'var'.
-
init
public void init()
Description copied from interface:CArExpression
Initializes this expression when this serves as input ofPropEquation
.- Specified by:
init
in interfaceCArExpression
-
-