|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcore.Search<T>
core.DirectedSearch<T>
T
- the specific type of all elements of the search domain.public abstract class DirectedSearch<T>
This subclass of Search is the core implementation of most directed search algorithms
and is able to perform many various directed search strategies
such as depth first, breath first or best first search.
Inherent for all these algorithms is that the search space is explored in a tree based structure.
To run a DirectedSearch there must be an instance of core.Problem given.
(See description for further information.)
To avoid duplicate states during the search a HashSet is used,
which tries to hash all expanded states in order to inhibit further expansion.
In detail there are two important rules for states of type T which allow proper hashing:
(e.hashCode()==t.hashCode()) and (e.equals(t))
implies e==t
DirectedSearch<State> search = new BreadthFirstSearch<State>(problem, true);
empty()
is true terminate the search.current = pop()
get the next node from the queue.isGoal(current)
is true then save the current state
and terminate the search.problem.expand(current)
add(node)
to the queue.
BestFirstSearch
,
BreadthFirstSearch
,
SlowDepthFirstSearch
Field Summary | |
---|---|
protected java.util.Set<T> |
hash
holds the set used for duplicate handling |
protected Problem<T> |
problem
holds the problem to be solved during the search |
Fields inherited from class core.Search |
---|
neededSteps, result |
Constructor Summary | |
---|---|
DirectedSearch(Problem<T> problem)
Creates a new directed search with the given problem. |
|
DirectedSearch(Problem<T> problem,
boolean noHash)
Creates a new directed search with the given problem and a flag indicating whether duplicate handling should be turned off. |
Method Summary | |
---|---|
protected abstract boolean |
add(T state)
This method is the hook for adding new states to the queue during the search. |
int |
branchedNodes()
This method returns the number of expanded nodes during the search. |
protected boolean |
canPrepare()
This method checks if the given problem returns a valid initial state. |
protected abstract void |
clear()
This method is the hook for clearing the queue on preparation of a new search. |
protected abstract boolean |
empty()
This method is the hook for the check if the queue is empty during the search. |
protected void |
finalize()
This method frees the search. |
Problem<T> |
getProblem()
This method returns the problem, with which this search has been created. |
protected abstract T |
pop()
This method is the hook for extracting the first element of the queue during the search. |
protected void |
prepare()
This method clears the queue and the hash used for duplicate handling to prepare them for a new search run. |
protected void |
search()
This method looks for a goal in the search domain, by iteratively expanding the first state of the queue and adding all successor state to the queue. |
Methods inherited from class core.Search |
---|
getResult, initialize, initialized, neededSteps, run, running, stop |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected Problem<T> problem
protected java.util.Set<T> hash
Constructor Detail |
---|
public DirectedSearch(Problem<T> problem) throws java.lang.IllegalArgumentException
problem
- to be solved
java.lang.IllegalArgumentException
- if the given problem is nullpublic DirectedSearch(Problem<T> problem, boolean noHash) throws java.lang.IllegalArgumentException
problem
- to be solvednoHash
- flag indicating that duplicates should not be handled
java.lang.IllegalArgumentException
- if the given problem is nullMethod Detail |
---|
public final int branchedNodes()
public Problem<T> getProblem()
protected final boolean canPrepare()
canPrepare
in class Search<T>
Search.canPrepare()
protected final void finalize() throws java.lang.Throwable
Search
finalize
in class Search<T>
java.lang.Throwable
Search.finalize()
protected final void prepare()
prepare
in class Search<T>
Search.prepare()
protected final void search()
search
in class Search<T>
Search.search()
protected abstract boolean add(T state)
state
- to be added to the queue
protected abstract T pop()
protected abstract void clear()
protected abstract boolean empty()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |