Write a program called Paths
that reads a directed graph
and then finds and displays paths in that graph by various methods.
The name of the file containing the graph data will be the first
command-line argument. The file will contain a positive integer
on the first line giving the number of vertices in the graph
and then zero or more lines where each line contains the index
of the from vertex and then the to vertex for an edge.
Each edge will be listed
at most once and the indices will be separated by any amount of
whitespace. There may also be leading and trailing whitespace on each
line.
Subsequent command-line arguments specify which vertices to find paths between and the method to use to find the paths. Command-line arguments "-breadth", "-depth", or "-degree" indicate that paths should be found using
The output of your program must be written to standard output with one line per path requested. That line should give the method used, the index of the from and to vertices, and the path in the format used in the example below (with "no path" in place of the path if there is no path from the from vertex to the to vertex). The output for the requested paths should appear in the order they were given on the command line.
Your program should run in time $O(a(n+m) + b(n^2 \log n) + p)$
where $a$ is the
total number of times -breadth
and -depth
appear on the command line, $b$ is the number of times
-degree
appears, and $p$ is the total length of
all the paths output.
If the input file or command-line arguments are not as specified then your program must behave gracefully: it must not crash or go into an infinite loop.
Your program and any program
must not produce any error messages when run with
valgrind --tool=memcheck --leak-check=yes -q
.
We reserve the right to deduct points from submissions for violations of the following guidelines.
#include
d regardless of what other files have
been #include
d -- if a declaration is required by
your header files, then #include
the appropriate
header file in your header file (or write a forward declaration in
your header) rather than relying on your #include
rs
to have already #include
d those header files before
they #include
yours.
const
should be declared as const
.
-Wall
and -pedantic
options.
graph_4.in
contains
4 0 1 0 3 1 3 1 2 2 0 2 3then running
./Paths graph_4.in -breadth 0 3 -depth 0 3 -degree 0 3
should result in the following output:
-breadth 0->3: [0, 3] -depth 0->3: [0, 1, 3] -degree 0->3: [0, 1, 2, 3]
/home/httpd/html/zoo/classes/cs223/f2017/Assignments/Paths
: