public class DFSearch extends Object
Constructor and Description |
---|
DFSearch(StateManager sm,
Supplier<Procedure[]> branching)
Creates a Depth First Search object with a given branching
that defines the search tree dynamically.
|
Modifier and Type | Method and Description |
---|---|
void |
onFailure(Procedure listener)
Adds a listener that is called whenever a failure occurs
and the search backtracks.
|
void |
onSolution(Procedure listener)
Adds a listener that is called on each solution.
|
SearchStatistics |
optimize(Objective obj)
Effectively start a branch and bound
depth first search with a given objective.
|
SearchStatistics |
optimize(Objective obj,
Predicate<SearchStatistics> limit)
Effectively start a branch and bound
depth first search with a given objective
and with a given predicate called at each node
to stop the search when it becomes true.
|
SearchStatistics |
optimizeSubjectTo(Objective obj,
Predicate<SearchStatistics> limit,
Procedure subjectTo)
Executes a closure prior to effectively
starting a branch and bound depth first search
with a given objective to optimize
and a given predicate called at each node
to stop the search when it becomes true.
|
SearchStatistics |
solve()
Effectively start a depth first search
looking for every solution.
|
SearchStatistics |
solve(Predicate<SearchStatistics> limit)
Effectively start a depth first search
with a given predicate called at each node
to stop the search when it becomes true.
|
SearchStatistics |
solveSubjectTo(Predicate<SearchStatistics> limit,
Procedure subjectTo)
Executes a closure prior to effectively
starting a depth first search
with a given predicate called at each node
to stop the search when it becomes true.
|
public DFSearch(StateManager sm, Supplier<Procedure[]> branching)
sm
- the state manager that will be saved and restored
at each node of the search treebranching
- a generator of closures in charge of defining the ordered
children nodes at each node of the depth-first-search tree.
When it returns an empty array, a solution is found.
A backtrack occurs when a InconsistencyException
is thrown.public void onSolution(Procedure listener)
listener
- the closure to be called whenever a solution is foundpublic void onFailure(Procedure listener)
InconsistencyException
is thrown
when executing the closure generated by the branching.listener
- the closure to be called whenever a failure occurs and
the search need to backtrackpublic SearchStatistics solve()
public SearchStatistics solve(Predicate<SearchStatistics> limit)
limit
- a predicate called at each node
that stops the search when it becomes truepublic SearchStatistics solveSubjectTo(Predicate<SearchStatistics> limit, Procedure subjectTo)
InconsistencyException
that may
be throw when executing the closure is also catched.limit
- a predicate called at each node
that stops the search when it becomes truesubjectTo
- the closure to execute prior to the search startspublic SearchStatistics optimize(Objective obj)
obj
- the objective to optimize that is tightened each
time a new solution is foundpublic SearchStatistics optimize(Objective obj, Predicate<SearchStatistics> limit)
obj
- the objective to optimize that is tightened each
time a new solution is foundlimit
- a predicate called at each node
that stops the search when it becomes truepublic SearchStatistics optimizeSubjectTo(Objective obj, Predicate<SearchStatistics> limit, Procedure subjectTo)
InconsistencyException
that may
be throw when executing the closure is also catched.obj
- the objective to optimize that is tightened each
time a new solution is foundlimit
- a predicate called at each node
that stops the search when it becomes truesubjectTo
- the closure to execute prior to the search startsCopyright © 2018 Laurent Michel, Pierre Schaus, Pascal Van Hentenryck. All rights reserved.