view RegularGraphTest.py @ 42:039249efe42f

Chapter 6, exercise 2, #4. Wrote a program to output the center column of a rule 30 CA as a stream of bytes. It is very slow though. It has to run a very long time to produce enough data for dieharder. Committing it now but will have to let it run overnight or something to generate a large file.
author Brian Neal <bgneal@gmail.com>
date Sun, 13 Jan 2013 16:24:00 -0600
parents 8e44660965ef
children
line wrap: on
line source
"""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))