def write_conn(id1, id2, w): global WRITE_INOUT if WRITE_INOUT: print "!output(@" + str(id1) + ", @" + str(id2) + ", " + str(w) + ")." print "!input(@" + str(id2) + ", @" + str(id1) + ", " + str(w) + ")." else: write_edge(id1, id2)
def generate_tree(root, levels): if levels == 0: return left = get_id() right = get_id() write_edge(root, left) write_edge(root, right) generate_tree(left, levels - 1) generate_tree(right, levels - 1)
def write_pyramid(depth, z): if depth == 1: write_edge(z, z + 1) else: write_edge(z, z + 1) write_edge(z, z + 2) write_edge(z + 1, z + 3) write_pyramid(depth - 1, z + 2)
def write_pyramid(depth, z): if depth == 1: write_edge(z, z+1) else: write_edge(z, z+1) write_edge(z, z+2) write_edge(z+1, z+3) write_pyramid(depth - 1, z + 2)
def write_line(line): for column in range(0, width): id = line * width + column if line < height - 1: southid = id + width write_edge(southid, id) write_edge(id, southid) if column < width - 1: eastid = id + 1 write_edge(eastid, id) write_edge(id, eastid)
def write_line(line): for column in range(0, width): id = line * width + column if line < height-1: southid = id + width write_edge(southid, id) write_edge(id, southid) if column < width-1: eastid = id + 1 write_edge(eastid, id) write_edge(id, eastid)
def try_write(a, b): try: true = edges[(a, b)] except KeyError: edges[(a, b)] = True write_edge(a, b)
#!/usr/bin/python import sys from lib import write_edge from lib import set_weight if len(sys.argv) < 2: print "Usage: generate_chain.py <num nodes> [weight]" sys.exit(1) if len(sys.argv) == 3: set_weight(int(sys.argv[2])) print "type route edge(node, node, int)." else: print "type route edge(node, node)." previous = 0 for i in range(1, int(sys.argv[1])): new = i write_edge(previous, new) previous = new
#!/usr/bin/python import sys from lib import write_edge from lib import set_weight if len(sys.argv) < 2: print "Usage: generate_cycle.py <num nodes> [weight]" sys.exit(1) if len(sys.argv) == 3: set_weight(int(sys.argv[2])) print "type route edge(node, node, int)." else: print "type route edge(node, node)." previous = 0 for i in range(1, int(sys.argv[1])): new = i write_edge(previous, new) previous = new write_edge(previous, 0)
#!/usr/bin/python # # Transforms files from http://snap.stanford.edu/data # into Meld edge fact files. # import sys from lib import write_edge from lib import set_weight if len(sys.argv) < 2: print "Usage: stanford-snap.py <file> [distance]" sys.exit(1) if len(sys.argv) == 3: set_weight(int(sys.argv[2])) else: set_weight(1) f = open(sys.argv[1], "rb") print "type route edge(node, node, int)." for line in f: if line[0] == '#': continue vec = line.rstrip().split('\t') write_edge(vec[0], vec[1])