0% found this document useful (0 votes)
28 views18 pages

Midterm Review 2

The document describes an iterative deepening search solution to a problem involving transporting a boy, a basket of cabbage, a wolf, and a goat across a river using a small boat that can only hold the boy and one other item. The optimal solution involves 5 river crossings with the boy transporting items one at a time or in pairs to ensure the goat is never left alone with the wolf or cabbage. The document also provides the details of a sliding tile puzzle problem involving 3 numbered tiles and an empty space, formulates it as a state space search problem, and uses A* search with a Manhattan distance heuristic to find an optimal solution path

Uploaded by

gmu.rajendra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views18 pages

Midterm Review 2

The document describes an iterative deepening search solution to a problem involving transporting a boy, a basket of cabbage, a wolf, and a goat across a river using a small boat that can only hold the boy and one other item. The optimal solution involves 5 river crossings with the boy transporting items one at a time or in pairs to ensure the goat is never left alone with the wolf or cabbage. The document also provides the details of a sliding tile puzzle problem involving 3 numbered tiles and an empty space, formulates it as a state space search problem, and uses A* search with a Manhattan distance heuristic to find an optimal solution path

Uploaded by

gmu.rajendra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

1 / 18

–2
September 29, 2008

+2
–3
+3
–1
–1
+1
X +5
+4
+1
1/ 18
0
X –2
X –1
X 0
–3
X +3
X +2
Start +3
node –3
+5
–5
X 0
Alpha-Beta Pruning Example
Alpha-Beta Pruning

X X –3

Midterm Review 2
(Backed-up +1
value = +1) +5
X +1
0
–5
+5
X +2
+5
X +3

Dr. Zoran Duric (CS Dept., GMU)


–2
MAX nodes +2
0
MIN nodes X –3
+3
+3
–3
+5
0
© 1998 Morgan Kaufman Publishers
Search

Problem #3

A boy brings a basket of cabbage, a wolf, and a goat to a river. There is a


small boat on their river bank that they can use to cross to the other side.
However, the boat is so small that it can hold only the boy and the
cabbage or the boy and one of the animals. The boy cannot leave the goat
alone with either the cabbage or the wolf. How should the boy use the
boat to take the cabbage and the animals to the other side of the river in
such a way that the number of river crossings is minimal and that the goat
is never left alone with either the wolf or the cabbage on any side of the
river? Use iterative deepening search to solve this problem.

Dr. Zoran Duric (CS Dept., GMU) Midterm Review 2 2/ 18 September 29, 2008 2 / 18
Search

Problem #3: Solution


BCWG

CW BG

BCW G

C BWG W BCG

BCG W BGW C

G BCW

BG CW

BCGW
Dr. Zoran Duric (CS Dept., GMU) Midterm Review 2 3/ 18 September 29, 2008 3 / 18
Search

Problem #5

A simple sliding-tile puzzle consists of 3 numbered tiles and an empty


space. The puzzle has two legal moves with associate costs: (i) A tile may
move into an adjacent empty location. This has a cost of 1. (ii) A tile can
move over one other tile into the empty position. This has a cost of 2.
The start and goal positions are given below.

1 2 3 3 1 2

Dr. Zoran Duric (CS Dept., GMU) Midterm Review 2 4/ 18 September 29, 2008 4 / 18
Search

Problem #5 (cont.)

Set up a state-space search formulation for this puzzle:


a) Specify the form of state descriptions, the starting state, and the goal
state for this problem.
b) Name the operators on states and describe what each operator does
to a state description. Write a lisp function that takes a state as
input and outputs a list of states that can be reached from that state.
Include the parent and the cost fields.
c) Propose a heuristic function ĥ for solving this problem.
d) Use the A∗ algorithm to find a solution path using your heuristic
function.
e) Is your solution path optimal? Give a formal argument.

Dr. Zoran Duric (CS Dept., GMU) Midterm Review 2 5/ 18 September 29, 2008 5 / 18
Search

Problem #5: Solution

a) A list of three numbers and a white space. Start: (1 2 3 −), Goal:


