import networkx as nx import random DC = 1 EC = 2 PO = 4 TPP = 8 NTPP = 16 TPPI = 32 NTPPI = 64 EQ = 128 DALL = 255 B = [DC , EC , PO , TPP , NTPP , TPPI , NTPPI , EQ] def translate(BR): if BR == DC: return 'DC' if BR == EC: return 'EC' if BR == PO: return 'PO' if BR == TPP: return 'TPP' if BR == TPPI: return 'TPPI' if BR == NTPP: return 'NTPP' if BR == NTPPI: return 'NTPPI' if BR == EQ: return 'EQ' 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): s = [random.randint(1,71) for i in xrange(size)] e = [s[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 if e[i] < s[j] or e[j] < s[i]: csp[i][j] |= DC elif e[i] == s[j] or e[j] == s[i]: csp[i][j] |= EC elif s[i] > s[j] and e[i] < e[j]: csp[i][j] |= NTPP elif s[i] < s[j] and e[i] > e[j]: csp[i][j] |= NTPPI elif s[i] == s[j] and e[i] < e[j]: csp[i][j] |= TPP elif s[i] == s[j] and e[i] > e[j]: csp[i][j] |= TPPI elif s[i] > s[j] and e[i] == e[j]: csp[i][j] |= TPP elif s[i] < s[j] and e[i] == e[j]: csp[i][j] |= TPPI elif s[i] == s[j] and e[i] == e[j]: csp[i][j] |= EQ elif s[i] < s[j] and e[i] < e[j] and e[i] > s[j]: csp[i][j] |= PO elif s[i] > s[j] and e[i] > e[j] and s[i] < e[j]: csp[i][j] |= PO else: print "ERROR" bsplit = [(bitdecoding(i+1)) for i in xrange(255)] import sys instances = int(sys.argv[1]) size = int(sys.argv[2]) m = 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, m) 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, 255) 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 '.'