Created
May 12, 2012 12:45
-
-
Save huonw/2666360 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys, argparse | |
p = argparse.ArgumentParser() | |
p.add_argument('levels', type=int, help='height of tree') | |
p.add_argument('--procs', type=int, default=4,help='num processors') | |
p.add_argument('-d', type=float, default=0.999999,help='damper') | |
p.add_argument('--deg', type=int,default=2,help='degree of tree') | |
args = p.parse_args() | |
degree = args.deg | |
nlevels = args.levels | |
nprocs = args.procs | |
damper = args.d | |
if nlevels <= 1 or nprocs < 1 or not (0 <= damper < 1): | |
print >> sys.stderr, "Fail" | |
sys.exit(1) | |
def per_row(n): | |
return degree**n | |
pages = ['%d_%d' % (n,d) for n in xrange(nlevels) for d in xrange(per_row(n))] | |
npages = len(pages) | |
print nprocs | |
print damper | |
print npages | |
print '\n'.join(pages) | |
edges = [] | |
for n in xrange(0, nlevels - 1): | |
for d in xrange(per_row(n)): | |
edges.extend('%d_%d %d_%d' % (n, d, n + 1, k) for k in xrange(degree * d, degree * (d+1))) | |
for d in xrange(per_row(nlevels - 1)): | |
edges.append('%d_%d 0_0' % (nlevels - 1, d)) | |
print len(edges) | |
print '\n'.join(edges) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment