|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcore.Search<T>
core.DirectedSearch<T>
core.BestFirstSearch<T>
T
- the specific type of all elements of the search domain.public abstract class BestFirstSearch<T>
This subclass of DirectedSearch is the abstraction of all best first search algorithms
like greedy search or A* search.
The basic idea behind this search algorithm is, to expand the promising states at first.
To estimate how promising a state is a specific evaluation function f
is used.
Each subclass has a different implementation for this function,
but all use the core.HeuristicProblem interface.
(For details on the evaluation function lock in to the concrete subclasses of BestFirstSearch.)
This search algorithm has two modes for evaluation of the states in the search space.
The first mode evaluates each state when the state is enqueued. (This is the default behavior.)
The second mode evaluates each state when ever a state is popped from the queue.
You can create a best first search with this behavior with the following code:
BestFirstSearch search = new MyBestFirstSearch(problem, true);
So what is the different between these two modes and when should which be used?
The first mode is only applicable if there are no two paths from the initial state to a state b
,
so that f(b)
would evaluate to two different values. For examples look into the documentations of the subclasses.
This simple constraint allows the search to use a java.util.PriorityQueue which grants high performance.
The second mode is applicable in all cases (also in cases where the evaluation of a state my change over time).
But this generality costs a lot of performance during the search,
because we have to use the util.SortedQueue instead.
f
according to the following rules:T
(but not for null
).a
is better then state b
,
f(a)
must be smaller then f(b)
.
GreedySearch
,
UniformCostSearch
,
AStarSearch
Field Summary | |
---|---|
protected HeuristicProblem<T> |
heuristicProblem
holds a reference to the problem to be solved of the actual type |
protected java.util.Queue<T> |
queue
holds the instance of the queue used during the search. |
Fields inherited from class core.DirectedSearch |
---|
hash, problem |
Fields inherited from class core.Search |
---|
neededSteps, result |
Constructor Summary | |
---|---|
BestFirstSearch(HeuristicProblem<T> problem)
This method creates a new BestFirstSearch. |
|
BestFirstSearch(HeuristicProblem<T> problem,
boolean update)
This method creates a new BestFirstSearch. |
|
BestFirstSearch(HeuristicProblem<T> problem,
boolean noHash,
boolean update)
This method creates a new BestFirstSearch. |
Method Summary | |
---|---|
protected boolean |
add(T state)
This method adds a new state to the queue. |
protected void |
clear()
This method removes all elements from the queue. |
protected boolean |
empty()
This method tells whether the queue is empty or not. |
abstract java.lang.Double |
f(T state)
This method is the hook for evaluating states during insertion into the queue. |
HeuristicProblem<T> |
getProblem()
This method returns the problem, with which this search has been created. |
protected T |
pop()
This method returns the best state according to the function value. |
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 |
Field Detail |
---|
protected HeuristicProblem<T> heuristicProblem
protected java.util.Queue<T> queue
Constructor Detail |
---|
public BestFirstSearch(HeuristicProblem<T> problem)
problem
- the HeuristicProblem to be solvedpublic BestFirstSearch(HeuristicProblem<T> problem, boolean update)
problem
- the HeuristicProblem to be solvedupdate
- flag indicating whether the states in the queue should be updated or not.public BestFirstSearch(HeuristicProblem<T> problem, boolean noHash, boolean update)
HeuristicProblem problem;
Search s1,s2,s3,s4;
s1 = new BestFirstSearch(problem,false,false);
s2 = new BestFirstSearch(problem,true ,false);
s3 = new BestFirstSearch(problem,false,true );
s4 = new BestFirstSearch(problem,true ,true );
s1 will be a search with duplicate handling and a queue without updates.
problem
- the HeuristicProblem to be solvednoHash
- flag indicating that duplicates should not be handledupdate
- flag indicating whether the states in the queue should be updated or not.Method Detail |
---|
public HeuristicProblem<T> getProblem()
DirectedSearch
getProblem
in class DirectedSearch<T>
DirectedSearch.getProblem()
protected boolean add(T state)
add
in class DirectedSearch<T>
state
- to be added to the queue
DirectedSearch.add(java.lang.Object)
protected void clear()
clear
in class DirectedSearch<T>
DirectedSearch.clear()
protected boolean empty()
empty
in class DirectedSearch<T>
DirectedSearch.empty()
protected T pop()
pop()
returned a state a
then there is no state b
in the queue with f(b)<f(a)
pop
in class DirectedSearch<T>
DirectedSearch.pop()
public abstract java.lang.Double f(T state)
a
is better than state b
then f(a)
should be smaller f(b)
.
state
- to be evaluated
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |