Ticket #10497: trac_10497-density.patch

File trac_10497-density.patch, 2.7 KB (added by ncohen, 10 years ago)
  • sage/graphs/generic_graph.py

    # 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  
    49074907            return g
    49084908
    49094909
    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):
    49114911        r"""
    49124912        Solves the traveling salesman problem (TSP)
    49134913
     
    49384938          :class:`MixedIntegerLinearProgram <sage.numerical.mip.MixedIntegerLinearProgram>`.
    49394939
    49404940        - ``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%.
    49434945
    49444946        - ``verbose`` -- integer (default: ``0``). Sets the level of
    49454947          verbosity. Set to 0 by default, which means quiet.
     
    49934995            sage: tsp = g.traveling_salesman_problem()
    49944996            Traceback (most recent call last):
    49954997            ...
    4996             ValueError: The given graph is not Hamiltonian
     4998            ValueError: The given graph is not hamiltonian
     4999
    49975000
    49985001        One easy way to change is is obviously to add to this graph the edges
    49995002        corresponding to a Hamiltonian cycle.
     
    50715074            ...           break
    50725075
    50735076        """
     5077        if constraint_generation is None:
     5078            if self.density() > .7:
     5079                constraint_generation = False
     5080            else:
     5081                constraint_generation = True
     5082
    50745083        ###############################
    5075         # Quick cheks of connectivity #
     5084        # Quick checks of connectivity #
    50765085        ###############################
    50775086
    50785087        # TODO : Improve it by checking vertex-connectivity instead of
     
    54115420            sage: g.hamiltonian_cycle()
    54125421            Traceback (most recent call last):
    54135422            ...
    5414             ValueError: The given graph is not Hamiltonian
     5423            ValueError: The given graph is not hamiltonian
    54155424           
    54165425        Now, using the backtrack algorithm in the Heawood graph ::
    54175426