I would like Sage to compute the number of all $5$-colorings of graphs on $2k$ vertices and $k^2$ edges with clique number 3 for a specified $k \geq 1$.
I know how to ask call nauty and ask sage to generate, for example, all graphs on $2k=8$ and $k^2=16$ vertices with clique number $3$:
g8 = [g for g in graphs.nauty_geng('8 16') if g.clique_number() == 3]
Is there a way to obtain a list of the number of $5$-colorings of all of these graphs? If not, could I at least obtain their chromatic polynomials? Then I could have them evaluated at $5$.
Thank you in advance for your help.
Best Answer
Yes, you can obtain the numbers by number_of_n_colorings:
The result is the same as evaluating the chromatic polynomials at $5$:
You can also obtain all the colorings by using all_graph_colorings:
The first coloring of the first graph is as follows:
The keys in the dictionary are the colors and the values are the lists of vertices with that color (see the
vertex_color_dict
argument ofall_graph_colorings
if you want the output the other way around). Hencecolorings[0][0].values()
is the partition of the vertex set into colors. We can use this partition to plot the graph with colors:Also, the list of all colorings agrees with the list of numbers obtained earlier: