chromatic_polynomial#
- graph_tool.structure.chromatic_polynomial(g)[git][source]#
Return the chromatic polynomial of a graph.
- Parameters:
- g
Graph Graph to be used. Edge directions are ignored.
- g
- Returns:
- P
numpy.ndarray The coefficients, where
P[i]is the coefficient of \(k^i\).
- P
See also
tutte_polynomialTutte polynomial
sequential_vertex_coloringGreedy vertex coloring
Notes
The chromatic polynomial [birkhoff-determinant-1912] [read-introduction-1968] \(P_G(k)\) is the number of proper colorings of the vertices with \(k\) colors, i.e. those in which the endpoints of every edge have different colors. It is obtained from the Tutte polynomial as
\[P_G(k) = (-1)^{|V|-c}\,k^c\,T_G(1-k, 0),\]where \(c\) is the number of connected components, with \(T_G(x, 0)\) computed as in
tutte_polynomial(), but with parallel edges reduced to single ones and the complete blocks evaluated directly. The polynomial vanishes for graphs with self-loops. The time is exponential in the number of edges.The polynomial can be evaluated with
numpy.polynomial.polynomial.polyval().References
[birkhoff-determinant-1912]George D. Birkhoff, “A determinant formula for the number of ways of coloring a map”, Annals of Mathematics 14, 42-46 (1912), DOI: 10.2307/1967597 [sci-hub, @tor]
[read-introduction-1968]Ronald C. Read, “An introduction to chromatic polynomials”, Journal of Combinatorial Theory 4, 52-71 (1968), DOI: 10.1016/S0021-9800(68)80087-0 [sci-hub, @tor]
Examples
>>> g = gt.circular_graph(5) >>> P = gt.chromatic_polynomial(g) >>> print(P) [ 0 4 -10 10 -5 1] >>> print(np.polynomial.polynomial.polyval(3, P)) # 3-colorings 30.0