|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectai.search.SearchEngine
ai.search.SearchEngineForIntCostFn<S>
ai.search.informed.BestFirstSearcherForIntCostFn<S>
ai.search.informed.RandomizedAStarSearcherForIntCostFn<S>
public class RandomizedAStarSearcherForIntCostFn<S extends SearchStateForIntCostFn>
This class represents a search engine that generates a search space from a given initial state and guided by a heuristic function. The initial state and the heuristic function must be given to this search engine at construction time.
Now the search can be started using the function doSearch()
.
Successors of the initial state will then be explored in the order determined
by the heuristic function plus some random element. The essential strategy is
to expand those nodes first for which the current path cost plus the
estimated distance to the closest goal state is smallest, i.e. nodes which
appear to be on a shortest path to a goal state. 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
SearchEngineForIntCostFn
class.
Thus, a typical invocation would look something like this:
SearchEngineForIntCostFn s = new RandomizedAStarSearcherForIntCostFn( initialState, heuristic, 1000, GRAPH); s.doSearch(); if (s.foundGoalState()) { ... }
To continue the search call doSearch()
again and the search will be
continued as far as possible. If the test for repeated states is switched on,
continuing the search will not result in the discovery of alternative paths
to an already discovered goal state, but in the discovery of alternative goal
states, if any. Furthermore, paths through a goal state will never be
considered.
Nested Class Summary | |
---|---|
static class |
RandomizedAStarSearcherForIntCostFn.RandomizationType
determines the type of randomization performed here; see setRandomizationType(ai.search.informed.RandomizedAStarSearcherForIntCostFn.RandomizationType) |
Nested classes/interfaces inherited from class ai.search.SearchEngineForIntCostFn |
---|
SearchEngineForIntCostFn.SearchNodeForIntCostFn<S extends SearchStateForIntCostFn> |
Nested classes/interfaces inherited from class ai.search.SearchEngine |
---|
SearchEngine.GraphType |
Field Summary | |
---|---|
protected java.util.Map<S,SearchEngineForIntCostFn.SearchNodeForIntCostFn<S>> |
foundStates
the table of all states generated this far for the test for repeated states |
protected inf.util.RandomAccessIntPriorityQueue<SearchEngineForIntCostFn.SearchNodeForIntCostFn<S>> |
searchQueue
the search queue for unexplored (open) nodes |
Fields inherited from class ai.search.informed.BestFirstSearcherForIntCostFn |
---|
dfTendency, h, hweight |
Fields inherited from class ai.search.SearchEngineForIntCostFn |
---|
foundGoalNode, initialState |
Fields inherited from class ai.search.SearchEngine |
---|
doInterrupt, doRepeatTest, searchLimit, searchStarted, traceStream, yieldFrequency |
Constructor Summary | |
---|---|
RandomizedAStarSearcherForIntCostFn(S state,
IntCostHeuristic<S> heuristic,
long limit,
SearchEngine.GraphType structure)
This constructor creates a new RandomizedAStarSearcherForIntCostFn for the given initial state, heuristic, 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 |
setRandomDistribution(inf.util.BiasedRandom bRandom)
This function can be used to set the random distribution with which elements of the search queue are selected for expansion. |
void |
setRandomizationType(RandomizedAStarSearcherForIntCostFn.RandomizationType rt)
This function can be used set the type of randomization performed by this search engine. |
Methods inherited from class ai.search.informed.BestFirstSearcherForIntCostFn |
---|
setBreadthFirstTendency, setDepthFirstTendency, setHeuristicWeight |
Methods inherited from class ai.search.SearchEngineForIntCostFn |
---|
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 inf.util.RandomAccessIntPriorityQueue<SearchEngineForIntCostFn.SearchNodeForIntCostFn<S extends SearchStateForIntCostFn>> searchQueue
protected java.util.Map<S extends SearchStateForIntCostFn,SearchEngineForIntCostFn.SearchNodeForIntCostFn<S extends SearchStateForIntCostFn>> foundStates
Constructor Detail |
---|
public RandomizedAStarSearcherForIntCostFn(S state, IntCostHeuristic<S> heuristic, long limit, SearchEngine.GraphType structure)
This constructor creates a new RandomizedAStarSearcherForIntCostFn for
the given initial state, heuristic, search limit, and type of search
space. 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 generatedheuristic
- the heuristic function that guides the searchlimit
- the initial value for the search limitstructure
- TREE or GRAPH, depending on what is to be be searchedMethod Detail |
---|
public 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:
SearchEngineForIntCostFn.foundGoalState()
will return true, the search will be continuable (continuable()
usually will return true), and SearchEngineForIntCostFn.getGoalState()
will return a goal
state, not nullSearchEngineForIntCostFn.foundGoalState()
will return false, the search will not be
continuable (continuable()
will return false), and
SearchEngineForIntCostFn.getGoalState()
will return null; to make the search continuable
the search limit has to be increased using SearchEngine.setSearchLimit(long)
SearchEngineForIntCostFn.foundGoalState()
will return false, the search will not be
continuable (continuable()
will return false), and
SearchEngineForIntCostFn.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
public void setRandomizationType(RandomizedAStarSearcherForIntCostFn.RandomizationType rt)
This function can be used set the type of randomization performed by this search engine. The values have the following effects:
rt
- the type of randomization to be performed during the searchpublic void setRandomDistribution(inf.util.BiasedRandom bRandom)
This function can be used to set the random distribution with which elements of the search queue are selected for expansion. The default value is BiasedRandom.POLY8_0.
bRandom
- the source of biased randomness
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |