View
225
Download
0
Embed Size (px)
Citation preview
Midterm IISolution
Prof. Mohamed Batouche
Department of Computer ScienceCCIS – King Saud University
Saudi Arabia
Question 1
• Solve the 8-puzzle problem using IDA* with h1() heuristic:
• Operators: slide-blank-up, slide-blank-down, slide-blank-right, slide-blank-left. Operators should be applied in this order.
57
461
382
567
48
321
57
461
382
0+5=5Cutoff = 5
Use DFS
57
461
382
57
46
1
382
0+5=5
1+5=6
Cutoff = 5
up
57
461
382
57
46
1
382
57
461
382
0+5=5
1+5=6
Cutoff = 5
1+4=5
up right
57
461
382
57
46
1
382
57
461
382
57
4
6
1
382
0+5=5
1+5=6
Cutoff = 5
1+4=5
2+3=5
up
up
right
57
461
382
57
46
1
382
57
461
382
57
4
6
1
382
57
4
6
1
3
8
2
0+5=5
1+5=6
Cutoff = 5
1+4=5
2+3=5
3+3=6
up
up
up
right
57
461
382
57
46
1
382
57
461
382
57
4
6
1
382
57
4
6
1
382
57
4
6
1
3
8
2
0+5=5
1+5=6
Cutoff = 5
1+4=5
2+3=5
3+3=6 3+4=7
up
up
up
right
right
57
461
382
57
46
1
382
57
461
382
57
4
6
1
382
57
4
6
1
382
57
4
6
1
3
8
2
57
4
6
1
382
0+5=5
1+5=6
Cutoff = 5
1+4=5
2+3=5
3+3=6 3+3=63+4=7
up
up
up
right
right left
57
461
382
57
46
1
382
57
461
382
57
461
382
57
4
6
1
382
57
4
6
1
382
57
4
6
1
3
8
2
57
4
6
1
382
0+5=5
1+5=6
Cutoff = 5
1+4=5
2+3=5 2+5=7
3+3=6 3+3=63+4=7
up
up
up
right
right
right left
57
461
382
57
46
1
382
57
461
382
57
461
382
57
4
6
1
382
57
4
6
1
382
57
4
6
1
3
8
2
57
4
6
1
382
0+5=5
1+5=6
Cutoff = 5
1+4=5
2+3=5 2+5=7
3+3=6 3+3=63+4=7
Failure: Change cutoff min(f(leaves)) = 6
up
up
up
right
right
right left
57
461
382
0+5=5Cutoff = 6
Use DFS
57
461
382
57
46
1
382
0+5=5
1+5=6
Cutoff = 6
up
57
461
382
57
46
1
382
0+5=5
1+5=6
Cutoff = 6
up
57
46
1
38
2
2+5=7
up
57
461
382
57
46
1
382
0+5=5
1+5=6
Cutoff = 6
up
57
46
1
38
2
57
46
1
382
2+5=7 2+5=7
upright
57
461
382
57
46
1
382
57
461
382
0+5=5
1+5=6
Cutoff = 6
1+4=5
up right
57
46
1
38
2
57
46
1
382
2+5=7 2+5=7
upright
57
461
382
57
46
1
382
57
461
382
57
4
6
1
382
0+5=5
1+5=6
Cutoff = 6
1+4=5
2+3=5
up
up
right
57
46
1
38
2
57
46
1
382
2+5=7 2+5=7
upright
57
461
382
57
46
1
382
57
461
382
57
4
6
1
382
57
4
6
1
3
8
2
0+5=5
1+5=6
Cutoff = 6
1+4=5
2+3=5
3+3=6
up
up
up
right
57
46
1
38
2
57
46
1
382
2+5=7 2+5=7
upright
57
461
382
57
46
1
382
57
461
382
57
4
6
1
382
57
4
6
1
3
8
2
0+5=5
1+5=6
Cutoff = 6
1+4=5
2+3=5
3+3=6
up
up
up
right
57
46
1
38
2
57
46
1
382
2+5=7 2+5=7
upright
57
4
6
1
3
8
2
right
4+4=8
57
461
382
57
46
1
382
57
461
382
57
4
6
1
382
57
4
6
1
3
8
2
0+5=5
1+5=6
Cutoff = 6
1+4=5
2+3=5
3+3=6
up
up
up
right
57
46
1
38
2
57
46
1
382
2+5=7 2+5=7
upright
57
4
6
1
3
8
2
57
4
6
1
3
8
2
right
left4+4=8
4+2=6
57
461
382
57
46
1
382
57
461
382
57
4
6
1
382
57
4
6
1
3
8
2
0+5=5
1+5=6
Cutoff = 6
1+4=5
2+3=5
3+3=6
up
up
up
right
57
46
1
38
2
57
46
1
382
2+5=7 2+5=7
upright
57
4
6
1
3
8
2
57
4
6
1
3
8
2
right
left
57
4
6
1 3
8
2
down
4+4=8
4+2=6
5+1=6
57
461
382
57
46
1
382
57
461
382
57
4
6
1
382
57
4
6
1
3
8
2
0+5=5
1+5=6
Cutoff = 6
1+4=5
2+3=5
3+3=6
up
up
up
right
57
46
1
38
2
57
46
1
382
2+5=7 2+5=7
upright
57
4
6
1
3
8
2
57
4
6
1
3
8
2
right
left
57
4
6
1 3
8
2
down
5
7 4
6
1 3
8
2
down
4+4=8
4+2=6
5+1=6
6+2=8
57
461
382
57
46
1
382
57
461
382
57
4
6
1
382
57
4
6
1
3
8
2
0+5=5
1+5=6
Cutoff = 6
1+4=5
2+3=5
3+3=6
up
up
up
right
57
46
1
38
2
57
46
1
382
2+5=7 2+5=7
upright
57
4
6
1
3
8
2
57
4
6
1
3
8
2
right
left
57
4
6
1 3
8
2
down
5
7 4
6
1 3
8
2
down right
567
48
321
4+4=8
4+2=6
5+1=6
6+2=8Goal !!
Question 2• Explain the way to use hill
climbing for map coloring:
• How to start:– Start with random solution: assign
randomly colors to regions
• How to improve current solution– Select the best solution (minconflicts)
in the neighborhood obtained by modifying region color.
• When to stop:– Stop when the next solution is not
better than current solution (local minimum)
Question 3
• Consider the following map. The task is to color the map using the four colors blue, green, red, and yellow such that no two adjacent regions
take the same color.
• Color the map using Backtracking Search with MCV. Show the steps. The values should be selected according to alphabetical order: (blue, green, red, yellow)
1
4
2
3 6
5
Question 3Solution
1
4
2
3 6
5
Order of variable selection using MCV (select first the variable with most constraints on remaining variables):
2, 1, 3, 5, 4, 6
Question 4
• Consider the problem of Sudoku where:– No value appears twice in the same row.– No value appears twice in the same
column.– No value appears twice in the same block
(22 block).
v1 3 V2 1
v3 1 V4 4
3 4 1 2
v5 V6 4 V7
• Solve this problem using Backtracking with Arc Consistency
Question 4Solution
v1
v7v6v5
v4v3
v2
{2}{4}
{2}
{1}
{2}
{3}
{3}
4 3 2 1
2 1 3 4
3 4 1 2
1 2 4 3