Ticket #10560: 15206.patch

File 15206.patch, 9.5 KB (added by eviatarbach, 11 years ago)
  • sage/graphs/generic_graph.py

    # HG changeset patch
    # User Eviatar Bach <eviatarbach@gmail.com>
    # Date 1294875715 28800
    # Node ID 50830205b2f235e4424424c4538f54710dea5540
    # Parent  1896a0311e7061fac80de9805e0258200b23336e
    Trac 10560: Updated patch.
    
    diff -r 1896a0311e70 -r 50830205b2f2 sage/graphs/generic_graph.py
    a b  
    19581958
    19591959    def eulerian_orientation(self):
    19601960        r"""
    1961         Returns a DiGraph which is an eulerian orientation of the current graph.
    1962 
    1963         An eulerian graph being a graph such that any vertex has an even degree,
    1964         an eulerian orientation of a graph is an orientation of its edges such
     1961        Returns a DiGraph which is an Eulerian orientation of the current graph.
     1962
     1963        An Eulerian graph being a graph such that any vertex has an even degree,
     1964        an Eulerian orientation of a graph is an orientation of its edges such
    19651965        that each vertex `v` verifies `d^+(v)=d^-(v)=d(v)/2`, where `d^+` and
    19661966        `d^-` respectively represent the out-degree and the in-degree of a vertex.
    19671967
    1968         If the graph is not eulerian, the orientation verifies for any vertex `v`
     1968        If the graph is not Eulerian, the orientation verifies for any vertex `v`
    19691969        that `| d^+(v)-d^-(v) | \leq 1`.
    19701970
    19711971        ALGORITHM:
     
    19811981        EXAMPLES:
    19821982
    19831983        The CubeGraph with parameter 4, which is regular of even degree, has an
    1984         eulerian orientation such that `d^+=d^-`::
     1984        Eulerian orientation such that `d^+=d^-`::
    19851985
    19861986            sage: g=graphs.CubeGraph(4)
    19871987            sage: g.degree()
     
    38533853       
    38543854    def vertex_cut(self, s, t, value_only=True, vertices=False, solver=None, verbose=0):
    38553855        r"""
    3856         Returns a minimum vertex cut between non adjacent vertices `s` and `t`
     3856        Returns a minimum vertex cut between non-adjacent vertices `s` and `t`
    38573857        represented by a list of vertices.
    38583858
    3859         A vertex cut between two non adjacent vertices is a set `U`
     3859        A vertex cut between two non-adjacent vertices is a set `U`
    38603860        of vertices of self such that the graph obtained by removing
    38613861        `U` from self is disconnected. For more information, see the
    38623862        `Wikipedia article on cuts
     
    41604160          only the size of a minimum vertex cover is returned. Otherwise,
    41614161          a minimum vertex cover is returned as a list of vertices.
    41624162
    4163         - ``log`` -- non negative integer (default: ``0``). Set the level
     4163        - ``log`` -- non-negative integer (default: ``0``). Set the level
    41644164          of verbosity you want from the linear program solver. Since the
    41654165          problem of computing a vertex cover is `NP`-complete, its solving
    41664166          may take some time depending on the graph. A value of 0 means
     
    43804380
    43814381        Given a graph (resp. a digraph) `G` with weighted edges,
    43824382        the traveling salesman problem consists in finding a
    4383         hamiltonian cycle (resp. circuit) of the graph of
     4383        Hamiltonian cycle (resp. circuit) of the graph of
    43844384        minimum cost.
    43854385
    43864386        This TSP is one of the most famous NP-Complete problems,
     
    44304430
    44314431        EXAMPLES:
    44324432
    4433         The Heawood graph is known to be hamiltonian::
     4433        The Heawood graph is known to be Hamiltonian::
    44344434
    44354435            sage: g = graphs.HeawoodGraph()
    44364436            sage: tsp = g.traveling_salesman_problem()
     
    44534453            True
    44544454
    44554455        On the other hand, the Petersen Graph is known not to
    4456         be hamiltonian::
     4456        be Hamiltonian::
    44574457
    44584458            sage: g = graphs.PetersenGraph()
    44594459            sage: tsp = g.traveling_salesman_problem()
    44604460            Traceback (most recent call last):
    44614461            ...
    4462             ValueError: The given graph is not hamiltonian
     4462            ValueError: The given graph is not Hamiltonian
    44634463
    44644464        One easy way to change is is obviously to add to this
    4465         graph the edges corresponding to a hamiltonian cycle.
     4465        graph the edges corresponding to a Hamiltonian cycle.
    44664466     
    44674467        If we do this by setting the cost of these new edges
    44684468        to `2`, while the others are set to `1`, we notice
     
    46094609            return tsp
    46104610       
    46114611        except MIPSolverException:
    4612             raise ValueError("The given graph is not hamiltonian")
     4612            raise ValueError("The given graph is not Hamiltonian")
    46134613
    46144614
    46154615    def hamiltonian_cycle(self, algorithm='tsp' ):
    46164616        r"""
    4617         Returns a hamiltonian cycle/circuit of the current graph/digraph
    4618 
    4619         A graph (resp. digraph) is said to be hamiltonian
     4617        Returns a Hamiltonian cycle/circuit of the current graph/digraph
     4618
     4619        A graph (resp. digraph) is said to be Hamiltonian
    46204620        if it contains as a subgraph a cycle (resp. a circuit)
    46214621        going through all the vertices.
    46224622
    4623         Computing a hamiltonian cycle/circuit being NP-Complete,
     4623        Computing a Hamiltonian cycle/circuit being NP-Complete,
    46244624        this algorithm could run for some time depending on
    46254625        the instance.
    46264626
     
    46364636
    46374637        OUTPUT:
    46384638
    4639         If using the 'tsp' algorithm, returns a hamiltonian cycle/circuit if it
     4639        If using the 'tsp' algorithm, returns a Hamiltonian cycle/circuit if it
    46404640        exists; otherwise, raises a ``ValueError`` exception. If using the
    46414641        'backtrack' algorithm, returns a pair (B,P). If B is True then P is a
    4642         hamiltonian cycle and if B is False, P is a longest path found by the
    4643         algorithm. Observe that if B is False, the graph may still be hamiltonian.
     4642        Hamiltonian cycle and if B is False, P is a longest path found by the
     4643        algorithm. Observe that if B is False, the graph may still be Hamiltonian.
    46444644        The 'backtrack' algorithm is only implemented for undirected
    46454645        graphs.
    46464646
     
    46514651
    46524652        NOTE:
    46534653
    4654         This function, as ``is_hamiltonian``, computes a hamiltonian
     4654        This function, as ``is_hamiltonian``, computes a Hamiltonian
    46554655        cycle if it exists : the user should *NOT* test for
    4656         hamiltonicity using ``is_hamiltonian`` before calling this
     4656        Hamiltonicity using ``is_hamiltonian`` before calling this
    46574657        function, as it would result in computing it twice.
    46584658
    46594659        The backtrack algorithm is only implemented for undirected graphs.
    46604660
    46614661        EXAMPLES:
    46624662
    4663         The Heawood Graph is known to be hamiltonian ::
     4663        The Heawood Graph is known to be Hamiltonian ::
    46644664
    46654665            sage: g = graphs.HeawoodGraph()
    46664666            sage: g.hamiltonian_cycle()
     
    46724672            sage: g.hamiltonian_cycle()
    46734673            Traceback (most recent call last):
    46744674            ...
    4675             ValueError: The given graph is not hamiltonian
     4675            ValueError: The given graph is not Hamiltonian
    46764676           
    46774677        Now, using the backtrack algorithm in the Heawood graph ::
    46784678
     
    46864686            sage: G.hamiltonian_cycle(algorithm='backtrack')
    46874687            (False, [6, 8, 5, 0, 1, 2, 7, 9, 4, 3])
    46884688
    4689         Finally, we test the algorithm in a cube graph, which is hamiltonian ::
     4689        Finally, we test the algorithm in a cube graph, which is Hamiltonian ::
    46904690           
    46914691            sage: G=graphs.CubeGraph(3)
    46924692            sage: G.hamiltonian_cycle(algorithm='backtrack')
     
    46994699            try:
    47004700                return self.traveling_salesman_problem(weighted = False)
    47014701            except MIPSolverException:
    4702                 raise ValueError("The given graph is not hamiltonian")
     4702                raise ValueError("The given graph is not Hamiltonian")
    47034703        elif algorithm=='backtrack':
    47044704            from sage.graphs.generic_graph_pyx import find_hamiltonian as fh
    47054705            return fh( self )
     
    1191011910    def layout_tree(self, tree_orientation = "down", tree_root = None, dim = 2, **options):
    1191111911        """
    1191211912        Computes an ordered tree layout for this graph, which should
    11913         be a tree (no non oriented cycles).
     11913        be a tree (no non-oriented cycles).
    1191411914
    1191511915        INPUT:
    1191611916
     
    1396413964
    1396513965    def is_hamiltonian(self):
    1396613966        r"""
    13967         Tests whether the current graph is hamiltonian
    13968 
    13969         A graph (resp. digraph) is said to be hamiltonian
     13967        Tests whether the current graph is Hamiltonian.
     13968
     13969        A graph (resp. digraph) is said to be Hamiltonian
    1397013970        if it contains as a subgraph a cycle (resp. a circuit)
    1397113971        going through all the vertices.
    1397213972
    13973         Testing for hamiltonicity being NP-Complete, this
     13973        Testing for Hamiltonicity being NP-Complete, this
    1397413974        algorithm could run for some time depending on
    1397513975        the instance.
    1397613976
     
    1398013980
    1398113981        OUTPUT:
    1398213982
    13983         Returns ``True`` if a hamiltonian cycle/circuit exists, and
     13983        Returns ``True`` if a Hamiltonian cycle/circuit exists, and
    1398413984        ``False`` otherwise.
    1398513985
    1398613986        NOTE:
    1398713987
    1398813988        This function, as ``hamiltonian_cycle`` and
    13989         ``traveling_salesman_problem``, computes a hamiltonian
     13989        ``traveling_salesman_problem``, computes a Hamiltonian
    1399013990        cycle if it exists : the user should *NOT* test for
    13991         hamiltonicity using ``is_hamiltonian`` before calling
     13991        Hamiltonicity using ``is_hamiltonian`` before calling
    1399213992        ``hamiltonian_cycle`` or ``traveling_salesman_problem``
    1399313993        as it would result in computing it twice.
    1399413994
    1399513995        EXAMPLES:
    1399613996
    13997         The Heawood Graph is known to be hamiltonian ::
     13997        The Heawood Graph is known to be Hamiltonian ::
    1399813998
    1399913999            sage: g = graphs.HeawoodGraph()
    1400014000            sage: g.is_hamiltonian()