Skip to content

Commit

Permalink
Trac #27079: acyclic_edge_coloring(Graph(3), k=None, value_only=True)…
Browse files Browse the repository at this point in the history
… should not be 2, should it?

I think that the correct value for
{{{
acyclic_edge_coloring(Graph(3), k=None, value_only=True)
}}}
should be 0, since there is nothing to color.

URL: https://trac.sagemath.org/27079
Reported by: mantepse
Ticket author(s): David Coudert
Reviewer(s): Martin Rubey
  • Loading branch information
Release Manager authored and vbraun committed Jan 26, 2019
2 parents d6e3539 + 2996f7a commit c40b052
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions src/sage/graphs/graph_coloring.py
Original file line number Diff line number Diff line change
Expand Up @@ -1524,11 +1524,39 @@ def acyclic_edge_coloring(g, hex_colors=False, value_only=False, k=0, solver=Non
sage: d = acyclic_edge_coloring(g, hex_colors=True)
sage: sorted(d)
['#0066ff', '#00ff66', '#cbff00', '#cc00ff', '#ff0000']
The acyclic chromatic index of a graph without edge is 0 (:trac:`27079`)::
sage: from sage.graphs.graph_coloring import acyclic_edge_coloring
sage: g = Graph(3)
sage: acyclic_edge_coloring(g, k=None, value_only=True)
0
sage: acyclic_edge_coloring(g, k=None, hex_colors=True)
{}
sage: acyclic_edge_coloring(g, k=None, hex_colors=False)
[]
Empty graph (:trac:`27079`)::
sage: from sage.graphs.graph_coloring import acyclic_edge_coloring
sage: acyclic_edge_coloring(Graph(), k=None, value_only=True)
0
"""
g._scream_if_not_simple(allow_multiple_edges=True)

from sage.rings.integer import Integer
from sage.combinat.subset import Subsets
from sage.plot.colors import rainbow

if not g.order() or not g.size():
if k == 0:
k = 2
if value_only:
return 0 if k is None else k
else:
if k is None:
return {} if hex_colors else []
return {c: [] for c in rainbow(k)} if hex_colors else [copy(g) for _ in range(k)]

if k is None:
k = max(g.degree())
Expand All @@ -1549,8 +1577,6 @@ def acyclic_edge_coloring(g, hex_colors=False, value_only=False, k=0, solver=Non
elif not k:
k = max(g.degree()) + 2

from sage.plot.colors import rainbow

p = MixedIntegerLinearProgram(solver=solver)

# c is a binary variable such that c[i,(u,v)] = 1 if and only if (u,v) is
Expand Down Expand Up @@ -1594,7 +1620,10 @@ def E(x, y):

except MIPSolverException:
if k == max(g.degree()) + 2:
raise RuntimeError("It looks like you have found a counterexample to a very old conjecture. Please do not loose it ! Please publish it, and send a post to sage-devel to warn us. We implore you!")
raise RuntimeError("It looks like you have found a counterexample to "
"a very old conjecture. Please do not loose it ! "
"Please publish it, and send a post to sage-devel "
"to warn us. We implore you!")
else:
raise ValueError("this graph can not be colored with the given number of colors")

Expand Down

0 comments on commit c40b052

Please sign in to comment.