001 package aima.search.framework; 002 003 /** 004 * Artificial Intelligence A Modern Approach (2nd Edition): Figure 3.7, page 70. 005 * <code> 006 * function TREE-SEARCH(problem, strategy) returns a solution, or failure 007 * initialize the search tree using the initial state of problem 008 * loop do 009 * if there are no candidates for expansion then return failure 010 * choose a leaf node for expansion according to strategy 011 * if the node contains a goal state then return the corresponding solution 012 * else expand the node and add the resulting nodes to the search tree. 013 * </code> 014 * Figure 3.7 An informal description of the general tree-search algorithm. 015 * 016 * 017 * Artificial Intelligence A Modern Approach (2nd Edition): Figure 3.9, page 72. 018 * <code> 019 * function TREE-SEARCH(problem, fringe) returns a solution, or failure 020 * 021 * fringe <- INSERT(MAKE-NODE(INITIAL-STATE[problem]), fringe) 022 * loop do 023 * if EMPTY?(fringe) then return failure 024 * node <- REMOVE-FIRST(fringe) 025 * if GOAL-TEST[problem] applied to STATE[node] succeeds 026 * the return SOLUTION(node) 027 * fringe <- INSERT-ALL(EXPAND(node, problem), fringe) 028 * --------------------------------------------------------------------- 029 * function EXPAND(node, problem) returns a set of nodes 030 * 031 * successors <- empty set 032 * for each <action, result> in SUCCESSOR-FN[problem](STATE[node]) do 033 * s <- a new NODE 034 * STATE[s] <- result 035 * PARENT-NODE[s] <- node 036 * ACTION[s] <- action 037 * PATH-COST[s] <- PATH-COST[node] + STEP-COSTS(STATE[node], action, result) 038 * DEPTH[s] <- DEPTH[node] + 1 039 * add s to successor 040 * return successors 041 * </code> 042 * Figure 3.9 The general tree-search algorithm. (Note that the fringe argument must be an 043 * empty queue, and the type of the queue will affect the order of the search.) The SOLUTION 044 * function returns the sequence of actions obtained by following parent pointers back to the 045 * root. 046 */ 047 048 /** 049 * @author Ravi Mohan 050 * 051 */ 052 053 public class TreeSearch extends QueueSearch { 054 055 @Override 056 public void addExpandedNodesToFringe(NodeStore fringe, Node node, 057 Problem problem) { 058 fringe.add(expandNode(node, problem)); 059 } 060 061 }