Notes From CS Undergrad Courses FSU
This project is maintained by awa03
Aiden Allen
1) Trace the execution of the recursive depth-first search algorithm (the second version of depth search in Section 6.1.1) on the state space of Chapter 3, Figure 14
The goal that we are seeking to reach within the following graph is an attempt to maximize the value of the node. We will attempt to classify this through the following algorithm referenced in 6.1.1.
function depth search(current state); // closed is global
begin
if current state is a goal
then return SUCCESS;
add current state to closed;
while current state has unexamined children
begin
child := next unexamined child;
if child not member of closed
then if depth search(child) = SUCCESS
then return SUCCESS
end;
return FAIL // search exhausted
end
We will be examining the following tree in order to describe the way in which this algorithm operates, through hand traversing the tree.
![[Screenshot 2024-11-01 at 17-04-13 05_Chapter_03.pdf - 05_Chapter_03.pdf.png]]
Current State | Path | Closed | Next Child | Outcome |
---|---|---|---|---|
A | A/ | A | B | Try Child |
B | A/B | A, B | E | Try Child |
E | A/B/E | A, B, E | H | Try Child |
H | A/B/E/H | A, B, E, H | NULL | FAIL |
I | A/B/E/I | A, B, E, H, I | NULL | FAIL |
F | A/B/F | A, B, E, H, I, F | J | Try Child |
J | A/B/F/J | A, B, E, H, I, F, J | NULL | FAIL |
C | A/C | A, B, E, H, I, F, J, C | F | Try Child |
G | A/C/G | A, B, E, H, I, F, J, C, G | NULL | FAIL |
D | A/D | A, B, E, H, I, F, J, C, G, D | NULL | SUCCESS |
5) Using the move and path definitions for the knight’s tour of Example 6.1.1, do the following:
The pattern search algorithm given to us in section 6.1.2, is shown below.
function pattern search(current goal);
begin
if current goal is a member of closed // test for loops
then return FAIL
else add current goal to closed;
while there remain unifying facts or rules do
begin
case
current goal unifies with a fact:
return unifying substitutions;
current goal is negated (¬p):
begin
call pattern search on p;
if pattern search returns FAIL
then return {}; // negation is true
else return FAIL;
end;
current goal is a conjunction (p ∧ . . .):
begin
for each conjunct do
begin
call pattern search on conjunct;
if pattern search returns FAIL
then return FAIL;
else apply substitutions to other conjuncts;
end;
if pattern search did not return FAIL for any conjunct
then return composition of unifications;
else return FAIL;
end;
current goal is a disjunction (p ∨ . . .):
begin
for each disjunct do
begin
call pattern search on disjunct
if pattern search returns SUCCESS
then return substitutions
else return FAIL;
end;
if pattern search returned FAIL for all disjuncts
then return FAIL;
end;
current goal unifies with rule conclusion (p in p ← q):
begin
apply goal unifying substitutions to premise (q);
call pattern search on premise;
if pattern search returns SUCCESS
then return composition of p and q substitutions
else return FAIL;
end;
end; //end case
end //end while
return FAIL
end
Goal: (1, 9) Unify with 9 by ${1/X, 9/Y}$ $move(1, Z) \land path(Z, 9) \implies path(1, 9)$
Subgoal: move(1, Z) Unify with fact move(1, 8), unifying with $(8 / z)$, satisfies subgoal $move(8, 9)$
Goal path(8, 9): Unifying with the Rule: $move(X, Z) \land path(Z, Y) \implies path(X, Y)$ $path(8,9)←move(8,Z)∧path(Z,9)$ Making the new subgoal $move(8, Z)$
Subgoal: move(8, Z) Using the fact move(8, 3), unify with {3, 2} satisfying this subgoal The new subgoal will then be $move(4, 9)$
Goal: path(4, 9) Unify with the rule: $path(X,Y)←move(X,Z)∧path(Z,Y)$ by {4/X, 9/Y}, giving: path(4,9)←move(4,Z)∧path(Z,9) The new subgoal will then be $move(4, Z)$
Subgoal: move(4, Z) Using the fact move(4, 9), unify by {9/Z}, meeting the subgoal The new subgoal is now, (9, 9)
Goal: path(9, 9)
For the goal path path(1, 5) the pattern search would attempt to find a sequence from 1 to 5 by exploring possible moves from each position. Starting from 1 it would likely follow the path from $move(1, 8)$, checking path $path(8, 5)$. Eventually this path would fail to find a valid sequence reaching 5, as there are no direct or compounded moves that will go from 1 to 5. Therefore the algorithm would eventually backtrack and fail, indicating that there are in fact no valid paths.
For path(7, 6), the algorithm would move to a position such as $move(7, 3)$ or $move(7, 2)$, recursively attempting to reach the position 6. If no cases lead to 6 it will backtrack and return. The ordering of entries in move predicate can impact this because it will prioritize closer and move relevant connections to the goal path. Poor ordering can thus lead to many irrelevant moves being made, when the algorithm may have made more effective choices otherwise. The same can be said for heuristic evaluations as well!
7) Using the rule in Example 6.1.2 as a model, write the eight move rules needed for the full 8 × 8 version of the knight’s tour.
8) Using the start and goal states of Figure 5, hand run the given production system solution to the 8-puzzle:
For each part, create a table like that shown in Figure 7
![[Screenshot 2024-11-04 at 12-37-31 07_Chapter_06.pdf - 07_Chapter_06.pdf.png]]
Production Set:
Control Regime:
Data Driven:
Iteration | Current State | Goal State | rule #'s | Fire Rule |
---|---|---|---|---|
0 | 1 | 31 | 2, 3, 4 | 2 |
1 | 2 | 31 | 3, 4 | 3 |
2 | 3 | 31 | 3, 4, 5 | 3 |
3 | 4 | 31 | 4, 5 | 4 |
4 | 5 | 31 | 2, 4, 5 | 2 |
5 | ALREADY VISITED SKIP | 31 | 1, 4, 5 | 1 |
6 | 5 | 31 | 2, 4, 5 | 2 |
7 | ALREADY VISITED SKIP | 31 | 1, 4, 5 | 1 |
8 | 5 | 31 | 4, 5 | 4 |
9 | 6 | 31 | NULL | Back Track |
10 | 1 | 31 | 3, 4 | 3 |
11 | 18 | 31 | 2, 3, 4, 5 | 2 |
12 | 19 | 31 | 3, 4, 5 | 3 |
13 | 20 | 31 | 4, 5 | 4 |
14 | ALREADY VISITED SKIP | 31 | 1 | 1 |
15 | 21 | 31 | 2, 4, 5 | 2 |
16 | ALREADY VISITED SKIP | 31 | 4, 5 | 4 |
17 | 22 | 31 | NULL | Back Track |
18 | 23 | 31 | NULL | Back Track |
19 | 24 | 31 | 3, 4 | 3 |
20 | ALREADY VISITED SKIP | 31 | 4 | 4 |
21 | 25 | 31 | 2, 3, 4 | 2 |
22 | ALREADY VISITED SKIP | 31 | 3, 4 | 3 |
23 | 26 | 31 | NULL | Back Track |
24 | 27 | 31 | NULL | Back Track |
25 | 18 | 31 | 2, 4, 5 | 2 |
26 | 28 | 31 | 4, 5 | 4 |
27 | 29 | 31 | 4, 5 | 4 |
28 | 31 | GOAL | GOAL | GOAL |
As we can see the goal state has been reached through the search method.
Goal Driven:
Iteration | Current State | Goal State | rule #'s | Fire Rule |
---|---|---|---|---|
0 | 31 | 1 | 2, 3, 4, 5 | 2 |
1 | 30 | 1 | 3, 4, 5 | 3 |
2 | 29 | 1 | 4, 5 | 4 |
3 | 28 | 1 | 2, 4, 5 | 2 |
4 | ALREADY VISITED SKIP | 1 | 4, 5 | 4 |
5 | 18 | 1 | 5 | 5 |
6 | 1 | GOAL | GOAL | GOAL |
9) Consider the financial advisor problem discussed in Chapters 2, 3, and 4.
Production Set:
Control Regime:
State | Income, Savings | Dependents | Income | Savings | Min Savings | Min Income |
---|---|---|---|---|---|---|
Stocks | Adequate, Adequate | 1 | 25000 | 22000 | 5000 | 19000 |
Combination | Inadequate, Adequate | 3 | 25000 | 20000 | 15000 | 31000 |
Savings | Adequate, Inadequate |
4 | 100000 | 0 | 20000 | 19000 |
Savings | Inadequate, Inadequate |
1 | 0 | 0 | 4000 | 19000 |
10) Repeat problem 9.b to produce a goal-driven solution.
Goal | Conditions | Necessary Info |
---|---|---|
Stocks | If both the savings and income is adequate | check income level, savings amount, number of dependents |
Combination | If the Savings is adequate and the income is inadequate | check income level, savings amount, number of dependents |
Savings | If the Savings in inadequate | check savings level and number of dependents |