Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The question is quite fuzzy and here is my best guess to interpret it:

from sage.graphs.graph_coloring import first_coloring
G = graphs.WheelGraph(5)
d=first_coloring(G, 5)
d_set = [set(c) for c in d]  # color classes as sets

color_code = {}
for i in G.vertices():
    col = next(k for k in range(len(d_set)) if i in d_set[k])    # color of i as index in d_set
    N = set(G.neighbors(i))
    color_code[i] = (col, tuple(len(N & c) for c in d_set))

print(color_code)

Is this what you want?

The question is quite fuzzy and here is my best guess to interpret it:

from sage.graphs.graph_coloring import first_coloring
G = graphs.WheelGraph(5)
d=first_coloring(G, 5)
d_set = [set(c) for c in d]  # color classes as sets

color_code = {}
for i in G.vertices():
    col = next(k for k in range(len(d_set)) if i in d_set[k])  # color of i as index in d_set
    N = set(G.neighbors(i))
    color_code[i] = (col, tuple(len(N & c) for c in d_set))

print(color_code)

Is this what you want?

The question is quite fuzzy and here is my best guess to interpret for interpreting it:

from sage.graphs.graph_coloring import first_coloring
G = graphs.WheelGraph(5)
d=first_coloring(G, 5)
d_set = [set(c) for c in d]  # color classes as sets

color_code = {}
for i in G.vertices():
    col = next(k for k in range(len(d_set)) if i in d_set[k]) # color of i as index in d_set
    N = set(G.neighbors(i))
    color_code[i] = (col, tuple(len(N & c) for c in d_set))

print(color_code)

Is this what you want?

The question is quite fuzzy and here is my best guess for interpreting it:

from sage.graphs.graph_coloring import first_coloring
G = graphs.WheelGraph(5)
d=first_coloring(G, 5)
d_set = [set(c) for c in d]  # color classes as sets

color_code = {}
for i in G.vertices():
    col = next(k for k in range(len(d_set)) if i in d_set[k]) # color of i as index in d_set
    N = set(G.neighbors(i))
    color_code[i] = (col, tuple(len(N & c) for c in d_set))

print(color_code)

Is this what you want?


ADDED. Similarly we can compute color code for each of the colorings:

from sage.graphs.graph_coloring import all_graph_colorings
G = Graph({0: [1, 2, 3], 1: [2]})
G = graphs.WheelGraph(5)

for m,d in enumerate(all_graph_colorings(G,5)):
    d_set = [set(c) for c in d.values()]

    color_code = {}
    for i in G.vertices():
        col = next(k for k in range(len(d_set)) if i in d_set[k]) 
        N = set(G.neighbors(i))
        color_code[i] = (col, tuple(len(N & c) for c in d_set))

    print(f'coloring # {m}\tcode: {color_code}')