(3 1 2 −)
b) Swap1(i, j): swaps a tile at position i with an empty tile at position j,
where |i − j| = 1
Swap2(i, j): swaps a tile at position i with an empty tile at position j,
where |i − j| = 2
c) City-block/Manhattan distance: sum of absolute distances of all
numbered tiles form their goal positions
ĥ((1 2 3 −)) = 1 + 1 + 2 = 4
d) Swap2(2, 4), Swap1(1, 2), Swap2(3, 1), Swap1(4, 3)
e) ĥ is admissible, A∗ with an admissible heuristics produces optimal
solution

Dr. Zoran Duric (CS Dept., GMU) Midterm Review 2 6/ 18 September 29, 2008 6 / 18
Search

Problem #5: Solution (d)

123− h=4
1 2

1+5=6 12−3 1−32 2+4=6

1 1
2 1

3+5=8 −213 1−23 2+4=6 −132 3+3=6 13−2 3+3=6

1 2 2

3+3=6 −123 132− 2+4=6 31−2 5+1=6

2 1

5+5=10 2 1 − 3 13−2 5+3=8 312− 6+0=6

Dr. Zoran Duric (CS Dept., GMU) Midterm Review 2 7/ 18 September 29, 2008 7 / 18
Search

Problem #13

The 8-puzzle consists of eight numbered, movable tiles set in a 3×3


frame. One cell of the frame is always empty thus making it possible to
move and adjacent numbered tile into the empty cell—or, we could say, to
move the empty cell. Two configurations of tiles are given. Consider the
problem of changing the initial configuration into the goal configuration.

2 4 3 1 2 3
1 6 8 4 8
5 7 5 6 7

start goal

Dr. Zoran Duric (CS Dept., GMU) Midterm Review 2 8/ 18 September 29, 2008 8 / 18
Search

Problem #13 (cont.)

Set up a state-space search formulation for this puzzle:


a) Specify the form of state descriptions, the starting state, and the goal
state for this problem.
b) Name the operators on states and describe what each operator does
to a state description.
c) Propose a heuristic function ĥ for solving this problem.
d) Use the A∗ algorithm to find a solution path.
e) Is your solution path optimal? Give a formal argument.

Dr. Zoran Duric (CS Dept., GMU) Midterm Review 2 9/ 18 September 29, 2008 9 / 18
Search

Problem #13: Solution


Solution:
a) 3 × 3 array
   
2 4 3 1 2 3
start :  1 6 8  , goal :  4 − 8 
5 − 7 5 6 7

b) MU(i, j): move empty tile at (i, j) up, empty tile is now at (i − 1, j)
MD(i, j): move empty tile at (i, j) down, empty tile is now at (i + 1, j)
ML(i, j): move empty tile at (i, j) left, empty tile is now at (i, j − 1)
MR(i, j): move empty tile at (i, j) right, empty tile is now at (i, j + 1)
c) City-block/Manhattan distance: sum of the absolute i and j distances
of all tiles from their goal positions
d) MU(3, 2), MU(2, 2), ML(1, 2), MD(1, 1), MR(2, 1)
e) h is admissible since it solves an easier problem, therefore A∗ results
in an optimal path
Dr. Zoran Duric (CS Dept., GMU) Midterm Review 2 10/ 18 September 29, 2008 10 / 18
Search

Problem #13: Solution (d)


243
168 h=5
5 −7
1 1
1
243 243 243
1−8 168 168
4+1=5
567 −57 57−
1 6+1=7 6+1=7
1
1

2 − 3 3+2=5 2 4 3 5+2=7 2 4 3 5+2=7


148 −18 18−
567 567 567

1 1
− 2 3 2+3=5 2 3 − 4+3=7
148 148
567 567
1

1 2 3 1+4=5
−48
567
1 1

1 2 3 0+5=5 1 2 3 2+5=7
4−8 548
567 −67

Dr. Zoran Duric (CS Dept., GMU) Midterm Review 2 11/ 18 September 29, 2008 11 / 18
Search

Problem #29

A simple sliding-tile puzzle consists of 4 numbered tiles. The puzzle has


