Homework Assignment 4 CS 350c Unique Number: 51160 Spring, 2016 Given: February 9, 2016 Due: February 18, 2016 This homework concerns efficiently calculating reachability. This homework is similar in character to HW 3. Our goal is to calculate all of the nodes that are reachable from an initial matrix configuration. Thus, we will be calculating what nodes can reach what other nodes. We represent a directed connection from Node i to Node j by placing a "1" in matrix position (i,j). Note, in an initial matrix, there may be "0"s on the diagonal -- meaning a node cannot reach itself in zero steps, but the transitive closure of such a matrix may include a "circular" route that eventually indicates that a node can indeed reach itself. Consider a matrix that includes a "1" at location (i,j) and another "1" at (j,i); the transitive closure of this matrix will include a "1" at (i,i) and at (j,j). Consider the 4x4 Boolean matrix below. Note, the diagonal contains "1"s; thus, for this example, each node is connected to itself. 0 1 2 3 0: 1 1 0 0 ; Node 0 is connected to itself and Node 1 1: 0 1 1 0 ; Node 1 is connected to itself and Node 2 2: 0 0 1 1 ; Node 2 is connected to itself and Node 3 3: 0 0 0 1 ; Node 3 is connected to itself only We want to calculate all of the nodes that each node can reach. For this example, we can see that Node 0 can reach all nodes. Node 1 can reach nodes 1 (itself), 2, and 3. Node 2 can reach itself and node 3. Finally, Node 3 can only reach itself. To calculate what we observed just above, we want to implement the transitive closure of an input matrix that contains a "1" if Node i can reach node j in one step. The transitive closure matrix contains a "1" in position (m,n) where m can transitively reach node n either directly or by reaching other nodes that can reach n. This assignment requires that you write a transitive-closure algorithm for this kind of matrix. On Monday (February 15, 2016), we will post on the homework class webpage a test dataset. Your program needs to calculate the transitive closure for this dataset. Your final answer will be to exclusive-OR all of the rows from your final answer matrix together and provide a bit string as rows of ASCII "1" and "0" characters. The answer string for the example array above is: 1010 Why? The transitive closure matrix is: 0 1 2 3 0: 1 1 1 1 1: 0 1 1 1 2: 0 0 1 1 3: 0 0 0 1 By xor'ing the four rows (just above) together we get (having already compressing out the spaces): 1111 0111 0011 xor 0001 --------- 1010 Note, your algorithm needs to work for a reachability matrix of at least 4096x4096 bits. You need to submit your code, as we will further test your solution. Your program must only print your final answer as a single string of "1"s and "0"s; each line must contain at most 64-bits, and a final line the remainder. For multiple-line results, all output lines must be 64 bits (and thus, 64 characters), except the last line. For example, if an 80-bit by 80-bit matrix is provided, then the output will have two lines: the first line will have 64 "1"s and/or "0"s and the second line will have 16 "1"s and/or "0"s. Evaluation: Correctly working code: 70% Efficient code: 20% Clearly documented code: 10% ----- Total 100% Of course, I should increase the scoring amount for documentation, but our judgment is subjective -- so we try to minimize any documentation bias we have. The efficiency of your code will be compared to our code. For instance, storing one bit in an 32-bit integer is logically fine, but from a memory-use efficiency point of view, it is wasteful. The first line for an input file will contain a single natural number indicating the dimension of the matrix. All remaining lines in the input file will contain two natural numbers separated by a space, each of these numbers will be at least 0 and less than the dimension of the matrix. The input may contain information about the diagonal; this information will overwrite any initialization we specify for the diagonal. Below is the input for our example matrix: Comments -- do not put in file 4 Dimension of matrix 0 1 Place a "1" at matrix position (0,1) 1 2 Place a "1" at matrix position (1,2) 2 3 Place a "1" at matrix position (2,3) Your program needs to accept (at least) two arguments: arg1: a arg2: either the single character "0" or the single character "1" You can have further, command-line parameters that you may use for other purposes. The second argument indicated whether the diagonal should be initialized to all "1"s or all "0"s; this initialization must be done before processing the lines with two numbers as an entry like 2 2 would indicate that node 2 is connected to itself, and thus, that there should be a "1" at location (2,2) -- even if arg2 was "0". Submission instructions will appear on "http://piazza.com".