Package org.jacop.search
Class TraceGenerator<T extends Var>
- java.lang.Object
-
- org.jacop.search.TraceGenerator<T>
-
- All Implemented Interfaces:
ConsistencyListener
,ExitChildListener<T>
,ExitListener
,SelectChoicePoint<T>
public class TraceGenerator<T extends Var> extends java.lang.Object implements SelectChoicePoint<T>, ConsistencyListener, ExitChildListener<T>, ExitListener
TODO TraceGenerator should accept as input to constructor a Search object. It should get all the previous listeners and establish itself as the parent of those listeners and substitute them for itself in the search provided. It should ask them to get the proper return value for listener functions which are returning a code. It should later act as suggested by those listeners. This way there may be no need for checking/informing trace if we search for all solutions or just one. However, on safety side before TraceGenerator object is created and search object passed to it maybe search object should be already properly set. Can we wrap one TraceGenerator within another TraceGenerator? It should be possible. getChoiceVariable in TraceGenerator assumes that the internal select choice point does not return choice point as primitive constraint. It incorrectly assumes that if no variable is given by getChoiceVariable then the search is finished. We need all check that getChoiceConstraint returns false. Can CPviz handle search for Set variables handle correctly 100%? If not maybe we should just makeTraceGenerator<T extends IntVar>
? FilterDom should not use string representation of the domain just use Enumeration to get values within domain and create required String. It should be more or less the same what toString() of domain is doing.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
TraceGenerator.SearchNode
-
Field Summary
Fields Modifier and Type Field Description (package private) ConsistencyListener[]
consistencyListeners
(package private) TraceGenerator.SearchNode
currentSearchNode
(package private) ExitChildListener<T>[]
exitChildListeners
(package private) ExitListener[]
exitListeners
(package private) javax.xml.transform.sax.TransformerHandler
hdTree
An xml handler for tree file.(package private) javax.xml.transform.sax.TransformerHandler
hdVis
An xml handler for visualization file.(package private) int
searchNodeId
(package private) java.util.Stack<TraceGenerator.SearchNode>
searchStack
(package private) SelectChoicePoint<T>
select
It stores the original select choice point method that is used by this trace wrapper.(package private) int
selectedValue
It specifies information about value being selected by internal select choice point.(package private) T
selectedVar
It stores information about var being selected by internal select choice point.java.util.List<Var>
tracedVar
It specifies the list of variables that are being traced.java.lang.String
treeFilename
The file containing information about tree for CPviz format.java.util.Map<Var,java.lang.Integer>
varIndex
java.lang.String
visFilename
The file containing visualisation information.(package private) int
visualisationNodeId
-
Constructor Summary
Constructors Modifier Constructor Description TraceGenerator(Search<T> search, SelectChoicePoint<T> select)
It creates a CPviz trace generator around proper select choice point object.TraceGenerator(Search<T> search, SelectChoicePoint<T> select, java.lang.String treeFilename, java.lang.String visFilename)
It creates a CPviz trace generator around proper select choice point object.TraceGenerator(Search<T> search, SelectChoicePoint<T> select, Var[] vars)
It creates a CPviz trace generator around proper select choice point object.TraceGenerator(Search<T> search, SelectChoicePoint<T> select, Var[] vars, java.lang.String treeFilename, java.lang.String visFilename)
It creates a CPviz trace generator around proper select choice point object.private
TraceGenerator(SelectChoicePoint<T> select, Var[] vars, java.lang.String treeFilename, java.lang.String visFilename)
It creates a CPviz trace generator around proper select choice point object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTracedVar(Var v)
boolean
executeAfterConsistency(boolean consistent)
It is executed right after consistency of the current search node.void
executedAtExit(Store store, int solutionsNo)
It is executed right after time out is determined.(package private) void
generateFailcNode(int searchNodeId, int parentNode, java.lang.String name, int size, Domain dom)
(package private) void
generateFailcNode(int searchNodeId, int parentNode, PrimitiveConstraint c)
(package private) void
generateFailNode(int searchNodeId, int parentNode, java.lang.String name, int size, int value)
(package private) void
generateSuccessNode(int searchNodeId)
(package private) void
generateTrycNode(int searchNodeId, int parentNode, java.lang.String name, int size, Domain dom)
(package private) void
generateTrycNode(int searchNodeId, int parentNode, PrimitiveConstraint c)
(package private) void
generateTryNode(int searchNodeId, int parentNode, java.lang.String name, int size, int value)
(package private) void
generateVisualizationNode(int searchNodeId, boolean tryNode)
PrimitiveConstraint
getChoiceConstraint(int index)
It returns the constraint which is the base of the choice point.int
getChoiceValue()
It returns a value which is the base of the next choice point.T
getChoiceVariable(int index)
It returns the variable which is the base on the next choice point.private java.lang.String
getDateTime()
int
getIndex()
It returns the current index.java.util.Map<T,java.lang.Integer>
getVariablesMapping()
It specifies the position of variables as given when variables of this select object were supplied.(package private) java.lang.String
intDomainToString(IntDomain domain)
boolean
leftChild(PrimitiveConstraint choice, boolean status)
It is executed after exiting the left child.boolean
leftChild(T var, int value, boolean status)
It is executed after exiting the left child.private int
maxValue(java.util.List<Var> vars)
private int
minValue(java.util.List<Var> vars)
(package private) void
prepareTreeHeader()
(package private) void
prepareVizHeader()
void
rightChild(PrimitiveConstraint choice, boolean status)
It is executed after exiting the right child.void
rightChild(T var, int value, boolean status)
It is executed after exiting the right child.void
setChildrenListeners(ConsistencyListener child)
Setting one child listener.void
setChildrenListeners(ConsistencyListener[] children)
Each of the child listeners will be called and the return code from them will be combined (taken into account) by a parent).void
setChildrenListeners(ExitChildListener<T> child)
It adds one child listener.void
setChildrenListeners(ExitChildListener<T>[] children)
It sets the children listeners for the current listener.void
setChildrenListeners(ExitListener child)
It sets one child listener.void
setChildrenListeners(ExitListener[] children)
It sets the children of this exit listener.(package private) java.lang.String
setDomainToString(SetDomain domain)
java.lang.String
toString()
-
-
-
Field Detail
-
consistencyListeners
ConsistencyListener[] consistencyListeners
-
exitChildListeners
ExitChildListener<T extends Var>[] exitChildListeners
-
exitListeners
ExitListener[] exitListeners
-
select
SelectChoicePoint<T extends Var> select
It stores the original select choice point method that is used by this trace wrapper.
-
selectedVar
T extends Var selectedVar
It stores information about var being selected by internal select choice point.
-
selectedValue
int selectedValue
It specifies information about value being selected by internal select choice point.
-
treeFilename
public final java.lang.String treeFilename
The file containing information about tree for CPviz format.
-
visFilename
public final java.lang.String visFilename
The file containing visualisation information.
-
hdTree
javax.xml.transform.sax.TransformerHandler hdTree
An xml handler for tree file.
-
hdVis
javax.xml.transform.sax.TransformerHandler hdVis
An xml handler for visualization file.
-
searchStack
java.util.Stack<TraceGenerator.SearchNode> searchStack
-
currentSearchNode
TraceGenerator.SearchNode currentSearchNode
-
searchNodeId
int searchNodeId
-
visualisationNodeId
int visualisationNodeId
-
tracedVar
public java.util.List<Var> tracedVar
It specifies the list of variables that are being traced.
-
varIndex
public java.util.Map<Var,java.lang.Integer> varIndex
-
-
Constructor Detail
-
TraceGenerator
public TraceGenerator(Search<T> search, SelectChoicePoint<T> select)
It creates a CPviz trace generator around proper select choice point object.- Parameters:
search
- it specifies search method used for depth-first-search.select
- it specifies how the select choice points are being generated.
-
TraceGenerator
public TraceGenerator(Search<T> search, SelectChoicePoint<T> select, java.lang.String treeFilename, java.lang.String visFilename)
It creates a CPviz trace generator around proper select choice point object.- Parameters:
search
- it specifies search method used for depth-first-search.select
- it specifies how the select choice points are being generated.treeFilename
- it specifies the file name for search tree trace (default tree.xml).visFilename
- it specifies the file name for variable trace (default vis.xml).
-
TraceGenerator
public TraceGenerator(Search<T> search, SelectChoicePoint<T> select, Var[] vars)
It creates a CPviz trace generator around proper select choice point object.- Parameters:
search
- it specifies search method used for depth-first-search.select
- it specifies how the select choice points are being generated.vars
- it specifies variables which are being traced.
-
TraceGenerator
private TraceGenerator(SelectChoicePoint<T> select, Var[] vars, java.lang.String treeFilename, java.lang.String visFilename)
It creates a CPviz trace generator around proper select choice point object.- Parameters:
select
- it specifies how the select choice points are being generated.vars
- it specifies variables which are being traced.treeFilename
- it specifies the file name for search tree trace (default tree.xml).visFilename
- it specifies the file name for variable trace (default vis.xml).
-
TraceGenerator
public TraceGenerator(Search<T> search, SelectChoicePoint<T> select, Var[] vars, java.lang.String treeFilename, java.lang.String visFilename)
It creates a CPviz trace generator around proper select choice point object.- Parameters:
search
- it specifies search method used for depth-first-search.select
- it specifies how the select choice points are being generated.vars
- it specifies variables which are being traced.treeFilename
- it specifies the file name for search tree trace (default tree.xml).visFilename
- it specifies the file name for variable trace (default vis.xml).
-
-
Method Detail
-
getChoiceVariable
public T getChoiceVariable(int index)
Description copied from interface:SelectChoicePoint
It returns the variable which is the base on the next choice point. Only if choice is of an X = C type. This function returns null if all variables have a value assigned or a choice point based on other type of constraint is being selected. The parameter index is the last variable which have been return by this SelectChoicePoint object which has not been backtracked upon yet.- Specified by:
getChoiceVariable
in interfaceSelectChoicePoint<T extends Var>
- Parameters:
index
- the position of the last variable in selection choice point heuristic.- Returns:
- variable based on which the choice needs to be created.
-
getChoiceValue
public int getChoiceValue()
Description copied from interface:SelectChoicePoint
It returns a value which is the base of the next choice point. Only if choice is of an getChoiceVariable() = getChoiceValue() type.- Specified by:
getChoiceValue
in interfaceSelectChoicePoint<T extends Var>
- Returns:
- value used in the choice point (value).
-
getChoiceConstraint
public PrimitiveConstraint getChoiceConstraint(int index)
Description copied from interface:SelectChoicePoint
It returns the constraint which is the base of the choice point. If the return value is equal to null and choice point is also not based on X = C type of constraint then all variables have been assigned a value.- Specified by:
getChoiceConstraint
in interfaceSelectChoicePoint<T extends Var>
- Parameters:
index
- the position of the last variable returned by selection choice point heuristic.- Returns:
- primitive constraint which is a base of a choice point.
-
getVariablesMapping
public java.util.Map<T,java.lang.Integer> getVariablesMapping()
Description copied from interface:SelectChoicePoint
It specifies the position of variables as given when variables of this select object were supplied.- Specified by:
getVariablesMapping
in interfaceSelectChoicePoint<T extends Var>
- Returns:
- mapping of variables to the positions in the variables array.
-
getIndex
public int getIndex()
Description copied from interface:SelectChoicePoint
It returns the current index. Supplying this value in the next invocation of select will make search for next variable faster without compromising efficiency.- Specified by:
getIndex
in interfaceSelectChoicePoint<T extends Var>
- Returns:
- internal position of the last variable chosen to be the base of the choice point.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
setChildrenListeners
public void setChildrenListeners(ConsistencyListener[] children)
Description copied from interface:ConsistencyListener
Each of the child listeners will be called and the return code from them will be combined (taken into account) by a parent).- Specified by:
setChildrenListeners
in interfaceConsistencyListener
- Parameters:
children
- the children listeners attached to this listener.
-
setChildrenListeners
public void setChildrenListeners(ConsistencyListener child)
Description copied from interface:ConsistencyListener
Setting one child listener.- Specified by:
setChildrenListeners
in interfaceConsistencyListener
- Parameters:
child
- the only child listener added to this consistency listener.
-
executeAfterConsistency
public boolean executeAfterConsistency(boolean consistent)
Description copied from interface:ConsistencyListener
It is executed right after consistency of the current search node. Returning true when the parameter was false is not advised as things like invalid solutions can be found.- Specified by:
executeAfterConsistency
in interfaceConsistencyListener
- Parameters:
consistent
- specifies if the consistency call returned true or false.- Returns:
- true if the search should continue, false if the search should act as the consistency returned false.
-
setChildrenListeners
public void setChildrenListeners(ExitChildListener<T>[] children)
Description copied from interface:ExitChildListener
It sets the children listeners for the current listener.- Specified by:
setChildrenListeners
in interfaceExitChildListener<T extends Var>
- Parameters:
children
- array containing children listeners.
-
setChildrenListeners
public void setChildrenListeners(ExitListener[] children)
Description copied from interface:ExitListener
It sets the children of this exit listener.- Specified by:
setChildrenListeners
in interfaceExitListener
- Parameters:
children
- an array containing the children.
-
leftChild
public boolean leftChild(T var, int value, boolean status)
Description copied from interface:ExitChildListener
It is executed after exiting the left child.- Specified by:
leftChild
in interfaceExitChildListener<T extends Var>
- Parameters:
var
- variable used in the choice point.value
- value used in the choice point.status
- true if the solution was found in the child subtree, false otherwise.- Returns:
- true if the search should continue undisturbed, false if it should exit the current node with false
-
leftChild
public boolean leftChild(PrimitiveConstraint choice, boolean status)
Description copied from interface:ExitChildListener
It is executed after exiting the left child.- Specified by:
leftChild
in interfaceExitChildListener<T extends Var>
- Parameters:
choice
- primitive constraint used as the base of the choice point.status
- true if the solution was found in the child subtree, false otherwise.- Returns:
- true if the search should continue undisturbed to the right node, false if it should exit the current node with false
-
rightChild
public void rightChild(T var, int value, boolean status)
Description copied from interface:ExitChildListener
It is executed after exiting the right child.- Specified by:
rightChild
in interfaceExitChildListener<T extends Var>
- Parameters:
var
- variable used in the choice point.value
- value used in the choice point.status
- true if the solution was found in the child subtree, false otherwise. exit the current node with false
-
rightChild
public void rightChild(PrimitiveConstraint choice, boolean status)
Description copied from interface:ExitChildListener
It is executed after exiting the right child.- Specified by:
rightChild
in interfaceExitChildListener<T extends Var>
- Parameters:
choice
- primitive constraint used as the base of the choice point.status
- true if the solution was found in the child subtree, false otherwise. exit the current node with false
-
setChildrenListeners
public void setChildrenListeners(ExitChildListener<T> child)
Description copied from interface:ExitChildListener
It adds one child listener.- Specified by:
setChildrenListeners
in interfaceExitChildListener<T extends Var>
- Parameters:
child
- added child listener.
-
setChildrenListeners
public void setChildrenListeners(ExitListener child)
Description copied from interface:ExitListener
It sets one child listener.- Specified by:
setChildrenListeners
in interfaceExitListener
- Parameters:
child
- the only child listener used by this listener.
-
executedAtExit
public void executedAtExit(Store store, int solutionsNo)
Description copied from interface:ExitListener
It is executed right after time out is determined.- Specified by:
executedAtExit
in interfaceExitListener
- Parameters:
store
- store in the context of which the search took place.solutionsNo
- the number of solutions found.
-
prepareTreeHeader
void prepareTreeHeader()
-
prepareVizHeader
void prepareVizHeader()
-
addTracedVar
public void addTracedVar(Var v)
-
minValue
private int minValue(java.util.List<Var> vars)
-
maxValue
private int maxValue(java.util.List<Var> vars)
-
getDateTime
private java.lang.String getDateTime()
-
generateSuccessNode
void generateSuccessNode(int searchNodeId)
-
generateTryNode
void generateTryNode(int searchNodeId, int parentNode, java.lang.String name, int size, int value)
-
generateFailNode
void generateFailNode(int searchNodeId, int parentNode, java.lang.String name, int size, int value)
-
generateTrycNode
void generateTrycNode(int searchNodeId, int parentNode, java.lang.String name, int size, Domain dom)
-
generateFailcNode
void generateFailcNode(int searchNodeId, int parentNode, java.lang.String name, int size, Domain dom)
-
generateTrycNode
void generateTrycNode(int searchNodeId, int parentNode, PrimitiveConstraint c)
-
generateFailcNode
void generateFailcNode(int searchNodeId, int parentNode, PrimitiveConstraint c)
-
generateVisualizationNode
void generateVisualizationNode(int searchNodeId, boolean tryNode)
-
intDomainToString
java.lang.String intDomainToString(IntDomain domain)
-
setDomainToString
java.lang.String setDomainToString(SetDomain domain)
-
-