Introduction to Artificial Intelligence

Homework #1
Due: Sept. 15

Contents

The Story

``Che successo?''

``Well, Godfather, your godson Alfonso, along with 50 other students, is dead,'' replied his assistant, hesitantly.

``Madonna. The same symptoms?''

``Yes, godfather. The coroner says a combination of exhaustion and stress.''

``Gentlemen,'' He addressed the other occupants of the room. ``Do we have ANY idea what is causing this? Is it the Tantaglio family?''

``I think I have a good idea, Godfather,'' volunteered Vinny. ``It seems all the students affected were registered for courses without having the proper prerequisites. I believe it was the incredible strain of the extra work load which did them in.''

``Doesn't the registration system check prerequisites?'' The anger in Don Corlione's voice was becoming more and more apparent.

The rest of the group laughed, then silenced in response to the Godfather's admonishing stare.

Slowly, and visibly restraining himself, Don Corlione rose and began to circle the table. Addressing himself to his lawyer, he said, ``WHY doesn't the registration system check prerequisites?''

``We...errr...they don't have the capability to do that kind of thing. It requires software way beyond the capacity of the meek system they run,'' he sputtered.

``Are you telling me I just donated six million dollars to a school so my Godson Alfonso could use those computers he loves, and it can't even do a simple task like checking prerequisites?'' Don Corlione had picked up a baseball bat and was holding it with both hands.

``Well...we never really thought about it....''

``This is unacceptable,'' the Godfather interrupted.

``What? I...''

``I PAY you,'' Don Corlione was trembling with passion. ``To advise me on such matters. You told me it was a good college. `The kid loves computers,' you said. `Send him here.' Now he's DEAD!'' The rest of the group were nervously watching the baseball bat in his hand as he slowly moved behind the lawyer.

``Look, I think I might be able to get one of their staff to do something...'' he said, desperately.

``Do you know what happened to people in ancient Rome who made decisions that lead to someone's death?''

``I...'' The lawyer was cut off as Don Corlione smashed his skull with the bat, and he collapsed on the table in a pool of blood. The Godfather cintinued to bludgeon him like a baby seal and then tossed the red-stained bat across the room to a heavy set gentleman in a dark suit.

``Rocco,'' the Godfather said.

``Yeah boss?''

``Fai questo pulito, poi chiama Welty. Ho un'altro cosa per lui de fare."

``OK boss.'' Rocco walked over to the body, tossed it easily over his shoulder and left. Immediately a custodial team rushed in and began cleaning the carpet and chair.

Michael Corlione looked at Vinny. ``Find me a new lawyer.'' And then to the rest of the people in the room, ``This meeting is over.''

The Project

Your assistance is required to help prevent further deaths. You must write a system, in LISP, for tracking prerequisites to courses. Your system should provide the facilities both to set up and query a database of courses and their prerequisites. You should provide the following functions:

prereqs course-name [Function]

This function should return a list of all the prerequisites for the course course-name, including all the prerequisites for each course in that list, if any, and so on. This list should not contain any duplicate course names. If course has no prerequisites, nil should be returned. It should not be necessary for a course to have been set up with add-prereqs to have no prerequisites (see the example below).

add-prereqs course-name prereq-list [Function]

This function should add the list prereq-list to the list of prerequisites for course-name. If course already has prerequisites, then prereq-list should be appended to that list. The return value should be prereq-list. This function should check for cycles (adding a course as a prequisite of itself), in this case, it should raise an error and not make any changes at all.

clear-prereqs course [Function]

This function should clear all the prerequisites of course, such that prereqs would return nil. The return value should be t.

For example:

> (add-prereqs 'a '(b c))
(B C)

> (add-prereqs 'b '(d e f)) (D E F)

> (add-prereqs 'c '(d f)) (D F)

> (add-prereqs 'd '(f g h)) (F G H) > (prereqs 'd) (F G H) > (prereqs 'b) (D E F G H) > (prereqs 'a) (B C D E F G H) > (prereqs 'f) nil > (add-prereqs 'f '(a)) ERROR: f is a prequisite for a.

Deliverables

You must turn in a well documented listing of your functions, including a discussion of how you stored the prerequisites. Sample data will be provided. You must submit sample runs that include runs that use the sample data.

Click here for the sample data.