basic
Class UniformCostSearch<T>

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

public class UniformCostSearch<T>
extends BestFirstSearch<T>

The uniform cost search algorithm is a blind search able to solve any problem implementing the core.HeuristicProblem interface.

The uniform cost search tries to expand those states at first which are cheap to reach from the initial state. This strategy grants completeness and a time and space complexity of O(b^n) (where b is the branching factor and n the depth of the solution).
In fact the solution found is optimal only if the following constraint holds:
For all states a in the search domain and all s in heuristicProblem.expand(a) the sum of the path costs of s is greater or equal to the sum of the path costs of a (or short where heuristicProblem.g(s) >= heuristicProblem.g(a)).

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
UniformCostSearch(HeuristicProblem<T> problem)
          This method creates a new UniformCostSearch.
UniformCostSearch(HeuristicProblem<T> problem, boolean update)
          This method creates a new UniformCostSearch.
UniformCostSearch(HeuristicProblem<T> problem, boolean noHash, boolean update)
          This method creates a new UniformCostSearch.
 
Method Summary
 java.lang.Double f(T state)
          This method evaluates a state according to the sum of the path costs from the initial 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

UniformCostSearch

public UniformCostSearch(HeuristicProblem<T> problem)
This method creates a new UniformCostSearch. All search parameters will be set to the default values.

Parameters:
problem - the HeuristicProblem to be solved

UniformCostSearch

public UniformCostSearch(HeuristicProblem<T> problem,
                         boolean update)
This method creates a new UniformCostSearch. According to the given update flag the search will use either a queue which is able to update the ordering or not.
Note: The performance is significantly improved, if the queue must not update its elements.

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

UniformCostSearch

public UniformCostSearch(HeuristicProblem<T> problem,
                         boolean noHash,
                         boolean update)
This method creates a new UniformCostSearch. According to the given flags the search will turn off the internal duplicate handling mechanism and uses a queue which updates its elements or not.

 HeuristicProblem problem;
 Search s1,s2,s3,s4;
 s1 = new UniformCostSearch(problem,false,false); 
 s2 = new UniformCostSearch(problem,true ,false);
 s3 = new UniformCostSearch(problem,false,true );
 s4 = new UniformCostSearch(problem,true ,true );
 
s1 will be a search with duplicate handling and a queue without updates.
s2 will be a search without duplicate handling and a queue without updates.
s3 will be a search with duplicate handling and a queue which updates its elements.
s4 will be a search without duplicate handling and a queue which updates its elements.

Note: The performance is significantly improved, if the queue must not update its elements.

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 evaluates a state according to the sum of the path costs from the initial state. Note: This method uses the function core.HeuristicProblem#g(java.lang.Object) to compute the sum of the path costs, 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)