コード例 #1
0
def is_stable(coloring):
    for color_class in coloring.colors():
        v = coloring[color_class][0]
        for u in coloring[color_class][1:]:
            if not checkNeighbourhood(u, v):
                return False
    return True
コード例 #2
0
 def isStable(self):
     for color_class in self.colors():
         v = self.__colors[color_class][0]
         for u in self.__colors[color_class][1:]:
             if not checkNeighbourhood(u, v):
                 return False
     return True
コード例 #3
0
def getColoring(G):
    alpha = coloring()
    highestDegree = -1
    for v in G.V():
        alpha.put(v.get_degree(), v)
        if highestDegree < v.get_color_num():
            highestDegree = v.get_color_num()
    changed = True
    buffer = alpha
    # De colour refinement:
    while changed:
        changed = False
        alpha = buffer.deepcopy()
        for color in alpha.colors():
            colour_list = buffer.get(color)
            if len(colour_list) > 1:
                changelist = []
                u = colour_list[0]
                for v in colour_list[1:]:
                    if not checkNeighbourhood(u, v):
                        changed = True
                        changelist.append(v)
                for v in changelist:
                    buffer.move(v, highestDegree + 1)
                if changed:
                    highestDegree += 1
    return buffer
コード例 #4
0
def coloring_refinement(coloring, highest_degree = -1):
    if highest_degree == -1:
        for key in coloring.keys():
            if key > highest_degree:
                highest_degree = key
    changed = True
    while changed:
        changed = False
        for colour_list in get_color_classes(coloring):
            change_list = []
            u = colour_list[0]
            for v in colour_list[1:]:
                if not checkNeighbourhood(u, v):
                    changed = True
                    change_list.append(v)
            move_all(coloring, change_list, highest_degree + 1)
            if changed:
                highest_degree += 1
    return coloring
コード例 #5
0
def get_coloring(G):
    alpha = dict()
    highest_degree = -1
    for v in G.V():
        put(alpha, v.get_degree(), v)
        if highest_degree < v.get_color_num():
            highest_degree = v.get_color_num()
    changed = True
    # De colour refinement:
    while changed:
        changed = False
        for colour_list in get_color_classes(alpha):
            change_list = []
            u = colour_list[0]
            for v in colour_list[1:]:
                if not checkNeighbourhood(u, v):
                    changed = True
                    change_list.append(v)
            move_all(alpha, change_list, highest_degree + 1)
            if changed:
                highest_degree += 1
    return alpha, len(G.V())
コード例 #6
0
def getColoring2(G):
    alpha = coloring()
    highestDegree = -1
    for v in G.V():
        alpha.put(v.get_degree(), v)
        if highestDegree < v.get_color_num():
            highestDegree = v.get_color_num()
    changed = True
    # De colour refinement:
    while changed:
        changed = False
        for colour_list in alpha.getColorClasses():
            change_list = []
            u = colour_list[0]
            for v in colour_list[1:]:
                if not checkNeighbourhood(u, v):
                    changed = True
                    change_list.append(v)
            alpha.moveAll(change_list, highestDegree + 1)
            if changed:
                highestDegree += 1
    return alpha