two legal moves. (i) Two adjacent tiles can switch positions. This has a
cost of 2. (ii) Two non-adjacent tiles can switch positions. This has a cost
of 3.

1 2 3 4 4 3 1 2
start goal

Dr. Zoran Duric (CS Dept., GMU) Midterm Review 2 12/ 18 September 29, 2008 12 / 18
Search

Problem #29 (cont.)

Set up a state-space search formulation for this puzzle:


a) Specify the form of state descriptions, the starting state, and the goal
state for this problem.
b) Name the operators on states and describe what each operator does
to a state description.
c) Propose a heuristic function ĥ for solving this problem.
d) Use the A∗ algorithm to find a solution path.
e) Is your solution path optimal? Give a formal argument.

Dr. Zoran Duric (CS Dept., GMU) Midterm Review 2 13/ 18 September 29, 2008 13 / 18
Search

Problem #29: Solution

Solution:
a) A list of 4 numbers

start : (1 2 3 4), goal : (4 3 1 2)

b) Swap2(i, j): swap tiles at positions i and j, where |i − j| = 1


Swap3(i, j): swap tiles at position i and j where |i − j| > 1
c) h = # of tiles out of place by 1 + 1.5 × # of tiles out of place by 2
or more
d) Swap2(2, 3), Swap2(3, 4), Swap3(1, 3)
e) h is admissible since it solves an easier problem, therefore A∗ results
in an optimal path

Dr. Zoran Duric (CS Dept., GMU) Midterm Review 2 14/ 18 September 29, 2008 14 / 18
Search

Problem #13: Solution (d)

1234
2 2 2 3 3
3
f=7 2 1 3 4 6 1324 8 1243 7 3214 6.5 1 4 3 2 6.5 4 2 3 1
2 2 3 3 3
3124 1342 4321 2314 1423
4+4.5=8.5 4+3=7 5+2=7 5+3=8 5+5=10
2 3 3 3
2 7 2
6 6 7 7 2
3142 1432 4312 1243 2341 2 3 3
2 2
9.5 9.5 7+0=7 13 11
3 3 3 1423
f=9 5+5=10
2314 3124 2431 4132 4132 1342 3412 2431
f=7 f=9 f=7 6+2=8 6+4.5=10.5
2143 5+2=7 5+3=8
f=8

2 3 3
2 2
2431 4321 4213 3241 4132
5+4.5=9.5 5+2=7 5+3=8 6+5=11 6+2=8

Dr. Zoran Duric (CS Dept., GMU) Midterm Review 2 15/ 18 September 29, 2008 15 / 18
Search

Problem #31

Show how different techniques can be used to solve the 4-queens


