# HG changeset patch
# User Nathann Cohen <nathann.cohen@gmail.com>
# Date 1306762566 7200
# Node ID d45356c3d4b63c837f9894d31d70817082850376
# Parent 52d48773b4d299d2ad00f1a82c73d58494a1848a
trac 10497  Density test in Graph.traveling_salesman_problem
diff r 52d48773b4d2 r d45356c3d4b6 sage/graphs/generic_graph.py
a

b


4907  4907  return g 
4908  4908  
4909  4909  
4910   def traveling_salesman_problem(self, weighted = True, solver = None, constraint_generation = True, verbose = 0, verbose_constraints = False): 
 4910  def traveling_salesman_problem(self, weighted = True, solver = None, constraint_generation = None, verbose = 0, verbose_constraints = False): 
4911  4911  r""" 
4912  4912  Solves the traveling salesman problem (TSP) 
4913  4913  
… 
… 

4938  4938  :class:`MixedIntegerLinearProgram <sage.numerical.mip.MixedIntegerLinearProgram>`. 
4939  4939  
4940  4940   ``constraint_generation`` (boolean)  whether to use constraint 
4941   generation when solving the Mixed Integer Linear Program (default: 
4942   ``True``). 
 4941  generation when solving the Mixed Integer Linear Program. 
 4942  
 4943  When ``constraint_generation = None``, constraint generation is used 
 4944  whenever the graph has a density larger than 70%. 
4943  4945  
4944  4946   ``verbose``  integer (default: ``0``). Sets the level of 
4945  4947  verbosity. Set to 0 by default, which means quiet. 
… 
… 

4993  4995  sage: tsp = g.traveling_salesman_problem() 
4994  4996  Traceback (most recent call last): 
4995  4997  ... 
4996   ValueError: The given graph is not Hamiltonian 
 4998  ValueError: The given graph is not hamiltonian 
 4999  
4997  5000  
4998  5001  One easy way to change is is obviously to add to this graph the edges 
4999  5002  corresponding to a Hamiltonian cycle. 
… 
… 

5071  5074  ... break 
5072  5075  
5073  5076  """ 
 5077  if constraint_generation is None: 
 5078  if self.density() > .7: 
 5079  constraint_generation = False 
 5080  else: 
 5081  constraint_generation = True 
 5082  
5074  5083  ############################### 
5075   # Quick cheks of connectivity # 
 5084  # Quick checks of connectivity # 
5076  5085  ############################### 
5077  5086  
5078  5087  # TODO : Improve it by checking vertexconnectivity instead of 
… 
… 

5411  5420  sage: g.hamiltonian_cycle() 
5412  5421  Traceback (most recent call last): 
5413  5422  ... 
5414   ValueError: The given graph is not Hamiltonian 
 5423  ValueError: The given graph is not hamiltonian 
5415  5424  
5416  5425  Now, using the backtrack algorithm in the Heawood graph :: 
5417  5426  