basic
Class AStarSearch<T>

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

public class AStarSearch<T>
extends BestFirstSearch<T>

The A* search algorithm is a heuristic search able to solve any problem implementing the core.HeuristicProblem interface.

This search tries to expand those states at first which are cheap to reach from the initial state and are most promising to reach a goal state. To do this the core.HeuristicProblem#g(java.lang.Object) and core.HeuristicProblem#h(java.lang.Object) methods are called for each state in order to approximate the overall costs needed to reach a goal from the initial 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.
This strategy grants completeness and a worst case time and 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 with enabled hashing and an updating queue. (These are not the default values.)
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.
To cope with this situation you can select one of the following implementation patterns:

Author:
eden06

Field Summary
 
Fields inherited from class core.BestFirstSearch
heuristicProblem, queue
 
Fields inherited from class core.DirectedSearch
hash, problem
 
Fields inherited from class core.Search
neededSteps, result
 
Constructor Summary
AStarSearch(HeuristicProblem<T> problem)
          Creates a new AStarSearch with the given problem.
AStarSearch(HeuristicProblem<T> problem, boolean update)
          Create a new AStarSearch with the given problem and a queue corresponding to the given update flag.
AStarSearch(HeuristicProblem<T> problem, boolean noHash, boolean update)
          Create a new AStarSearch with the given problem, disabled hashing if the noHash flag is true and a queue corresponding to the given update flag.
 
Method Summary
 java.lang.Double f(T state)
          This method estimates the costs to reach a goal state from the initial state over the given state.
 
Methods inherited from class core.BestFirstSearch
add, clear, empty, getProblem, pop
 
Methods inherited from class core.DirectedSearch
branchedNodes, canPrepare, finalize, prepare, search
 
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
 

Constructor Detail

AStarSearch

public AStarSearch(HeuristicProblem<T> problem)
Creates a new AStarSearch with the given problem. The search will use implicit duplicate handling and no updating queue.

Parameters:
problem - the HeuristicProblem to be solved

AStarSearch

public AStarSearch(HeuristicProblem<T> problem,
                   boolean update)
Create a new AStarSearch with the given problem and a queue corresponding to the given update flag. The search will also use implicit duplicate handling.

Parameters:
problem - the HeuristicProblem to be solved
update - flag indicating whether the states in the queue should be updated or not.

AStarSearch

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

Parameters:
problem - the HeuristicProblem to be solved
noHash - flag indicating that duplicates should not be handled
update - flag indicating whether the states in the queue should be updated or not.
Method Detail

f

public java.lang.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.

Specified by:
f in class BestFirstSearch<T>
Parameters:
state - to be evaluated
Returns:
the function value
See Also:
BestFirstSearch.f(java.lang.Object)