Exemplo n.º 1
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.º 2
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.º 3
0
					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")


def neighbourcolor(x, y):
	if len(x.nbs()) != len(y.nbs()):
		return False
	temp1 = set()
	temp2 = set()
	for vx in x.nbs():
		temp1.add(vx.oldcolor)
	for vy in y.nbs():
		temp2.add(vy.oldcolor)
	print(temp1==temp2)
	return temp1 == temp2


G = loadgraph("colorref_smallexample_4_7.grl")

coloring(G)
Exemplo n.º 4
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")
Exemplo n.º 5
0
    print("\n\n")
    if automorphisms:
        print(str1, " Automorphisms:")
    else:
        print(str1)
    for group in isomorphisms:
        str2 = str([gl.index(g) for g in group])
        if automorphisms:
            print(str2, " " * (len(str1) - len(str2)), automorphisms[group[0]])
        else:
            print(str2)


def getIsomorphismGroups(graphList, aut = False):
    """[gl.index(g) for g in group]
    The full algorithm that converts a list of graphs to a list of groups of isomorphic graphs
    The outcome contains all elements of the input, in isomorphic groups. Every graph in a group is isomorphic with
    every other graph in the groups.
    :param graphList: A list of graphs
    :return: A list containing smaller list. The smaller lists are groups of isomorphic graphs.
    """
    groups, G = getAllIsomorphisms(graphList)
    further, automorphisms = refineFurther(groups, aut)
    output(graphList, further, automorphisms)
    return further

if __name__ == "__main__":
    gl = loadgraph("./../data/bigtrees1.grl", readlist=True)
    # gl = [[disjointUnionMulti([createCycleGraph(1), createCycleGraph(1)]), createCycleGraph(2), createCycleGraph(2)]]
    getIsomorphismGroups(gl[0], True)