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 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 make
TraceGenerator<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 -
Field Summary
FieldsModifier and TypeFieldDescription(package private) ConsistencyListener[](package private) TraceGenerator<T>.SearchNode(package private) ExitChildListener<T>[](package private) ExitListener[](package private) TransformerHandlerAn xml handler for tree file.(package private) TransformerHandlerAn xml handler for visualization file.(package private) int(package private) Stack<TraceGenerator<T>.SearchNode> (package private) SelectChoicePoint<T> It stores the original select choice point method that is used by this trace wrapper.(package private) intIt specifies information about value being selected by internal select choice point.(package private) TIt stores information about var being selected by internal select choice point.It specifies the list of variables that are being traced.final StringThe file containing information about tree for CPviz format.final StringThe file containing visualisation information.(package private) int -
Constructor Summary
ConstructorsModifierConstructorDescriptionTraceGenerator(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, String treeFilename, 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, String treeFilename, String visFilename) It creates a CPviz trace generator around proper select choice point object.privateTraceGenerator(SelectChoicePoint<T> select, Var[] vars, String treeFilename, String visFilename) It creates a CPviz trace generator around proper select choice point object. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTracedVar(Var v) booleanexecuteAfterConsistency(boolean consistent) It is executed right after consistency of the current search node.voidexecutedAtExit(Store store, int solutionsNo) It is executed right after time out is determined.(package private) voidgenerateFailcNode(int searchNodeId, int parentNode, String name, int size, Domain dom) (package private) voidgenerateFailcNode(int searchNodeId, int parentNode, PrimitiveConstraint c) (package private) voidgenerateFailNode(int searchNodeId, int parentNode, String name, int size, int value) (package private) voidgenerateSuccessNode(int searchNodeId) (package private) voidgenerateTrycNode(int searchNodeId, int parentNode, String name, int size, Domain dom) (package private) voidgenerateTrycNode(int searchNodeId, int parentNode, PrimitiveConstraint c) (package private) voidgenerateTryNode(int searchNodeId, int parentNode, String name, int size, int value) (package private) voidgenerateVisualizationNode(int searchNodeId, boolean tryNode) getChoiceConstraint(int index) It returns the constraint which is the base of the choice point.intIt returns a value which is the base of the next choice point.getChoiceVariable(int index) It returns the variable which is the base on the next choice point.private StringintgetIndex()It returns the current index.It specifies the position of variables as given when variables of this select object were supplied.(package private) StringintDomainToString(IntDomain domain) booleanleftChild(PrimitiveConstraint choice, boolean status) It is executed after exiting the left child.booleanIt is executed after exiting the left child.private intprivate int(package private) void(package private) voidvoidrightChild(PrimitiveConstraint choice, boolean status) It is executed after exiting the right child.voidrightChild(T var, int value, boolean status) It is executed after exiting the right child.voidSetting one child listener.voidsetChildrenListeners(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).voidsetChildrenListeners(ExitChildListener<T> child) It adds one child listener.voidsetChildrenListeners(ExitChildListener<T>[] children) It sets the children listeners for the current listener.voidsetChildrenListeners(ExitListener child) It sets one child listener.voidsetChildrenListeners(ExitListener[] children) It sets the children of this exit listener.(package private) StringsetDomainToString(SetDomain domain) toString()
-
Field Details
-
consistencyListeners
ConsistencyListener[] consistencyListeners -
exitChildListeners
ExitChildListener<T extends Var>[] exitChildListeners -
exitListeners
ExitListener[] exitListeners -
select
SelectChoicePoint<T extends Var> selectIt stores the original select choice point method that is used by this trace wrapper. -
selectedVar
It stores information about var being selected by internal select choice point. -
selectedValue
int selectedValueIt specifies information about value being selected by internal select choice point. -
treeFilename
The file containing information about tree for CPviz format. -
visFilename
The file containing visualisation information. -
hdTree
TransformerHandler hdTreeAn xml handler for tree file. -
hdVis
TransformerHandler hdVisAn xml handler for visualization file. -
searchStack
Stack<TraceGenerator<T extends Var>.SearchNode> searchStack -
currentSearchNode
TraceGenerator<T extends Var>.SearchNode currentSearchNode -
searchNodeId
int searchNodeId -
visualisationNodeId
int visualisationNodeId -
tracedVar
It specifies the list of variables that are being traced. -
varIndex
-
-
Constructor Details
-
TraceGenerator
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, String treeFilename, 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
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, String treeFilename, 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, String treeFilename, 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 Details
-
getChoiceVariable
Description copied from interface:SelectChoicePointIt 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:
getChoiceVariablein 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:SelectChoicePointIt returns a value which is the base of the next choice point. Only if choice is of an getChoiceVariable() = getChoiceValue() type.- Specified by:
getChoiceValuein interfaceSelectChoicePoint<T extends Var>- Returns:
- value used in the choice point (value).
-
getChoiceConstraint
Description copied from interface:SelectChoicePointIt 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:
getChoiceConstraintin 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
Description copied from interface:SelectChoicePointIt specifies the position of variables as given when variables of this select object were supplied.- Specified by:
getVariablesMappingin interfaceSelectChoicePoint<T extends Var>- Returns:
- mapping of variables to the positions in the variables array.
-
getIndex
public int getIndex()Description copied from interface:SelectChoicePointIt 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:
getIndexin interfaceSelectChoicePoint<T extends Var>- Returns:
- internal position of the last variable chosen to be the base of the choice point.
-
toString
-
setChildrenListeners
Description copied from interface:ConsistencyListenerEach of the child listeners will be called and the return code from them will be combined (taken into account) by a parent).- Specified by:
setChildrenListenersin interfaceConsistencyListener- Parameters:
children- the children listeners attached to this listener.
-
setChildrenListeners
Description copied from interface:ConsistencyListenerSetting one child listener.- Specified by:
setChildrenListenersin interfaceConsistencyListener- Parameters:
child- the only child listener added to this consistency listener.
-
executeAfterConsistency
public boolean executeAfterConsistency(boolean consistent) Description copied from interface:ConsistencyListenerIt 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:
executeAfterConsistencyin 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
Description copied from interface:ExitChildListenerIt sets the children listeners for the current listener.- Specified by:
setChildrenListenersin interfaceExitChildListener<T extends Var>- Parameters:
children- array containing children listeners.
-
setChildrenListeners
Description copied from interface:ExitListenerIt sets the children of this exit listener.- Specified by:
setChildrenListenersin interfaceExitListener- Parameters:
children- an array containing the children.
-
leftChild
Description copied from interface:ExitChildListenerIt is executed after exiting the left child.- Specified by:
leftChildin 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
Description copied from interface:ExitChildListenerIt is executed after exiting the left child.- Specified by:
leftChildin 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
Description copied from interface:ExitChildListenerIt is executed after exiting the right child.- Specified by:
rightChildin 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
Description copied from interface:ExitChildListenerIt is executed after exiting the right child.- Specified by:
rightChildin 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
Description copied from interface:ExitChildListenerIt adds one child listener.- Specified by:
setChildrenListenersin interfaceExitChildListener<T extends Var>- Parameters:
child- added child listener.
-
setChildrenListeners
Description copied from interface:ExitListenerIt sets one child listener.- Specified by:
setChildrenListenersin interfaceExitListener- Parameters:
child- the only child listener used by this listener.
-
executedAtExit
Description copied from interface:ExitListenerIt is executed right after time out is determined.- Specified by:
executedAtExitin 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
-
minValue
-
maxValue
-
getDateTime
-
generateSuccessNode
void generateSuccessNode(int searchNodeId) -
generateTryNode
-
generateFailNode
-
generateTrycNode
-
generateFailcNode
-
generateTrycNode
-
generateFailcNode
-
generateVisualizationNode
void generateVisualizationNode(int searchNodeId, boolean tryNode) -
intDomainToString
-
setDomainToString
-