Artificial Intelligence – Lab Assignment 1

advertisement
Artificial Intelligence – Lab Assignment 1
UNIZG FER, academic year 2011/12
Handed out: March 17. Due: March 25 at 23:59
Bridge crossing problem
Group of students of FER are on their way to the FER Freshmen Party 2012. On the way
to their destination there is a bridge they have to cross. Since it is night time and there
is no moonlight to show the way, the students must light their way across the bridge with
a flashlight. Students have only one flashlight. Unfortunately, the old and rusty bridge
is very narrow and allows only for two people to cross it at the same time. Each student
crosses the bridge at his own pace. If the two students are crossing the bridge together,
they are crossing it at the pace of the slower one. The students are in a big hurry to make
it to the opening of the party, so they’re trying to cross the bridge as quickly as possible.
Your task is to write a computer program that finds an optimal solution to the problem
using state space search. An optimal solution to the problem is the sequence of bridge
crossings that will bring the students across the bridge in a minimum amount of total
time. The program must compute the minimum time required for all the students to cross
the bridge together with the total number of states visited during the search (i.e., the
total number of nodes in the closed list). In addition, the program should print out the
sequence of steps (bridge crossings) that lead to the optimal solution. You must solve the
problem using:
(a) blind search, by implementing uniform cost search algorithm;
(b) heuristic search, by implementing the A algorithm with the following heuristic functions:
(1) the amount of time required for the remaining students to cross the bridge is larger
than or equal to the amount of time required for the slowest one of them to cross
the bridge;
(2) the time required for the remaining students to cross the bridge is larger than
or equal to the sum of the times required for the following bridge crossings: the
slowest student and the second slowest student cross the bridge together, the third
slowest student and the fourth slowest student cross the bridge together, the fifth
slowest student and the sixth slowest student cross the bridge together, etc.
You are encouraged to design your own heuristics that are potentially better than
those provided above. In this case, however, you must be certain that your heuristics
are optimistic – finding the optimal solution is the main goal of this lab assignment.
1
Artificial Intelligence – Lab Assignment 1
Examples
(a) The group consist of four students. The amount of time required to cross the bridge
for each of the four students is 1,2,5, and 10 minutes, respectively. The optimal
bridge crossing for all the students takes 17 minutes in total, and consists of following
crossings:
(a) The 1st and the 2nd student cross the bridge (duration 2 minutes),
(b) The 1st student returns with the flashlight (duration 1 minute),
(c) The 3rd and 4th student cross the bridge (duration 10 minutes),
(d) The 2nd student returns with the flashlight (duration 2 minutes),
(e) The 1st and the 2nd student cross the bridge (duration 2 minutes).
Note: The ordering of the crossings described here is not the only possible optimal
solution. Generally, there can be several different optimal solutions to the search
problem.
(b) The group consist of 10 students. The amount of time required to cross the vridge for
each of the students is 1, 2, 5, 10, 3, 4, 14, 18, 20 i 50 minutes, respectively. Uniform
cost search gives the optimal solution with the total duration of 104 minutes. The A
algorithm gives the same solution, but the number of the visited states is significantly
reduced (approximately 150 states less are visited when using the simpler of the two
heuristics and 1030 states less when using the more complex heuristic);
(c) The group consist of 15 students. The amount of time required for bridge crossing for
each of the students is 1, 2, 5, 10, 12, 17, 24, 21, 20, 20, 11, 33, 15, 19 i 55 minutes,
respectively. Uniform cost search provides the optimal solution with the total duration
of 182 minutes. The A algorithm gives the same solution, but the number of visited
states is significantly reduced (approximately 1000 states less when using the simple
of the two heuristics and 47000 states less when using the more complex heuristic);
Note: The number of states visited using the proposed heuristics will not necessarily
be equal for every implementation, i.e., the number of visited states may slightly vary
depending on the implementation. The numbers given in the examples should be
taken as estimates.
Input and output format
The program should take an array of space separated integers as input. The integers
represent the bridge crossing durations for all students in the group. The programs will
be tested using arrays with at most 16 elements. The program should print out the optimal
solution (the shortest overall duration), the number of the states visited during the search,
and the sequence of steps that lead to the optimal solution (each step in a separate row).
An example is given below.
Input:
19 1 2 15 5 15 9
Output:
2
Artificial Intelligence – Lab Assignment 1
52 222
1 2 ->
1 <15 15 ->
2 <1 2 ->
1 <9 19 ->
2 <1 2 ->
1 <1 5 ->
3
Download