Assignment 5

CS 146
due May 15, 2001
100 points

Redo Assignment 1 using graphs to represent relations, adjacency matrices to represent graphs, and one of the algorithms from the text to implement the transitive closure method. You are also to make the other changes described below.

In determining the efficiency of your transitive closure method, you may assume that the adjacency matrix is dense.

You should provide a class template for relations.

Test with the main function in the file a5.cpp, obtainable from the class web site.

In order to support adjacency matrices efficiently, it is desirable that all vertices be known in advance. So for this assigment, you should not construct the matrix until a message make_relation has been received. Until this message is received, the pairs of arguments to insert_pair should merely be saved. Then in response to the make_relation message, the array should be constructed.

Calls to insert_pair occuring after the call to make_relation may be ignored if either argument was not seen before the call to make_relation. Otherwise the adjacency matrix should be updated. Second and subsequent make_relation messages to the same relation may be ignored. All messages besides insert_pair may be ignored, except that an error message should be printed, if no make_relation message has been passed to a given relation.

The related method should print an error message if one or both its arguments are unrecognized vertices.