basic
Class IterativeDeepeningAStar<T>

java.lang.Object
  extended by core.Search<T>
      extended by basic.IterativeDeepeningAStar<T>
Type Parameters:
T - the specific type of all elements in the search domain.
All Implemented Interfaces:
java.lang.Runnable

public class IterativeDeepeningAStar<T>
extends Search<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:


In general this search should be used without implicit duplicate handling. (These is not the default.)
Because in all cases where two or more paths from the initial state to an other state exists you have to take care of updated states.
If your search domain has constant path costs between each state and its successors, you do not have to care about duplicates. Because the first occurrence of a state 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: Note: Due to its implementation problems, it is not possible to use user defined hashing. The simple problem is that before each run the hash must be cleared, but there is no method which can be called for that purpose. (The assumption that the basic.HeuristicProblem#initial() method is called before each iteration, will not hold.)
Example:
HeuristicProblem problem = new MyHeuristicProblem();
//General search domain Search search = new IterativeDeepeningAStar(problem,true); //Special search domain Search search = new IterativeDeepeningAStar(problem);

Author:
eden06

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

problem

protected HeuristicProblem<T> problem
holds a reference to the problem to be solved


hash

protected java.util.Map<T,java.lang.Integer> hash
holds the map used for duplicate handling

Constructor Detail

IterativeDeepeningAStar

public IterativeDeepeningAStar(HeuristicProblem<T> problem)
Create a new IterativeDeepeningAStar with the given problem. This search will use implicit duplicate handling.

Parameters:
problem - the core.Poblem to be solved

IterativeDeepeningAStar

public IterativeDeepeningAStar(HeuristicProblem<T> problem,
                               boolean noHash)
Create a new IterativeDeepeningAStar with the given problem and disabled hashing if the noHash flag is true.

Parameters:
problem - the core.Poblem to be solved
noHash - flag indicating that duplicates should not be handled
Method Detail

canPrepare

protected boolean canPrepare()
This method checks if the given problem returns a valid initial state.

Specified by:
canPrepare in class Search<T>
Returns:
true if the search can be prepared
See Also:
Search.canPrepare()

prepare

protected void prepare()
This method does nothing.

Specified by:
prepare in class Search<T>
See Also:
Search.prepare()

search

protected final void search()
This method looks for a goal by iteratively calling a recursive f-limited search with increasing f-limits. It terminates when a goal has been found or the search domain has been fully explored.

Specified by:
search in class Search<T>
See Also:
Search.search()

getProblem

public final HeuristicProblem<T> getProblem()
This method returns the problem, with which this search has been created.

Returns:
the problem to be solved

f

public final double f(T state)
This method estimates the costs to reach a goal state from the initial state over the given state. Note: This method uses the function core.HeuristicProblem#g(java.lang.Object) and core.HeuristicProblem#h(java.lang.Object)to compute this estimation, and nothing else.

Parameters:
state - to be evaluated
Returns:
the function value