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?
2 | No.2 Revision |
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?
3 | No.3 Revision |
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?
4 | No.4 Revision |
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}')