Mercurial > public > think_complexity
diff RegularGraphTest.py @ 5:8e44660965ef
Completed chapter 2, exercise 3 on regular graphs.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 01 Dec 2012 16:51:39 -0600 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RegularGraphTest.py Sat Dec 01 16:51:39 2012 -0600 @@ -0,0 +1,35 @@ +"""Tests our regular graph making abilities by displaying examples. + +""" +import string + +from Graph import Vertex, Graph, GraphError +from GraphWorld import GraphWorld, CircleLayout + +def main(script_name, n, k): + + # Attempt to create a regular graph of order n and degree k + + n, k = int(n), int(k) + + labels = string.ascii_lowercase + string.ascii_uppercase + vs = [Vertex(c) for c in labels[:n]] + + # create graph and layout + g = Graph(vs) + g.add_regular_edges(k) + layout = CircleLayout(g) + + # draw the graph + + gw = GraphWorld() + gw.show_graph(g, layout) + gw.mainloop() + + +if __name__ == '__main__': + import sys + try: + main(*sys.argv) + except GraphError, ex: + sys.stderr.write("GraphError: {}\n".format(ex))