Exemplo n.º 1
0
def coloring(G):

	verts = set()

	for vertex in G.V():
		vertex.oldcolor = len(vertex.nbs())
		vertex.newcolor = len(vertex.nbs())
		verts.add(vertex)

	print(verts)
	colordict = dict()

	for v in verts:
		if len(colordict) > 0:
			for key in colordict.keys():
				if key == v.oldcolor:
					if len(colordict[key]) > 0:
						colordict[key].add(v)
						print("append")
					else:
						colordict[key] = set().add(v)
						break
			colordict[v.oldcolor] = set().add(v)
		else:
			colordict[v.oldcolor] = set().add(v)
	print(colordict)


	for vertexi in G.V():
		print("Meer dingen")
		vertexi.colornum = vertexi.oldcolor
	writeDOT(G, "Test.dot")
Exemplo n.º 2
0
def drawProgress(G, v, color, done, queue=None):
    global fileNum
    for vv in G.V():
        vv.colornum = -1
    for dv in done:
        dv.colornum = 1
    if queue:
        for c in queue:
            if type(c) == tuple:
                vertex, p = c
                vertex.colornum = 4
            else:
                for cv in c:
                    cv.colornum = 4
    for cv in color:
        cv.colornum = 2
    if v:
        v.colornum = 3
    writeDOT(G, "progress%i.dot" % fileNum)
    fileNum += 1
Exemplo n.º 3
0
                lenghts[i],
                lenghts[groupStartIndices[groupI]],
                a,
            ):
                groups[groupI].append(g)
                placed = True
                break
        # if our graph is not yet placed, it belongs to a new group
        if not placed:
            groups.append([g])
            groupStartIndices.append(i)
        i += 1

    for graphI in range(len(graphList)):
        for i in range(len(graphList[graphI].V())):
            graphList[graphI].V()[i].colornum = G.V()[startIndices[graphI] + i].colornum

    return groups, G


if __name__ == "__main__":
    gl = loadgraph("./../data/colorref_smallexample_4_7.grl", readlist=True)

    i = 0
    groups, G = getAllIsomorphisms(gl[0])
    graphIO.writeDOT(G, "./output.dot")
    for group in groups:
        print("Group with size: ", len(group))
        graphIO.writeDOT(group[0], "./output%i.dot" % i)
        i += 1
Exemplo n.º 4
0
            v.nbnum=tuple(sorted([i.colornum for i in v.nbs()])) # Determine neighbour coloring
    l=0
    while len(set(v.nbnum for v in G.V()))!=l:  # While partition is refined
        k=0 # First color number
        l=(len(set(v.nbnum for v in G.V())))
        for i in set(v.nbnum for v in G.V()): # Loops along all different sorts of neighbour sets
            for v in G.V():       # Colors numbers with same colored neighbours the same
                if v.nbnum==i:    #
                    v.colornum=k  #
            k+=1                  #
        for v in G.V():
            v.nbnum=tuple(sorted([i.colornum for i in v.nbs()])) # Determine new neighbour coloring
    return G


if __name__ == "__main__":
    begin=time()
    G=loadgraph("./colorref_largeexample_4_1026.grl",readlist=True)
    colorref(G[0][0])
    writeDOT(G[0][0],"bla")
    end=time()
    print(end-begin)

    begin=time()
    G=loadgraph("./colorref_smallexample_4_16.grl",readlist=True)
    colorref(G[0][1])
    writeDOT(G[0][1],"bla")
    end=time()
    print(end-begin)

Exemplo n.º 5
0
from utilities.graphUtil import createGraph
from week1.colorRefinement import refineColorsv2
from week3.gSnellerPartitioning import generatePartitions, writeColors

def generateTree(length):
    G = graph(length)
    done = {G.V()[0]}
    c = 0
    for i in range(1, len(G.V())):
        G.addedge(G.V()[i], G.V()[int((10000.0*time.time()+c)%i)])
        c += 1
        done.add(G.V()[i])
    return G

def createSimpleExample():
    return createGraph(11, [(0,4), (1,4), (4,6), (2, 5 ), (3,5), (5,6), (6,7), (7,8), (8,9), (8,10)])

# g = createGraph(22, [(0,2), (1,2), (2,9), (3,5), (4,5), (5,9), (6,8), (7,8), (8,9),
#                     (9, 10), (10, 11), (11, 12), (11, 13), (11,14), (13, 15), (10, 16), (10, 17), (17, 18), (17, 19), (17,20), (20,21)])

#g = createGraph(10, [(0,1), (1,2), (2,3), (3,4), (4,5), (0,6), (0,7), (5,8), (5,9)])
g = generateTree(3000)
# writeDOT(g, "testTree.dot")
# g.V()[2] = None
p = generatePartitions(g)
# refineColorsv2(g)5
print(countTreeAutomorphismsLS(g, True))
print(countTreeAutomorphismsRS(g, True))
writeColors(p)
writeDOT(g, "testTree.dot")
Exemplo n.º 6
0
                                else:
                                    w.add(len(p) - 1)
    return p


def writeColors(partitions):
    for i in range(len(partitions)):
        for v in partitions[i]:
            v.colornum = i


if __name__ == "__main__":
    from utilities.graphIO import loadgraph, writeDOT
    from trees.automorphismsCounter import countTreeAutomorphismsLS, countTreeAutomorphismsRS

    gl = loadgraph("./../data/trees90.grl", readlist=True)
    #gl = [[disjointUnionMulti([createCycleGraph(3), createCycleGraph(3)]), createCycleGraph(7), createCycleGraph(6)]]
    i = 0
    g = gl[0][0]
    # g = loadgraph("./../data/threepaths10240.gr")
    t = time.time()
    p = generatePartitions(g)
    print(time.time() - t)
    print(p)
    writeColors(p)
    print("Goed?: ", countTreeAutomorphismsLS(g))
    print("Goed?: ", countTreeAutomorphismsRS(g))


    writeDOT(g, "output.dot")