submit itec360-01 README.txt topo.adb etc.adb
Last modified:
Updates:
You can see an example of this program at assignment checker (which uses gnoga to integrate the GUI, web server, and problem solution). On-campus or VPN session required. [Note that the URL has changed.]
Overview: This assignment involves implementing a directed graph data structure and using that structure for implementing depth-first, breadth-first, topological sorts and checking a topological sort.
Sample Run:
If the input file prereqs.txt
is as follows:
7 120 0 220 1 120 122 1 120 324 1 220 320 1 220 360 4 320 324 122 171And if the input file360 3 320 324 122 171420 1 122
commands.txt
is as follows:
count acyclic breadth 120 depth 120 topological check 120 122 220 320 324 171 360 420 check 120 122 220 320 324 360 171 420 print help quitThe following sample run reads standard input from a file
>./topo prereqs.txt < commands.txt Node count: 8 Acyclic: Yes Breadth-first search from 120: 120, 122, 220, 360, 420, 320, 324, 171 Depth-first search from 120: 120, 122, 360, 420, 220, 320, 324, 171 Topological search: 171, 120, 220, 324, 320, 122, 420, 360 Valid topological sort: Yes: 120, 122, 220, 320, 324, 171, 360, 420 Valid topological sort: No: 120, 122, 220, 320, 324, 360, 171, 420 Graph: Node: 120: Parents: Children: 122, 220 Node: 220: Parents: 120 Children: 320, 324 Node: 122: Parents: 120 Children: 360, 420 Node: 324: Parents: 220 Children: 360 Node: 320: Parents: 220 Children: 360 Node: 360: Parents: 122, 171, 320, 324 Children: Node: 171: Parents: Children: 360 Node: 420: Parents: 122 Children: Possible commands: [A]CYCLIC [D]EPTH Node [B]READTH Node [CH]ECK Node+ [C]OUNT [T]OPOLOGICAL [P]RINT [H]ELP [Q]UIT
Acyclic: The command "Acyclic" should indicate whether or not the graph is acyclic.
An attempted topological sort of a non-acyclic (ie cyclic) graph should simply report that the graph is cyclic. A check of a cyclic graph should simply report that the graph is cyclic. See the assignment checker's second data set.
Personally, I found it easier to implement the function is_cyclic rather than is_acyclic (to reduce the need for negations). A graph has a topological sort iff it is acyclic. A graph is cyclic iff a DFS finds a back edge. How do you know if an edge is a back edge? Well, a few years ago you were precollege, now you are progressing through college, and soon (for some of you, about 11 weeks!) you will be done with college. (In case you didn't notice, that was a hint!)
Language and Platform: In general you should use a traditional, non-scripting language, but if you really want to use a scripting language, then I will consider that. So if you want to use a language other than Ada, C++, or Java then you should discuss your choice with me first. I will test your program on rucs, and so you should verify that it works correctly there. (Although if you want to use something exotic that's not on rucs, then I will at least consider that possibility.)
Submit a file called README.txt (case sensitive) that briefly describes the following:
Program Name, Program Execution, and Comments: You may name your program anything that you like. Give the commands needed for compiling and running in both the comments of your main routine and in the README.txt file that you submit along with your program.
No specific commenting style is required, except that your name should be in all files. You should of course make good use of white space, and your comments should help the reader by describing the purpose of routines and sections of your code and by explaining any non-obvious and/or interesting design and implementation decisions.
Input: Your program will have two input streams:
In standard input will be a sequence of commands (case insensitive):
Output: Output from your program will be in response to the commands that are read from standard input. The output for each command, and the output's format, should be similar to that of the sample run.
Graph Data Type: You are to implement a graph abstract data type similar to this one: graphs.ads. You do not have to implement exactly these routines, but they should provide you with a good starting point (and they are adequate for implementing the searches and check routines).
Program Submission:
Use a submit command on rucs similar to the one above. Submit all of your source code files and your README.txt
file. You may also submit your data files if you like.