placement problem (place 4-queens on a 4 × 4 board so that there is at
most one queen in each row, column, or a diagonal of the board. Solve
this problem using the following tecniques:
a. Backtracking search.
b. Forward checking.
c. Min-conflicts algorithm. To initialize the problem place all four
queens on the main diagonal of the board.

Dr. Zoran Duric (CS Dept., GMU) Midterm Review 2 16/ 18 September 29, 2008 16 / 18
Search

Problem #31: Solution

a. Backtracking search.
2 3 2 3 2 3 2 3
Q ∗ ∗ ∗ Q ∗ ∗ ∗ Q ∗ ∗ ∗ Q ∗ ∗ ∗
6 ∗ ∗ ∗ ∗ 7
7→6 ∗ ∗ ∗ 7 6 ∗ ∗ ∗
Q back 7→6 ∗
Q 7 ∗ ∗ Q 7
6 6
6 7··· 6 7
4 ∗ ∗ ∗ ∗ 5 4 ∗ ∗ ∗ ∗ 5 → 4 ∗ ∗ ∗ ∗ 5 4 ∗ Q ∗ ∗ 5
∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗

2 3 2 3 2 3 2 3
∗ Q ∗ ∗ ∗ Q ∗ ∗ ∗ Q ∗ ∗ ∗ Q ∗ ∗
6 ∗ ∗ ∗ ∗ 7
back 6 6 ∗ ∗ ∗ Q 7 6 ∗ ∗ ∗ Q 7 6 ∗ ∗ ∗ Q 7
··· 7→ 6 7→ 6 7→ 6 7
→ 4 ∗ ∗ ∗ ∗ 5 4 ∗ ∗ ∗ ∗ 5 4 Q ∗ ∗ ∗ 5 4 Q ∗ ∗ ∗ 5
∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗ Q ∗

b. Forward checking.
2 3 2 3 2 3 2 3
Q x x x Q x x x Q x x x Q x x x
6 x
6 x ∗ ∗ 7
7→6 x
6 x Q x 7
7 back 6 x
6 x x Q 7
7→6 x
6 x x Q 7
7
4 x ∗ x ∗ 5 4 x x x x 5 → 4 x ∗ x x 5 4 x Q x x 5
x ∗ ∗ x x ∗ x x x x ∗ x x x x x

2 3 2 3 2 3 2 3
x Q x x x Q x x x Q x x x Q x x
back 6 x
6 x x ∗ 7
7→6 x
6 x x Q 7
7→6 x
6 x x Q 7
7→6 x
6 x x Q 7
7
→ 4 ∗ x ∗ x 5 4 ∗ x x x 5 4 Q x x x 5 4 Q x x x 5
∗ x ∗ ∗ ∗ x ∗ x x x ∗ x x x Q x

Dr. Zoran Duric (CS Dept., GMU) Midterm Review 2 17/ 18 September 29, 2008 17 / 18
Search

Problem #31: Solution

c. Min-conflicts algorithm. To initialize the problem place all four


queens on the main diagonal of the board.
Q0 Q0
2 3 2 32 3 2 32 3
∗ ∗ ∗ 3 ∗ ∗ ∗ ∗ 1 ∗ ∗ ∗
∗ Q0 ∗ ∗ 7 7 6 Q0 Q0 ∗ ∗ 7 0
∗ ∗ ∗ 7
7 , c1 6 1 3 7
76 Q
6 6 6 6
7 , c2 6 7,
Q0 Q0 Q0
6 76
4 ∗ ∗ ∗ 5 4 2 54 ∗ ∗ ∗ 5 4 2 54 ∗ ∗ ∗ 5
0
∗ ∗ ∗ Q0 1 ∗ ∗ ∗ Q 2 ∗ ∗ ∗ Q0

Q0 Q0 Q0 Q0
2 32 3 2 32 3
1 ∗ ∗ 2 ∗ ∗
6 2 7 6 Q0 ∗ ∗ ∗ 7 2 7 0
∗ ∗ ∗ 7
76 Q
6 6
c3 4
6 76 7 , c4 6 7,
1 54 ∗ ∗ ∗ ∗ 5 4 1 54 ∗ ∗ ∗ ∗ 5
2 ∗ ∗ ∗ Q0 0 ∗ ∗ ∗ Q0

Q0 Q0 Q0
2 32 3 2 32 3
3 ∗ ∗ 2 ∗ ∗ ∗
6 1 7 6 Q0 ∗ ∗ ∗ 7 3 7 0
∗ ∗ ∗ 7
76 Q
6 6
c1 4
6 76 7 , c2 6 7,
1 5 4 ∗ ∗ ∗ ∗ 5 4 1 5 4 ∗ ∗ ∗ ∗ 5
1 ∗ ∗ ∗ Q0 1 ∗ Q0 ∗ Q0

Q0 Q0
2 32 3 2 32 3
0 ∗ ∗ ∗ 1 ∗ ∗ ∗
6 1 7 6 Q0 ∗ ∗ ∗ 7 7 6 7 6 Q0
3 7 ∗ ∗ ∗ 77
c3 4 , c4 6 ,
Q0 5
6 76 6
2 5 4 ∗ ∗ ∗ ∗ 5 4 0 5 4 ∗ ∗ ∗
3 ∗ Q0 ∗ Q 0 1 ∗ Q0 ∗ ∗

Dr. Zoran Duric (CS Dept., GMU) Midterm Review 2 18/ 18 September 29, 2008 18 / 18

You might also like