Module org.chocosolver.solver
Class AbstractGraphVar<E extends IGraph>
java.lang.Object
org.chocosolver.solver.variables.impl.AbstractVariable
org.chocosolver.solver.variables.impl.AbstractGraphVar<E>
- All Implemented Interfaces:
Comparable<Variable>
,Identity
,GraphVar<E>
,Variable
- Direct Known Subclasses:
DirectedGraphVarImpl
,UndirectedGraphVarImpl
public abstract class AbstractGraphVar<E extends IGraph>
extends AbstractVariable
implements GraphVar<E>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected GraphDelta
protected E
protected int
protected boolean
protected E
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractGraphVar
(String name, Model solver, E LB, E UB) Creates a graph variable -
Method Summary
Modifier and TypeMethodDescriptionvoid
Create a delta, if necessary, in order to observe removed values of a this.boolean
enforceEdge
(int x, int y, ICause cause) Adds edge (directed directed graph variable) (x,y) in the lower boundboolean
enforceNode
(int x, ICause cause) Enforce the node x to belong to any solution Adds x to the lower bound graphgetDelta()
Return the delta domain of thisgetLB()
Get GraphVar lower bound (or kernel): the graph which is a subgraph of any instantiation.int
int
Return a MASK composed of 2 main information: TYPE and KIND.getUB()
Get GraphVar upper bound (or envelope): any instantiation of this GraphVar is a subgraph of the upper bound.boolean[][]
void
instantiateTo
(boolean[][] value, ICause cause) Instantiatesthis
to value which represents an adjacency matrix plus a set of nodes (last row of the matrix).void
instantiateTo
(E value, ICause cause) Instantiatesthis
to value given in parameter.boolean
Indicates whetherthis
is instantiated (see implementations to know what instantiation means).monitorDelta
(ICause propagator) Make the propagator 'prop' have an incremental filtering w.r.t. this graph variablevoid
notifyPropagators
(IEventType event, ICause cause) Ifthis
has changed, then notify all of its observers.
Each observer has its update method.boolean
removeEdge
(int x, int y, ICause cause) Removes edge (directed in case of directed graph variable) (x,y) from the upper boundboolean
removeNode
(int x, ICause cause) Remove node x from the domain Removes x from the upper bound graphtoString()
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, 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 java.lang.Comparable
compareTo
Methods inherited from interface org.chocosolver.solver.variables.GraphVar
getDomainSize, getMandatoryNodes, getMandatoryPredecessorsOf, getMandatorySuccessorsOf, getPotentialNodes, getPotentialPredecessorOf, getPotentialSuccessorsOf, getValue, isDirected
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, notifyViews, recordWorldIndex, removeMonitor, schedule, schedulePropagators, storeEvents, streamPropagators, subscribeView, swapOnPassivate, unlink, unschedule
-
Field Details
-
UB
-
LB
-
delta
-
n
protected int n -
reactOnModification
protected boolean reactOnModification
-
-
Constructor Details
-
AbstractGraphVar
Creates a graph variable- Parameters:
solver
-
-
-
Method Details
-
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
-
removeNode
Remove node x from the domain Removes x from the upper bound graph- Specified by:
removeNode
in interfaceGraphVar<E extends IGraph>
- Parameters:
x
- node's indexcause
- algorithm which is related to the removal- Returns:
- true iff the removal has an effect
- Throws:
ContradictionException
-
enforceNode
Enforce the node x to belong to any solution Adds x to the lower bound graph- Specified by:
enforceNode
in interfaceGraphVar<E extends IGraph>
- Parameters:
x
- node's indexcause
- algorithm which is related to the modification- Returns:
- true iff the enforcing has an effect
- Throws:
ContradictionException
-
removeEdge
Description copied from interface:GraphVar
Removes edge (directed in case of directed graph variable) (x,y) from the upper bound- Specified by:
removeEdge
in interfaceGraphVar<E extends IGraph>
- Parameters:
x
- node's indexy
- node's indexcause
- cause of edge removal- Returns:
- true iff the edge has been removed from the upper bound
- Throws:
ContradictionException
- if the edge was mandatory
-
enforceEdge
Description copied from interface:GraphVar
Adds edge (directed directed graph variable) (x,y) in the lower bound- Specified by:
enforceEdge
in interfaceGraphVar<E extends IGraph>
- Parameters:
x
- node's indexy
- node's indexcause
- cause of edge addition- Returns:
- true iff the edge has been add to the lower bound
- Throws:
ContradictionException
-
getLB
Description copied from interface:GraphVar
Get GraphVar lower bound (or kernel): the graph which is a subgraph of any instantiation. -
getUB
Description copied from interface:GraphVar
Get GraphVar upper bound (or envelope): any instantiation of this GraphVar is a subgraph of the upper bound. -
getNbMaxNodes
public int getNbMaxNodes()- Specified by:
getNbMaxNodes
in interfaceGraphVar<E extends IGraph>
- Returns:
- the maximum number of node the graph variable may have. Nodes are comprised in the interval [0,getNbMaxNodes()] Therefore, any vertex should be strictly lower than getNbMaxNodes()
-
getDelta
Description copied from interface:Variable
Return the delta domain of this -
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 invalid input: '<'invalid input: '<' 0), CSTE (1 invalid input: '<'invalid input: '<' 1) or VIEW (1 invalid input: '<'invalid input: '<' 2)
KIND is defined on the other bits : INT (1 invalid input: '<'invalid input: '<' 3), BOOL (INT + 1 invalid input: '<'invalid input: '<' 4), GRAPH (1 invalid input: '<'invalid input: '<' 5) or META (1 invalid input: '<'invalid input: '<' 6) To get the TYPE of a variable:int type = var.getTypeAndKind() invalid input: '&' Variable.TYPE;
To get the KIND of a variable:int kind = var.getTypeAndKind() invalid input: '&' Variable.KIND;
To check a specific type or kind of a variable:boolean isVar = (var.getTypeAndKind() invalid input: '&' Variable.VAR) !=0; boolean isInt = (var.getTypeAndKind() invalid input: '&' Variable.INT) !=0;
- Specified by:
getTypeAndKind
in interfaceVariable
- Returns:
- an int representing the type and kind of the variable
-
createScheduler
- Specified by:
createScheduler
in classAbstractVariable
-
toString
- Overrides:
toString
in classAbstractVariable
-
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
-
notifyPropagators
Description copied from interface:Variable
Ifthis
has changed, then notify all of its observers.
Each observer has its update method.- Specified by:
notifyPropagators
in interfaceVariable
- Overrides:
notifyPropagators
in classAbstractVariable
- Parameters:
event
- event on this objectcause
- object which leads to the modification of this object- Throws:
ContradictionException
- if a contradiction occurs during notification
-
instantiateTo
Description copied from interface:GraphVar
Instantiatesthis
to value given in parameter. This method is not supposed to be used except for restoring solutions.- Specified by:
instantiateTo
in interfaceGraphVar<E extends IGraph>
- Parameters:
value
- value ofthis
cause
-- Throws:
ContradictionException
-
getValueAsBoolMatrix
public boolean[][] getValueAsBoolMatrix()- Returns:
- the value of the graph variable represented through an adjacency matrix plus a set of nodes (last row of the matrix). This method is not supposed to be used except for restoring solutions.
-
instantiateTo
Instantiatesthis
to value which represents an adjacency matrix plus a set of nodes (last row of the matrix). This method is not supposed to be used except for restoring solutions.- Parameters:
value
- value ofthis
cause
-- Throws:
ContradictionException
- if the edge was mandatory
-
monitorDelta
Description copied from interface:GraphVar
Make the propagator 'prop' have an incremental filtering w.r.t. this graph variable- Specified by:
monitorDelta
in interfaceGraphVar<E extends IGraph>
- Parameters:
propagator
- A propagator involving this graph variable- Returns:
- A new instance of GraphDeltaMonitor to make incremental propagators
-