|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcore.Search<T>
basic.IterativeDeepeningAStar<T>
T
- the specific type of all elements in the search domain.public class IterativeDeepeningAStar<T>
The iterative deepening A* algorithm is a heuristic search
able to solve any problem implementing the core.HeuristicProblem interface.
IterativeDeepeningAStar is a subclass of core.Search because it uses
recursion rather then the general search algorithm employed in core.DirectedSearch.
The iterative deepening A* search uses a modified depth limited search to iteratively
explore the search domain.
The modified depth limited search uses the core.HeuristicProblem#g(java.lang.Object) and core.HeuristicProblem#h(java.lang.Object) methods
methods to approximate the overall costs needed to reach a goal
from the initial state for each state.
This approximation for a state can be mathematically described with the following formula:
f(s) = g(s) + h(s)
Where g computes the path costs to reach state s and h estimates the costs needed to reach a goal.
Using this evaluation function the depth limited search is modified
so that only states s
where f(s) <= f-limit
will be expanded.
The first iteration starts with an f-limit
equal to f(problem.initial())
.
For the next iteration the f-limit
will be set to the lowest f
value
seen during the last iteration.
This strategy grants completeness and a worst case time complexity of O(b* ^ n)
and a space complexity
of O(b* * n)
(where b* is the effective branching factor and n the depth of the solution).
This search is able to generate optimal solutions whenever the following constraints hold
for all states s
in the search domain:
h(s) <= h(s') + cost(s,s')
for all successors s'
of state s
.h
is constantly falling.
h(s) <= g(t)
where t
is the nearest goal to state s
s
implies
that each later occurrence of this state has a greater sum of path costs.
Thats why we can discard every state which has already been seen.
As a conclusion you can use the implicit duplicate handling mechanism.
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
HeuristicProblem problem = new MyHeuristicProblem();
//General search domain
Search search = new IterativeDeepeningAStar(problem,true);
//Special search domain
Search search = new IterativeDeepeningAStar(problem);
Field Summary | |
---|---|
protected java.util.Map<T,java.lang.Integer> |
hash
holds the map used for duplicate handling |
protected HeuristicProblem<T> |
problem
holds a reference to the problem to be solved |
Fields inherited from class core.Search |
---|
neededSteps, result |
Constructor Summary | |
---|---|
IterativeDeepeningAStar(HeuristicProblem<T> problem)
Create a new IterativeDeepeningAStar with the given problem. |
|
IterativeDeepeningAStar(HeuristicProblem<T> problem,
boolean noHash)
Create a new IterativeDeepeningAStar with the given problem 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. |
double |
f(T state)
This method estimates the costs to reach a goal state from the initial state over the given state. |
HeuristicProblem<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 f-limited search with increasing f-limits. |
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 HeuristicProblem<T> problem
protected java.util.Map<T,java.lang.Integer> hash
Constructor Detail |
---|
public IterativeDeepeningAStar(HeuristicProblem<T> problem)
problem
- the core.Poblem to be solvedpublic IterativeDeepeningAStar(HeuristicProblem<T> problem, boolean noHash)
problem
- the core.Poblem to be solvednoHash
- 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 final HeuristicProblem<T> getProblem()
public final double f(T state)
state
- to be evaluated
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |