Ejemplo n.º 1
0
def test_add_node2(n):
    # generate some random strings
    import random
    import digraph
    letters = 'abcdefghijklm'
    strings = []
    for _ in range(n):
        samp_size = random.randint(1, 10)
        strings.append(''.join(sorted(random.sample(letters, samp_size))))
    g = digraph.DirectedGraph()

    def func(v, w):
        if set(v).issubset(set(w)) and len(v) < len(w):
            return True
        elif set(v).issuperset(set(w)) and len(v) > len(w):
            return False
        return None

    for s in strings:
        try:
            maintain_reduction_add_node(g, s, func)
        except:
            print
            print 'strings', strings
            print
            raise
    to_file(g, '/home/duncan/add_node_2.png')
    return g
Ejemplo n.º 2
0
def test_add_node(n):
    # generate some random strings
    import random
    import digraph
    letters = 'abcdefghijklmnopqrstuvwxyz'
    strings = []
    for _ in range(n):
        strings.append(''.join(random.sample(letters, 6)))
    g = digraph.DirectedGraph()

    def func(v, w):
        if v[0] == w[0]:
            return None
        return v[0] < w[0]

    for s in strings:
        try:
            maintain_reduction_add_node(g, s, func)
        except:
            print
            print 'strings', strings
            print
            raise
    to_file(g, '/home/duncan/add_node.png')
    return g
Ejemplo n.º 3
0
    def setUp(self):
        self.g = digraph.DirectedGraph(range(6))

        self.g.add_edge(0, 1)
        self.g.add_edge(0, 2)
        self.g.add_edge(0, 4)
        self.g.add_edge(2, 3)
        self.g.add_edge(3, 4)
        self.g.add_edge(4, 0)
Ejemplo n.º 4
0
def tree2file(tree, filename):
    import dot
    import digraph
    g = digraph.DirectedGraph()
    for node in tree:
        g.addNode(node)
    for node in tree:
        parent = tree[node]
        if parent:
            g.addEdge((parent, node))
    dot.graph2image(g, filename, True, filename[-3:])