コード例 #1
0
ファイル: coloring.py プロジェクト: Destion/Projectmod7
    def refineColors(self, g1, g2):
        """
        Refines the colors with the graphs
        :param g1: graph1
        :param g2: graph2
        :return: Nothing, this function acts on the current object
        """
        if self.refined:
            print("Warning! Refining a ColorCombination that is already flagged as refined!")
        self.applyToGraphs(g1, g2)
        g = disjointUnionMulti([g1, g2], True)

        p = generatePartitions(g, True)
        newColoring = dict()
        for c in range(len(p)):
            for v in p[c]:
                newColoring[v] = c

        # newColoring = refineColorsv2(g, True)

        newColoringG1 = dict()
        gV = g.V()
        g1V = g1.V()
        for i in range(len(g1V)):
            newColoringG1[g1V[i]] = newColoring[gV[i]]

        newColoringG2 = dict()
        g2V = g2.V()
        for i in range(len(g2V)):
            newColoringG2[g2V[i]] = newColoring[gV[i + len(g1V)]]

        self.generateCoreValues(newColoringG1, newColoringG2, True)
コード例 #2
0
def getAllIsomorphisms(graphList, useColornums=False):
    # Make a list of groups
    groups = [[graphList[0]]]

    # these lists hold indices of our graphs in the vertex list of our union graph and the lengths of the vertex lists
    groupStartIndices = [0]
    startIndices = [0]
    lenghts = [len(graphList[0].V())]

    for g in graphList:
        startIndices.append(startIndices[-1] + lenghts[-1])
        lenghts.append(len(g.V()))

    # create one gaint graph containing all the graphs in our graphlist
    G = disjointUnionMulti(graphList, useColornums)

    # execute the refineColors function on our union graph
    a = refineColorsv2(G, useColornums)
    i = 1

    # fill the groups based on our new color data
    for g in graphList[1:]:

        # this boolean indicates whether the current graph has been placed in a group
        placed = False
        for groupI in range(len(groups)):
            if areIsomorph(
                G,
                startIndices[i],
                startIndices[groupStartIndices[groupI]],
                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