Mercurial > public > think_complexity
annotate RegularGraphTest.py @ 24:5c2c4ce095ef
A stab at the L(p)/L(0) plot.
I still don't quite get how the graphs in the Watts and Strogatz paper were
generated. My results have basically the same shape, but don't converge to 0.
I'm not sure how this is possible if the rewire function does not remove edges.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 03 Jan 2013 18:41:13 -0600 |
parents | 8e44660965ef |
children |
rev | line source |
---|---|
bgneal@5 | 1 """Tests our regular graph making abilities by displaying examples. |
bgneal@5 | 2 |
bgneal@5 | 3 """ |
bgneal@5 | 4 import string |
bgneal@5 | 5 |
bgneal@5 | 6 from Graph import Vertex, Graph, GraphError |
bgneal@5 | 7 from GraphWorld import GraphWorld, CircleLayout |
bgneal@5 | 8 |
bgneal@5 | 9 def main(script_name, n, k): |
bgneal@5 | 10 |
bgneal@5 | 11 # Attempt to create a regular graph of order n and degree k |
bgneal@5 | 12 |
bgneal@5 | 13 n, k = int(n), int(k) |
bgneal@5 | 14 |
bgneal@5 | 15 labels = string.ascii_lowercase + string.ascii_uppercase |
bgneal@5 | 16 vs = [Vertex(c) for c in labels[:n]] |
bgneal@5 | 17 |
bgneal@5 | 18 # create graph and layout |
bgneal@5 | 19 g = Graph(vs) |
bgneal@5 | 20 g.add_regular_edges(k) |
bgneal@5 | 21 layout = CircleLayout(g) |
bgneal@5 | 22 |
bgneal@5 | 23 # draw the graph |
bgneal@5 | 24 |
bgneal@5 | 25 gw = GraphWorld() |
bgneal@5 | 26 gw.show_graph(g, layout) |
bgneal@5 | 27 gw.mainloop() |
bgneal@5 | 28 |
bgneal@5 | 29 |
bgneal@5 | 30 if __name__ == '__main__': |
bgneal@5 | 31 import sys |
bgneal@5 | 32 try: |
bgneal@5 | 33 main(*sys.argv) |
bgneal@5 | 34 except GraphError, ex: |
bgneal@5 | 35 sys.stderr.write("GraphError: {}\n".format(ex)) |