예제 #1
0
def main(directory, algorithm, file_type='png',
         num_imgs=1, num_nodes=10, cell_length=10,
         start_color=[0, 0, 0], act_color=[25, 25, 25]):
    """Print a picture of a graph's traversal permutations."""
    
    start_color, act_color = [make_color(c) for c in (start_color, act_color)]
    nodes = range(1, num_nodes + 1)
    make_filename = filename_maker(directory, file_type)
    print_graph = graph_printer(algorithm, cell_length)
    
    for i in xrange(num_imgs):
        G = randobj.random_connected_graph(nodes)
        filename = make_filename(i, start_color, act_color)
        print_graph(G, start_color, act_color, filename=filename)
예제 #2
0
 def random_connected_graph(self):
     """A random choice from the set of connected graphs with at least n nodes."""
     
     # A random connected graph can be chosen by first picking a random spanning tree,
     # then choosing a random subset of edges uniformly from the set of edges not
     # included in the tree.
     
     min_n = self.config['min_n']
     max_n = self.config['max_n']
     sizes = range(min_n, max_n + 1)
     
     distribution = self.node_distribution()
     size = randobj.pick(sizes, distribution)
     nodes = range(1, size + 1)
     return randobj.random_connected_graph(nodes)