|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcore.Search<T>
basic.IterativeDeepeningSearch<T>
T
- the specific type of all elements in the search domain.public class IterativeDeepeningSearch<T>
The iterative deepening search algorithm is a blind search
able to solve any problem implementing the core.TreeProblem interface.
IterativeDeepeningSearch is a subclass of core.Search because it uses
recursion rather then the general search algorithm employed in core.DirectedSearch.
The iterative deepening search starts a depth limited search with a depth limit of zero
and increases the depth limit slowly until a goal has been found
or the maximum depth is reached.
This strategy grants completeness, a time complexity of O(b^n)
and
a space complexity of O(b*n)
(where b is the branching factor and n is the depth of the solution).
Further more the algorithm can find an optimal solution only
if the path costs between two states are constant or increase by a function of the depth.
In fact iterative deepening search is the best trade of between breadth first
and depth limited search for medium and large search domains.
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
class MyTreeProblem<T> extends TreeProblem<T>{
private Set<Integer> visited=new HashSet<Integer>();
public List expand(T state){
List result = new LinkedList();
for (T newState : super.expand(state) ){
if ( visited.add( newState.hashCode() ) ){
result.add(newState);
}
}
return result;
}
}
// ...
TreeProblem problem = new MyTreeProblem();
//Turn of the implicit duplicate handling mechanism
Search search = IterativeDeepeningSearch(problem, 1000, false);
Field Summary | |
---|---|
protected java.util.Map<T,java.lang.Integer> |
hash
holds the map used for duplicate handling |
protected int |
maximumDepth
holds the maximal number of iterations allowed |
protected TreeProblem<T> |
problem
holds a reference to the problem to be solved |
Fields inherited from class core.Search |
---|
neededSteps, result |
Constructor Summary | |
---|---|
IterativeDeepeningSearch(TreeProblem<T> problem)
Create a new IterativeDeepeningSearch with the given problem. |
|
IterativeDeepeningSearch(TreeProblem<T> problem,
int maximumDepth)
Create a new IterativeDeepeningSearch with the given problem, which needs at most the given iterations. |
|
IterativeDeepeningSearch(TreeProblem<T> problem,
int maximumDepth,
boolean noHash)
Create a new IterativeDeepeningSearch with the given problem, which needs at most the given iterations and disabled hashing if the noHash flag is true. |
Method Summary | |
---|---|
protected boolean |
canPrepare()
This method checks if the given problem returns a valid initial state. |
int |
getMaximumDepth()
Returns the maximal depth to which the search tree will be explored. |
TreeProblem<T> |
getProblem()
This method returns the problem, with which this search has been created. |
protected void |
prepare()
This method does nothing. |
protected void |
search()
This method looks for a goal by iteratively calling a recursive depth limited search with increasing depth limits. |
void |
setMaximumDepth(int maximumDepth)
Changes the maximal number of iterations to the given value. |
Methods inherited from class core.Search |
---|
finalize, 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 TreeProblem<T> problem
protected int maximumDepth
protected java.util.Map<T,java.lang.Integer> hash
Constructor Detail |
---|
public IterativeDeepeningSearch(TreeProblem<T> problem)
problem
- the core.Poblem to be solvedpublic IterativeDeepeningSearch(TreeProblem<T> problem, int maximumDepth)
problem
- the core.Poblem to be solvedmaximumDepth
- the maximum exploration depth for the overall searchpublic IterativeDeepeningSearch(TreeProblem<T> problem, int maximumDepth, boolean noHash)
problem
- the core.Poblem to be solvedmaximumDepth
- the maximum exploration depth for the overall searchnoHash
- flag indicating that duplicates should not be handledMethod Detail |
---|
protected boolean canPrepare()
canPrepare
in class Search<T>
Search.canPrepare()
protected void prepare()
prepare
in class Search<T>
Search.prepare()
protected final void search()
search
in class Search<T>
Search.search()
public TreeProblem<T> getProblem()
public int getMaximumDepth()
public void setMaximumDepth(int maximumDepth)
maximumDepth
- the new maximum number of iterations
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |