import networkx as nx import random eq = 1 lt = 2 gt = 4 d = 8 di = 16 o = 32 oi = 64 m = 128 mi = 256 s = 512 si = 1024 f = 2048 fi = 4096 DALL = 8191 B = [eq, lt, gt, d, di, o, oi, m, mi, s, si, f, fi] def translate(BR): if BR == eq: return '=' elif BR == lt: return '<' elif BR == gt: return '>' elif BR == d: return 'd' elif BR == di: return 'di' elif BR == o: return 'o' elif BR == oi: return 'oi' elif BR == m: return 'm' elif BR == mi: return 'mi' elif BR == s: return 's' elif BR == si: return 'si' elif BR == f: return 'f' elif BR == fi: return 'fi' def bitdecoding(b): l = [] if b in B: return [b] if b == DALL: return B[:] l = [i for i in B if b&i != 0 and i <=b] return l def makeconsistent(csp,size): st = [random.randint(1,71) for i in xrange(size)] en = [st[i] + random.randint(1,17) for i in xrange(size)] for i in csp: for j in csp[i]: if i == j: csp[i][j] |= eq elif (en[i] < st[j]): csp[i][j] |= lt elif (st[i] > en[j]): csp[i][j] |= gt elif (en[i] == st[j]): csp[i][j] |= m elif (st[i] == en[j]): csp [i][j] |= mi elif (st[i] > st[j] and en[i] < en[j]): csp[i][j] |= d elif (st[i] < st[j] and en[i] > en[j]): csp[i][j] |= di elif (st[i] == st[j] and en[i] < en[j]): csp[i][j] |= s elif (st[i] == st[j] and en[i] > en[j]): csp[i][j] |= si elif (st[i] > st[j] and en[i] == en[j]): csp[i][j] |= f elif (st[i] < st[j] and en[i] == en[j]): csp[i][j] |= fi elif (st[i] == st[j] and en[i] == en[j]): csp[i][j] |= eq elif (st[i] < st[j] and en[i] < en[j] and en[i] > st[j]): csp[i][j] |= o elif (st[i] > st[j] and en[i] > en[j] and st[i] < en[j]): csp[i][j] |= oi else: print "ERROR" bsplit = [bitdecoding(i+1) for i in xrange(8191)] import sys instances = int(sys.argv[1]) size = int(sys.argv[2]) p = int(sys.argv[3]) flag = 0 if len(sys.argv) == 5: flag = int(sys.argv[4]) for i in xrange(1,instances+1): G = nx.barabasi_albert_graph(size, p) csp = {} for v in xrange(size): j = {} j[v] = eq csp[v] = j print max(G.nodes())+1, '#' + str(i) + '-scale-free' for i in G.edges(): csp[i[0]][i[1]] = random.randint(1, 8191) if flag: makeconsistent(csp, size) for i in csp: for j in csp[i]: print i, j, '(', for r in bsplit[csp[i][j]-1]: print translate(r), print ')' print '.'