예제 #1
0
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)
예제 #2
0
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)
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
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)
예제 #6
0
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)
예제 #7
0
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)
예제 #8
0
def try_write(a, b):
    try:
        true = edges[(a, b)]
    except KeyError:
        edges[(a, b)] = True
        write_edge(a, b)
def try_write(a, b):
	try:
		true = edges[(a, b)]
	except KeyError:
		edges[(a, b)] = True
		write_edge(a, b)
예제 #10
0
#!/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
예제 #11
0
#!/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)

예제 #12
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])
예제 #13
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])