def color_freq(vertices, coloring): res = priorityDictionary() for v in vertices: c = coloring[v] if c not in res: res[c] = 0 res[c] += 1 return res
def color_freq(vertices, coloring): res = priorityDictionary() for v in vertices: c = coloring[v] if c not in res: res[c] = 0 res[c] += 1 return res
def color_by_ordering(graph, vchoice, cchoice, upd=None): cols = Coloring() n = len(graph) usedCols = priorityDictionary() uncolored = set(graph.nodes) while len(uncolored) > 0: v = vchoice(uncolored, cols, graph) neighbourCols = {} for w in graph.neighbours(v): if w in cols: if cols[w] not in neighbourCols: neighbourCols[cols[w]] = 0 neighbourCols[cols[w]] += 1 cols[v] = cchoice(neighbourCols, usedCols) if cols[v] not in usedCols: usedCols[cols[v]] = 0 usedCols[cols[v]] += 1 uncolored.remove(v) if upd: upd(v, cols, usedCols, graph) return cols
def color_by_ordering(graph, vchoice, cchoice, upd=None): cols = Coloring() n = len(graph) usedCols = priorityDictionary() uncolored = set(graph.nodes) while len(uncolored) > 0: v = vchoice(uncolored, cols, graph) neighbourCols = {} for w in graph.neighbours(v): if w in cols: if cols[w] not in neighbourCols: neighbourCols[cols[w]] = 0 neighbourCols[cols[w]] += 1 cols[v] = cchoice(neighbourCols, usedCols) if cols[v] not in usedCols: usedCols[cols[v]] = 0 usedCols[cols[v]] += 1 uncolored.remove(v) if upd: upd(v, cols, usedCols, graph) return cols