Вы находитесь на странице: 1из 3

159.

302 Artificial Intelligence


Assignment #1

The 8-Puzzle: Comparing Search Algorithms


Maximum number of members per group: 3 students
Deadline for submission: May 2, 2012
Instructions
Your task is to write a program that will solve the 8-puzzle problem using four different search
algorithms, one after the other.
An AnimateSolution() function has been provided that you can use to animate the sequence of
moves (i.e. path) calculated by the algorithms. A start-up program (compiles with ScITE) with a
graphics library is available for downloading from our website:
http://www.massey.ac.nz/~nhreyes/Massey/159302.htm.
It is up to you to write any functions , classes or data structures that you may require. You can use
any printf() (or cout) to trace the algorithm execution.
For each implementation of the algorithms below, include codes that will capture the following
information during the algorithms execution:
a. Max. Queue length e.g. 26
b. Path length - e.g. 30
c. Number of state expansions e.g. 157
d. Sequence of moves e.g. DDRRULUL
e. Actual running time in seconds (use the clock() function as shown in the sample codes in
slides)
Part 1: Depth-First Search using the Visited List:
Write code that uses the s (initial state) and g (a goal state) and returns the sequence of moves.
Part 2: Breadth-First Search using the Visited List:
Write code that uses the s (initial state) and g (a goal state) and returns the sequence of moves.
Part 3: Progressive Deepening Search
Write code that uses the s (initial state) and g (a goal state) and returns the sequence of moves.
Part 4: A* Search using the Strict Expanded List:
Write a function in the same form as Part 1 to implement the A* algorithm with Strict Expanded
List and using the following heuristic:
A* with Strict Expanded List and using the Sum of Manhattan Distances as heuristic
Part 5: Algorithm Documentation
Write a pseudo code (or flow chart) for each of the algorithm (in Parts 1, 2, 3 & 4) implementation.
Discuss also the data structures and variables you have used.

Part 6: Tests and Results


N.H.Reyes

159.302 Artificial Intelligence


Assignment #1
Test all the algorithms using the given 5 starting states and 1 goal state below.
Include in your documentation the following information for each test case and algorithm
combination:
a. Max. Queue length
b. Path length
c. Number of state expansions
d. Sequence of moves (e.g. d, l, r, etc.)
e. Actual running time in seconds
Accomplish the given table below to summarize your results.

Algorithm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

DFS using the Visited List


BFS with Visited List
Progressive Deepening Search
A* using the Strict Expanded List
DFS using the Visited List
BFS with Visited List
Progressive Deepening Search
A* using the Strict Expanded List
DFS using the Visited List
BFS with Visited List
Progressive Deepening Search
A* using the Strict Expanded List
DFS using the Visited List
BFS with Visited List
Progressive Deepening Search
A* using the Strict Expanded List
DFS using the Visited List
BFS with Visited List
Progressive Deepening Search
A* using the Strict Expanded List

Initial
State

Max.
Queue
length

Path
length

No. of state
expansions

Sequence
of moves

Actual
Running
Time
(sec.)

042158367
042158367
042158367
042158367
876543210
876543210
876543210
876543210
481302675
481302675
481302675
481302675
168342750
168342750
168342750
168342750
123804765
123804765
123804765
123804765

Note: # - blank space


GOAL STATE:

((# 1 2)
(3 4 5)
(6 7 8))

A set of starting states of differing complexity:


START1:

((# 4 2)
(1 5 8)
(3 6 7))

START2:

((8 7 6)
(5 4 3)
N.H.Reyes

159.302 Artificial Intelligence


Assignment #1
(2 1 #))
START3:

((4 8 1)
(3 # 2)
(6 7 5))

START4:

((1 6 8)
(3 4 2)
(7 5 #))

START5:

((1 2 3)
(8 # 4)
(7 6 5))

Marking:
Make sure your program compiles using gcc before handing it in.
Effective comments make it easier to award marks or partial points if the program is not 100%
working properly.
You can work as a group for this assignment. Copied work will be awarded zero marks.
Hints:
Some random combinations of pieces for your initial state are unsolvable.
Refer to the lecture slides for concepts.
You can step through the search by including a getch() function inside your main loop to pause the
program until the user presses any key.
Example Sequence:

Sequence of states and operations.


You may choose to represent states in an array, size 9. You can represent operations with the 'u' 'd' 'l'
'r' characters.
In notation, the sequence s to get to the goal from the initial state could be represented:
s = {d,r,u,u,l,d} You may find it helpful to printf() (or cout) something similar to help debug your
program.
Nothing follows.

N.H.Reyes

Вам также может понравиться