Mercurial > public > think_complexity
comparison 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 |
comparison
equal
deleted
inserted
replaced
4:9d0cf96b6a3b | 5:8e44660965ef |
---|---|
1 """Tests our regular graph making abilities by displaying examples. | |
2 | |
3 """ | |
4 import string | |
5 | |
6 from Graph import Vertex, Graph, GraphError | |
7 from GraphWorld import GraphWorld, CircleLayout | |
8 | |
9 def main(script_name, n, k): | |
10 | |
11 # Attempt to create a regular graph of order n and degree k | |
12 | |
13 n, k = int(n), int(k) | |
14 | |
15 labels = string.ascii_lowercase + string.ascii_uppercase | |
16 vs = [Vertex(c) for c in labels[:n]] | |
17 | |
18 # create graph and layout | |
19 g = Graph(vs) | |
20 g.add_regular_edges(k) | |
21 layout = CircleLayout(g) | |
22 | |
23 # draw the graph | |
24 | |
25 gw = GraphWorld() | |
26 gw.show_graph(g, layout) | |
27 gw.mainloop() | |
28 | |
29 | |
30 if __name__ == '__main__': | |
31 import sys | |
32 try: | |
33 main(*sys.argv) | |
34 except GraphError, ex: | |
35 sys.stderr.write("GraphError: {}\n".format(ex)) |