# HG changeset patch
# User Nathann Cohen <nathann.cohen@gmail.com>
# Date 1272370432 7200
# Node ID 3ffb58d8c602e90a7f446f31d1544128878190ad
# Parent ef74a6ed21179df343f658c015d7b068bb28c0f3
trac #8781 : is_overfull and update to edge_coloring
diff r ef74a6ed2117 r 3ffb58d8c602 sage/graphs/generic_graph.py
a

b


1783  1783  return False 
1784  1784  return True 
1785  1785  
 1786  def is_overfull(self): 
 1787  r""" 
 1788  Tests whether the current graph is overfull. 
 1789  
 1790  A graph `G` on `n` vertices and `m` edges is said to 
 1791  be overfull if : 
 1792  
 1793   `n` is odd 
 1794  
 1795   It satisfies `2m > (n1)\Delta(G)`, where 
 1796  `\Delta(G)` denotes the maximal degree of 
 1797  a vertex in `G` 
 1798  
 1799  An overfull graph must have a chromatic index of `\Delta(G)+1`. 
 1800  
 1801  EXAMPLE: 
 1802  
 1803  A complete graph is overfull if and only if its number 
 1804  of vertices is odd:: 
 1805  
 1806  sage: graphs.CompleteGraph(6).is_overfull() 
 1807  False 
 1808  sage: graphs.CompleteGraph(7).is_overfull() 
 1809  True 
 1810  
 1811  The Petersen Graph, though, is not overfull while 
 1812  its chromatic index is `\Delta+1`:: 
 1813  
 1814  sage: g = graphs.PetersenGraph() 
 1815  sage: g.is_overfull() 
 1816  False 
 1817  sage: from sage.graphs.graph_coloring import edge_coloring 
 1818  sage: max(g.degree()) + 1 == edge_coloring(g, value_only=True) # optional  requires GLPK CBC or CPLEX 
 1819  True 
 1820  """ 
 1821  
 1822  return (self.order() % 2 == 1) and \ 
 1823  (2*self.size() > max(self.degree())*(self.order()1)) 
 1824  
1786  1825  def order(self): 
1787  1826  """ 
1788  1827  Returns the number of vertices. Note that len(G) returns the number 
diff r ef74a6ed2117 r 3ffb58d8c602 sage/graphs/graph_coloring.py
a

b


506  506  graph, and this is not the easiest way. By Vizing's theorem, a graph 
507  507  has a chromatic index equal to `\Delta` or to `\Delta + 1`. 
508  508  
 509  .. NOTE:: 
 510  
 511  In a few cases, it is possible to find very quickly the chromatic 
 512  index of a graph, while it remains a tedious job to compute 
 513  a corresponding coloring. For this reason, ``value_only = True`` 
 514  can sometimes be much faster, and it is a bad idea to compute 
 515  the whole coloring if you do not need it ! 
 516  
509  517  EXAMPLE:: 
510  518  
511  519  sage: from sage.graphs.graph_coloring import edge_coloring 
… 
… 

525  533  
526  534  if g.is_clique(): 
527  535  if value_only: 
528   return g.order() if g.order() % 2 == 0 else g.order() + 1 
 536  return g.order()1 if g.order() % 2 == 0 else g.order() 
529  537  vertices = g.vertices() 
530  538  r = round_robin(g.order()) 
531  539  classes = [[] for v in g] 
… 
… 

538  546  else: 
539  547  return classes 
540  548  
 549  if value_only and g.is_overfull(): 
 550  return max(g.degree())+1 
 551  
541  552  p = MixedIntegerLinearProgram(maximization=True) 
542  553  color = p.new_variable(dim=2) 
543  554  obj = {} 