aima.core.search.framework.qsearch.GraphSearchReducedFrontier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aima-core Show documentation
Show all versions of aima-core Show documentation
AIMA-Java Core Algorithms from the book Artificial Intelligence a Modern Approach 3rd Ed.
The newest version!
package aima.core.search.framework.qsearch;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import aima.core.search.framework.Node;
import aima.core.search.framework.NodeExpander;
import aima.core.search.framework.problem.Problem;
/**
* Artificial Intelligence A Modern Approach (3rd Edition): Figure 3.7, page 77.
*
*
*
* function GRAPH-SEARCH(problem) returns a solution, or failure
* initialize the frontier using the initial state of problem
* initialize the explored set to be empty
* loop do
* if the frontier is empty then return failure
* choose a leaf node and remove it from the frontier
* if the node contains a goal state then return the corresponding solution
* add the node to the explored set
* expand the chosen node, adding the resulting nodes to the frontier
* only if not in the frontier or explored set
*
*
* Figure 3.7 An informal description of the general graph-search algorithm.
*
*
* This implementation is based on the template method
* {@link QueueSearch#findNode(Problem, Queue)} of the superclass and provides
* implementations for the needed primitive operations. It implements a special
* version of graph search which keeps the frontier short by focusing on the
* best node for each state only. It should only be used in combination with
* priority queue frontiers. If a node is added to the frontier, this
* implementation checks whether another node for the same state already exists
* and decides whether to replace it or ignore the new node depending on the
* node's costs (comparator of priority queue is used, if available).
*
* @author Ravi Mohan
* @author Ciaran O'Reilly
* @author Ruediger Lunde
*/
public class GraphSearchReducedFrontier extends QueueSearch {
private Set