Package org.jacop.search
Class DepthFirstSearch<T extends Var>
java.lang.Object
org.jacop.search.DepthFirstSearch<T>
- Type Parameters:
T- type of variables used in this search.
- All Implemented Interfaces:
Search<T>
- Direct Known Subclasses:
PrioritySearch,PrioritySearch.LinkingSearch
Implements Depth First Search with number of possible plugins (listeners) to
be attached to modify the search.
- Version:
- 4.10
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) booleanIt decides if the found solution is immediately assigned to the store.* If the solution is not assigned immediately after the search is concluded but later then special care may be required.(package private) longIt specifies after how many backtracks the search exits.(package private) booleanIt specifies if the backtrack out is on.(package private) booleanIt specifies if search can exit before the search has finished.It stores searches which will be executed when this one has assign all its variables.It is invoked when consistency function has been executed.(package private) ConstraintIt represents the constraint which enforces that next solution is better than currently best solution.intIt represents the cost value of currently best solution for IntVar cost.doubleIt represents the cost value of currently best solution for FloatVar cost.It represents the cost variable.intIt remembers what child search has been already examined.(package private) static final boolean(package private) intIt stores number of nodes with decisions during search.(package private) longIt specifies after how many decisions the search exits.(package private) booleanIt specifies if the decisions out is on.(package private) intIt represents current depth of store used in search.(package private) intIt stores current depth of the search excluding paths in a search tree.booleanIt specifies if for setVar based search the left branch should impose EinA constraint.It is invoked when returning from left or right child.(package private) ExitListenerIt is executed upon search exit.(package private) SelectChoicePoint<T> It represents the choice point selection heuristic.It specifies the id of the search.It is executed when search is started, before entering the search.If this search is a sub-search then this pointer will point out to the master search (i.e.(package private) intIt stores the maximum depth reached during search.(package private) intIt stores the maximum depth of the search excluding paths.(package private) static AtomicInteger(package private) intIt stores number of nodes visited during search.(package private) longIt specifies after how many nodes the search exits.(package private) booleanIt specifies if the nodes out is on.(package private) intIt stores number of backtracks during search.(package private) boolean(package private) booleanIt decides if information about search is printed.booleanIf it is set to true then the optimizing search will quit the search if this action is indicated by the solution listener.It is executed when a solution is found.It represents store within which a search is performed.(package private) longIt specifies the exact time point after which the timeout will occur (in miliseconds).(package private) booleanIt specifies if the timeout is on.(package private) TimeOutListenerThe object informed about the determination of the timeout.booleanIt specifies that the time-out has occured(package private) longIt specifies the number of seconds after which the search will timeout.(package private) intIt stores number of wrong decisions during search.(package private) longIt specifies after how many wrong decisions the search exits.(package private) booleanIt specifies if the wrong decisions out is on. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChildSearch(Search<? extends Var> child) It adds another child search to this one.booleanIt assigns the last solution.booleanassignSolution(int no) The first solution has index 0.intIt returns number of backtracks performed by the search.It returns the root of the Consistency Listener.intIt returns the value of the cost int variable for the best solution.doubleIt returns the value of the cost float variable for the best solution.It returns the cost variable.intIt returns number of decisions performed by the search.It returns the root of the ExitChildListener.It returns the root of the ExitListener.It returns the root of the InitializationListener.intIt returns the maximum depth reached by a search.intgetNodes()It returns number of search nodes explored by the search.Domain[]It returns the solution (an assignment of values to variables).Domain[]getSolution(int no) It returns the solution specified by the search.It returns the root Solution Listener.It returns the root of the TimeOutListener.T[]It returns the order of variables used by functions returning a solution in terms of the values.intIt returns number of wrong decisions performed by the search.id()It returns the string id of the search.booleanlabel(int firstVariable) This function is called recursively to assign variables one by one.booleanlabeling()It is a labeling function called if the search is a sub-search being called from the parent search.booleanlabeling(Store store, SelectChoicePoint<T> select) It performs search using supplied choice point selection heuristic.booleanlabeling(Store store, SelectChoicePoint<T> select, Var costVar) It performs search using supplied choice point selection heuristic, as well as costVariable as aim at finding an optimal solution.voidIt prints all solutions.voidsetAssignSolution(boolean value) It decides if a solution is assigned to store after search exits.voidsetBacktracksOut(long out) It turns on the backtrack out.voidsetChildSearch(Search<? extends Var>[] child) It specifies the sub-searches for the current search.voidsetConsistencyListener(ConsistencyListener listener) It sets the root of the Consistency Listener.voidsetCostVar(Var cost) It sets the reference to the cost variable.voidsetDecisionsOut(long out) It turns on the decisions out.voidsetExitChildListener(ExitChildListener<T> listener) It sets the root of the ExitChild listener.voidsetExitListener(ExitListener listener) It sets the root of the Exit Listener.voidIt sets the id of the store.voidsetInitializeListener(InitializeListener listener) It sets the root of the InitializeListener.voidsetMasterSearch(Search<? extends Var> master) If the search is called by a master search then the search may need to obtain some information about the master search.voidsetNodesOut(long out) It turns on the nodes out.(package private) voidsetOptimizationForChildSearches(DepthFirstSearch<T> s, Var costVar) voidsetOptimize(boolean value) It sets the optimization flag.voidsetPrintInfo(boolean value) It decides if information about search is printed.voidsetSelectChoicePoint(SelectChoicePoint<T> select) It sets the select choice point object.voidsetSolutionListener(SolutionListener<T> listener) It returns the root of the SolutionListener.voidIt sets the reference to the store in the context of which the search operates.voidsetTimeOut(long out) It turns on the timeout.voidsetTimeOutListener(TimeOutListener listener) It sets the root of the TimeOutListener.voidsetTimeOutMilliseconds(long out) It turns on the timeout.voidsetWrongDecisionsOut(long out) It turns on the wrong decisions out.toString()
-
Field Details
-
debugAll
static final boolean debugAll- See Also:
-
respectSolutionListenerAdvice
public boolean respectSolutionListenerAdviceIf it is set to true then the optimizing search will quit the search if this action is indicated by the solution listener. -
assignSolution
boolean assignSolutionIt decides if the found solution is immediately assigned to the store.* If the solution is not assigned immediately after the search is concluded but later then special care may be required. As soon as search exits all propagations (including the first time consistency execution of the constraints) may be forgotten. Even worse some values of the variables for which the constraint was never aware of (not even at impose time) may appear back in the domain. The best remedy for this problem is to call store.consistency() method once and only once after the model is imposed and before the search is executed and never remove the level at which the store resides after store.consistency() method is executed. -
backtracksOut
long backtracksOutIt specifies after how many backtracks the search exits. -
backtracksOutCheck
boolean backtracksOutCheckIt specifies if the backtrack out is on. -
check
boolean checkIt specifies if search can exit before the search has finished. -
cost
Constraint costIt represents the constraint which enforces that next solution is better than currently best solution. -
costValue
public int costValueIt represents the cost value of currently best solution for IntVar cost. -
costValueFloat
public double costValueFloatIt represents the cost value of currently best solution for FloatVar cost. -
costVariable
It represents the cost variable. -
optimize
boolean optimize -
decisions
int decisionsIt stores number of nodes with decisions during search. -
decisionsOut
long decisionsOutIt specifies after how many decisions the search exits. -
decisionsOutCheck
boolean decisionsOutCheckIt specifies if the decisions out is on. -
depth
int depthIt represents current depth of store used in search. -
depthExcludePaths
int depthExcludePathsIt stores current depth of the search excluding paths in a search tree. -
heuristic
SelectChoicePoint<T extends Var> heuristicIt represents the choice point selection heuristic. -
exitChildListener
It is invoked when returning from left or right child. -
consistencyListener
It is invoked when consistency function has been executed. -
solutionListener
It is executed when a solution is found. -
initializeListener
It is executed when search is started, before entering the search. -
maxDepth
int maxDepthIt stores the maximum depth reached during search. -
maxDepthExcludePaths
int maxDepthExcludePathsIt stores the maximum depth of the search excluding paths. -
nodes
int nodesIt stores number of nodes visited during search. -
nodesOut
long nodesOutIt specifies after how many nodes the search exits. -
nodesOutCheck
boolean nodesOutCheckIt specifies if the nodes out is on. -
numberBacktracks
int numberBacktracksIt stores number of backtracks during search. A backtrack is a search node for which all children has failed. -
printInfo
boolean printInfoIt decides if information about search is printed. -
childSearches
It stores searches which will be executed when this one has assign all its variables. -
masterSearch
If this search is a sub-search then this pointer will point out to the master search (i.e. the search which have invoked this search). -
store
It represents store within which a search is performed. -
timeOutListener
TimeOutListener timeOutListenerThe object informed about the determination of the timeout. -
exitListener
ExitListener exitListenerIt is executed upon search exit. It allows to add learnt constraints. -
timeOut
long timeOutIt specifies the exact time point after which the timeout will occur (in miliseconds). -
timeOutCheck
boolean timeOutCheckIt specifies if the timeout is on. -
timeOutOccured
public boolean timeOutOccuredIt specifies that the time-out has occured -
tOut
long tOutIt specifies the number of seconds after which the search will timeout. -
wrongDecisions
int wrongDecisionsIt stores number of wrong decisions during search. A wrong decision is a leaf of a search which has failed. -
wrongDecisionsOut
long wrongDecisionsOutIt specifies after how many wrong decisions the search exits. -
wrongDecisionsOutCheck
boolean wrongDecisionsOutCheckIt specifies if the wrong decisions out is on. -
no
-
id
It specifies the id of the search. -
einAinleftTree
public boolean einAinleftTreeIt specifies if for setVar based search the left branch should impose EinA constraint. -
currentChildSearch
public int currentChildSearchIt remembers what child search has been already examined.
-
-
Constructor Details
-
DepthFirstSearch
public DepthFirstSearch()It specifies current child search.
-
-
Method Details
-
setID
It sets the id of the store.- Parameters:
name- the id of the store object.
-
id
Description copied from interface:SearchIt returns the string id of the search. -
setChildSearch
Description copied from interface:SearchIt specifies the sub-searches for the current search. In order for the current search to succeed at least one of those must succeed. If there are no sub-searches then the current search succeeds if all variables within select choice point object are assigned and all constraints attached to those variables are satisfied.- Specified by:
setChildSearchin interfaceSearch<T extends Var>- Parameters:
child- the array containing all children searches.
-
addChildSearch
Description copied from interface:SearchIt adds another child search to this one.- Specified by:
addChildSearchin interfaceSearch<T extends Var>- Parameters:
child- the search which is being added as child search.
-
setSelectChoicePoint
Description copied from interface:SearchIt sets the select choice point object.- Specified by:
setSelectChoicePointin interfaceSearch<T extends Var>- Parameters:
select- the choice point heuristic used by search.
-
getBacktracks
public int getBacktracks()It returns number of backtracks performed by the search.- Specified by:
getBacktracksin interfaceSearch<T extends Var>- Returns:
- the number of backtracks.
-
getDecisions
public int getDecisions()It returns number of decisions performed by the search.- Specified by:
getDecisionsin interfaceSearch<T extends Var>- Returns:
- the number of decisions.
-
getMaximumDepth
public int getMaximumDepth()It returns the maximum depth reached by a search.- Specified by:
getMaximumDepthin interfaceSearch<T extends Var>- Returns:
- the maximum depth.
-
getNodes
public int getNodes()It returns number of search nodes explored by the search. -
getWrongDecisions
public int getWrongDecisions()It returns number of wrong decisions performed by the search.- Specified by:
getWrongDecisionsin interfaceSearch<T extends Var>- Returns:
- number of wrong decisions.
-
getSolution
Description copied from interface:SearchIt returns the solution (an assignment of values to variables).- Specified by:
getSolutionin interfaceSearch<T extends Var>- Returns:
- an array constituting the assignments.
-
getSolution
Description copied from interface:SearchIt returns the solution specified by the search. The first solution has an index 1.- Specified by:
getSolutionin interfaceSearch<T extends Var>- Parameters:
no- the solution we are interested in.- Returns:
- an array constituting the assignments.
-
getVariables
Description copied from interface:SearchIt returns the order of variables used by functions returning a solution in terms of the values.- Specified by:
getVariablesin interfaceSearch<T extends Var>- Returns:
- an array of variables as used by functions getSolution.
-
getSolutionListener
Description copied from interface:SearchIt returns the root Solution Listener.- Specified by:
getSolutionListenerin interfaceSearch<T extends Var>- Returns:
- the root Solution Listener.
-
label
public boolean label(int firstVariable) This function is called recursively to assign variables one by one. -
setStore
Description copied from interface:SearchIt sets the reference to the store in the context of which the search operates. -
setCostVar
Description copied from interface:SearchIt sets the reference to the cost variable. It does not automatically mean that the search optimizes.- Specified by:
setCostVarin interfaceSearch<T extends Var>- Parameters:
cost- variable used as a cost metric.
-
labeling
public boolean labeling()It is a labeling function called if the search is a sub-search being called from the parent search. It never assigns a solution as it will be immediately retracted by search calling this one. -
labeling
Description copied from interface:SearchIt performs search using supplied choice point selection heuristic. -
setOptimizationForChildSearches
-
labeling
Description copied from interface:SearchIt performs search using supplied choice point selection heuristic, as well as costVariable as aim at finding an optimal solution. -
setAssignSolution
public void setAssignSolution(boolean value) It decides if a solution is assigned to store after search exits.- Specified by:
setAssignSolutionin interfaceSearch<T extends Var>- Parameters:
value- defines if solution is assigned.
-
setBacktracksOut
public void setBacktracksOut(long out) It turns on the backtrack out.- Specified by:
setBacktracksOutin interfaceSearch<T extends Var>- Parameters:
out- defines how many backtracks are performed before the search exits.
-
setDecisionsOut
public void setDecisionsOut(long out) It turns on the decisions out.- Specified by:
setDecisionsOutin interfaceSearch<T extends Var>- Parameters:
out- defines how many decisions are made before the search exits.
-
setNodesOut
public void setNodesOut(long out) It turns on the nodes out.- Specified by:
setNodesOutin interfaceSearch<T extends Var>- Parameters:
out- defines how many nodes are visited before the search exits.
-
setPrintInfo
public void setPrintInfo(boolean value) It decides if information about search is printed.- Specified by:
setPrintInfoin interfaceSearch<T extends Var>- Parameters:
value- defines if info is printed to standard output.
-
setTimeOut
public void setTimeOut(long out) It turns on the timeout.- Specified by:
setTimeOutin interfaceSearch<T extends Var>- Parameters:
out- defines how many seconds before the search exits.
-
setTimeOutMilliseconds
public void setTimeOutMilliseconds(long out) Description copied from interface:SearchIt turns on the timeout.- Specified by:
setTimeOutMillisecondsin interfaceSearch<T extends Var>- Parameters:
out- defines how many miliseconds before the search exits.
-
setWrongDecisionsOut
public void setWrongDecisionsOut(long out) It turns on the wrong decisions out.- Specified by:
setWrongDecisionsOutin interfaceSearch<T extends Var>- Parameters:
out- defines how many wrong decisions are made before the search exits.
-
setMasterSearch
Description copied from interface:SearchIf the search is called by a master search then the search may need to obtain some information about the master search. For example, the textual description of the solution.- Specified by:
setMasterSearchin interfaceSearch<T extends Var>- Parameters:
master- master search which will be/is calling that slave search.
-
toString
-
toStringFull
-
assignSolution
public boolean assignSolution()Description copied from interface:SearchIt assigns the last solution.- Specified by:
assignSolutionin interfaceSearch<T extends Var>- Returns:
- true if the store is consistent after imposing the last solution.
-
assignSolution
public boolean assignSolution(int no) Description copied from interface:SearchThe first solution has index 0.- Specified by:
assignSolutionin interfaceSearch<T extends Var>- Parameters:
no- the solution number which we want to enforce in the store.- Returns:
- true if the store is consistent after imposing the solution.
-
getConsistencyListener
Description copied from interface:SearchIt returns the root of the Consistency Listener.- Specified by:
getConsistencyListenerin interfaceSearch<T extends Var>- Returns:
- the root Consistency Listener.
-
getExitChildListener
Description copied from interface:SearchIt returns the root of the ExitChildListener.- Specified by:
getExitChildListenerin interfaceSearch<T extends Var>- Returns:
- the root of ExitChildListener.
-
getExitListener
Description copied from interface:SearchIt returns the root of the ExitListener.- Specified by:
getExitListenerin interfaceSearch<T extends Var>- Returns:
- the root of ExitListener.
-
getTimeOutListener
Description copied from interface:SearchIt returns the root of the TimeOutListener.- Specified by:
getTimeOutListenerin interfaceSearch<T extends Var>- Returns:
- the root of the TimeOutListener.
-
setSolutionListener
Description copied from interface:SearchIt returns the root of the SolutionListener.- Specified by:
setSolutionListenerin interfaceSearch<T extends Var>- Parameters:
listener- the root of the SolutionListener.
-
setConsistencyListener
Description copied from interface:SearchIt sets the root of the Consistency Listener.- Specified by:
setConsistencyListenerin interfaceSearch<T extends Var>- Parameters:
listener- the new root.
-
setExitChildListener
Description copied from interface:SearchIt sets the root of the ExitChild listener.- Specified by:
setExitChildListenerin interfaceSearch<T extends Var>- Parameters:
listener- the new root.
-
setExitListener
Description copied from interface:SearchIt sets the root of the Exit Listener.- Specified by:
setExitListenerin interfaceSearch<T extends Var>- Parameters:
listener- the new root.
-
setTimeOutListener
Description copied from interface:SearchIt sets the root of the TimeOutListener.- Specified by:
setTimeOutListenerin interfaceSearch<T extends Var>- Parameters:
listener- the new root.
-
getInitializeListener
Description copied from interface:SearchIt returns the root of the InitializationListener.- Specified by:
getInitializeListenerin interfaceSearch<T extends Var>- Returns:
- the root of the InitializeListener.
-
setInitializeListener
Description copied from interface:SearchIt sets the root of the InitializeListener.- Specified by:
setInitializeListenerin interfaceSearch<T extends Var>- Parameters:
listener- the new root.
-
printAllSolutions
public void printAllSolutions()Description copied from interface:SearchIt prints all solutions.- Specified by:
printAllSolutionsin interfaceSearch<T extends Var>
-
getCostVariable
Description copied from interface:SearchIt returns the cost variable.- Specified by:
getCostVariablein interfaceSearch<T extends Var>- Returns:
- cost variable.
-
getCostValue
public int getCostValue()Description copied from interface:SearchIt returns the value of the cost int variable for the best solution.- Specified by:
getCostValuein interfaceSearch<T extends Var>- Returns:
- the cost value.
-
getCostValueFloat
public double getCostValueFloat()Description copied from interface:SearchIt returns the value of the cost float variable for the best solution.- Specified by:
getCostValueFloatin interfaceSearch<T extends Var>- Returns:
- the cost value.
-
setOptimize
public void setOptimize(boolean value) Description copied from interface:SearchIt sets the optimization flag.- Specified by:
setOptimizein interfaceSearch<T extends Var>- Parameters:
value- true if the search should optimize, false otherwise.
-