In general state-space search is characterized by the following points:
If a recursive search algorithm is used, we can dispense with the open list. The internal mechanism of recursion keeps track of unexplored children instead of the open list.
function depthsearch(current_state) { %% closed_list is global if current_state is a goal state return (success); %% Base case: success add current_state to closed_list; while (current_state has unexamined children) { child = next unexamined child; if child not member of closed_list if depthsearch(child) = success %% Recursive case return (success); } return (fail); %% Base case: failure ==> Backtrack
Basic idea: To find a path from the current state to a goal state, move to a child state and recur. If the child state fails to lead to a goal, try its siblings.
Pattern directed search uses unification to determine when two expressions match, and it uses modus ponens to generate the children states.
function pattern_search(current_goal) { %% closed_list is global if current_state is a member of closed_list %% Loop test return (fail); else add current_goal to closed_list; while there remain in database unifying facts or rules do { case: current_goal unifies with a fact: return (success); %% Base case: success case: current_goal is a conjunction (p ^ ...) for each conjunct do pattern_search(conjunct); %% Recursive case if pattern_search succeeds for each conjunct return (success); %% Base case: success else return (fail); %% Base case: fail case: current_goal unifies with a rule conclusion (p in p :- q) apply goal unifying substitutions to premise (q); pattern_search(premise); %% Recursive case if pattern_search succeeds return (success); %% Base case: success else return (fail); %% Base case: fail } return (fail); %% Base case: failure ==> Backtrack
Production rules can take a wide variety of forms. In this problem we are doing string rewriting of the sort that might be done in certain forms of proof system or in a Lindenmayer system (L-system). Suppose we have the following set of productions:
1. ba → ab 2. ca → ac 3. cb → bc
A production matches if its LHS matches any portion of the string in working memory. The conflict resolution rule in this example is to choose the lowest numbered rule.
Iteration # | Working memory | Conflict set | Rule fired |
---|---|---|---|
0 | cbaca | 1,2,3 | 1 |
1 | cabca | 2 | 2 |
2 | acbca | 3,2 | 2 |
3 | acbac | 1,3 | 1 |
4 | acabc | 2 | 2 |
5 | aacbc | 3 | 3 |
6 | aabcc | - | Halt |
Problem: Solve the 3 x 3 knight's tour using the production system model. Each legal move is represented as a production rule of the form:
current_state → new_state
Working memory contains both the current board state and the goal state. Conflict resolution would fire the first rule that avoids creating a loop. The control regime should also allow backtracking. Find a path from square 1 to square 2.
Production rules ----------------- 1. 1 → 8 9. 6 → 1 ---------------------- 2. 1 → 6 10. 6 → 7 | | | | 3. 2 → 9 11. 7 → 2 | 1 | 2 | 3 | 4. 2 → 7 12. 7 → 6 ---------------------- 5. 3 → 4 13. 8 → 3 | | | | 6. 3 → 8 14. 8 → 1 | 4 | 5 | 6 | 7. 4 → 9 15. 9 → 2 ---------------------- 8. 4 → 3 16. 9 → 4 | | | | | 7 | 8 | 9 | ----------------------
Iteration # | Working memory | Conflict set | Rule fired | |
---|---|---|---|---|
Current Square | Goal Square | |||
0 | 1 | 2 | 1,2 | 1 |
1 | 8 | 2 | 13,14 | 13 |
2 | 3 | 2 | 5,6 | 5 |
3 | 4 | 2 | 7,8 | 7 |
4 | 9 | 2 | 15,16 | 15 |
5 | 2 | 2 | - | Halt |
Problem: Given the set of propositional calculus productions, perform goal driven search using the production system approach.
Production rules ----------------- 1. p ^ q → goal 2. r ^ s → p 3. w ^ r → p 4. t ^ u → q 5. v → s 6. start → v ^ r ^ q
The following table provides a trace of a goal-driven search. The conflict resolution rule is to use the least recently used rule.
Iteration # | Working memory | Conflict set | Rule fired |
---|---|---|---|
0 | goal | 1 | 1 |
1 | goal,p,q | 1,2,3,4 | 2 |
2 | goal,p,q,r,s | 1,2,3,4,5 | 3 |
3 | goal,p,q,r,s,w | 1,2,3,4,5 | 4 |
4 | goal,p,q,r,s,w,t,u | 1,2,3,4,5 | 5 |
5 | goal,p,q,r,s,w,t,u,v | 1,2,3,4,5,6 | 6 |
6 | goal,p,q,r,s,w,t,u,v,start | 1,2,3,4,5,6 | halt |
Perform the search in a data-driven direction.