|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectai.search.SearchEngine
ai.search.SearchEngineForDoubleCostFn<S>
ai.search.uninformed.DepthFirstSearcherForDoubleCostFn<S>
public class DepthFirstSearcherForDoubleCostFn<S extends SearchStateForDoubleCostFn>
This class represents a search engine that generates a search space in
depth-first order from a given initial state. The initial state, the search
limit, and the type of search space must be given to this search engine at
construction time. Note that the test for repeated states that is performed
during a graph search will only be performed on the predecessors of a newly
generated state. The depth limit should be set to a reasonable value using
the functionsetDepthLimit(int)
. The search limit may be increased later
using SearchEngine.setSearchLimit(long)
.
The search must be started using the function doSearch()
. Successors
of the initial state will then be explored in the reverse order of their
depth in the search tree. That is, fringe nodes at a given depth d
are explored before fringe nodes at depth d-1 (or lower). The search
will halt when a goal state has been expanded. The goal state and the path to
it can then be inspected using the appropriate functions described in the
SearchEngineForDoubleCostFn
class.
Thus, a typical invocation of a
DepthFirstSearcherForDoubleCostFn
would look something like
this:
DepthFirstSearcherForDoubleCostFn s = new DepthFirstSearcherForDoubleCostFn( initialState, 1000, GRAPH); s.setDepthLimit(10); s.doSearch(); if (s.foundGoalState()) { ... }
To continue the search call doSearch()
again and the search will be
continued as far as possible. Paths through a goal state will never be
considered.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class ai.search.SearchEngineForDoubleCostFn |
---|
SearchEngineForDoubleCostFn.SearchNodeForDoubleCostFn<S extends SearchStateForDoubleCostFn> |
Nested classes/interfaces inherited from class ai.search.SearchEngine |
---|
SearchEngine.GraphType |
Field Summary | |
---|---|
protected int |
maxDepth
the maximum depth at which nodes are to be explored |
protected java.util.List<SearchEngineForDoubleCostFn.SearchNodeForDoubleCostFn<S>> |
searchStack
the stack for unexplored (open) nodes |
Fields inherited from class ai.search.SearchEngineForDoubleCostFn |
---|
foundGoalNode, initialState |
Fields inherited from class ai.search.SearchEngine |
---|
doInterrupt, doRepeatTest, searchLimit, searchStarted, traceStream, yieldFrequency |
Constructor Summary | |
---|---|
DepthFirstSearcherForDoubleCostFn(S state,
long limit,
SearchEngine.GraphType structure)
This constructor creates a new DepthFirstSearcherForDoubleCostFn for the given initial state, search limit, and type of search space. |
Method Summary | |
---|---|
boolean |
continuable()
This function tests whether the search may be continued. |
void |
doSearch()
This function must be called to start or continue the search. |
long |
getNrOfExploredStates()
This function returns the number of states that have been explored during this search. |
long |
getNrOfGeneratedStates()
This function returns the number of states that have been generated during this search. |
void |
setDepthLimit(int limit)
This function can be used to limit the depth to which this DepthFirstSearcherForDoubleCostFn will search. |
Methods inherited from class ai.search.SearchEngineForDoubleCostFn |
---|
foundGoalState, getGoalState, getInitialState, getSolutionDepth, getSolutionPath, getSolutionPathCost |
Methods inherited from class ai.search.SearchEngine |
---|
clone, equals, getSearchLimit, hashCode, interrupt, printTrace, setSearchLimit, setTraceStream, setYieldFrequency, toString |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.util.List<SearchEngineForDoubleCostFn.SearchNodeForDoubleCostFn<S extends SearchStateForDoubleCostFn>> searchStack
protected int maxDepth
Constructor Detail |
---|
public DepthFirstSearcherForDoubleCostFn(S state, long limit, SearchEngine.GraphType structure)
This constructor creates a new DepthFirstSearcherForDoubleCostFn for the
given initial state, search limit, and type of search space. Note that
the given initial search state must not be null. The search does not
start immediately but waits for the function doSearch()
to be
called.
state
- the initial state from which the search space is generatedlimit
- the initial value for the search limitstructure
- TREE or GRAPH, depending on what is to be be searchedMethod Detail |
---|
public void setDepthLimit(int limit)
This function can be used to limit the depth to which this DepthFirstSearcherForDoubleCostFn will search. By default the search engine will go to virtually any depth.
limit
- the maximal depth at which nodes are exploredpublic void doSearch()
This function must be called to start or continue the search. It will only return when one of the following conditions becomes true:
SearchEngineForDoubleCostFn.foundGoalState()
will return true, the search will be continuable (continuable()
will return true), and SearchEngineForDoubleCostFn.getGoalState()
will return a goal state,
not nullSearchEngineForDoubleCostFn.foundGoalState()
will return false, the search will not be
continuable (continuable()
will return false), and
SearchEngineForDoubleCostFn.getGoalState()
will return null; to make the search continuable
the search limit has to be increased using SearchEngine.setSearchLimit(long)
SearchEngineForDoubleCostFn.foundGoalState()
will return false, the search will not be
continuable (continuable()
will return false), and
SearchEngineForDoubleCostFn.getGoalState()
will return null
doSearch
in class SearchEngine
public boolean continuable()
This function tests whether the search may be continued. Usually this is the case if there are more search states to be explored and the search limit has not yet been exceeded.
continuable
in class SearchEngine
public long getNrOfExploredStates()
This function returns the number of states that have been explored during this search. A state counts as explored when the goal test has been performed on the state and its successors have been generated.
getNrOfExploredStates
in class SearchEngine
public long getNrOfGeneratedStates()
This function returns the number of states that have been generated during this search. Note that these states may not all be different.
getNrOfGeneratedStates
in class SearchEngine
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |