# Ticket #10560: 15059.patch

File 15059.patch, 7.1 KB (added by eviatarbach, 11 years ago)
• ## sage/graphs/generic_graph.py

```# HG changeset patch
# User Eviatar Bach <eviatarbach@gmail.com>
# Date 1294203899 28800
# Node ID bcff8a8fb10fe78088ccf0e33aca797a6489592b
# Parent  d152b23009e4811eba04aff095949e25c5f19fef
trac 10560: Fixes spelling errors in generic_graph.py

diff -r d152b23009e4 -r bcff8a8fb10f sage/graphs/generic_graph.py```
 a def vertex_cut(self, s, t, value_only=True, vertices=False, solver=None, verbose=0): r""" Returns a minimum vertex cut between non adjacent vertices `s` and `t` Returns a minimum vertex cut between non-adjacent vertices `s` and `t` represented by a list of vertices. A vertex cut between two non adjacent vertices is a set `U` A vertex cut between two non-adjacent vertices is a set `U` of vertices of self such that the graph obtained by removing `U` from self is disconnected. For more information, see the `Wikipedia article on cuts only the size of a minimum vertex cover is returned. Otherwise, a minimum vertex cover is returned as a list of vertices. - ``log`` -- non negative integer (default: ``0``). Set the level - ``log`` -- non-negative integer (default: ``0``). Set the level of verbosity you want from the linear program solver. Since the problem of computing a vertex cover is `NP`-complete, its solving may take some time depending on the graph. A value of 0 means Given a graph (resp. a digraph) `G` with weighted edges, the traveling salesman problem consists in finding a hamiltonian cycle (resp. circuit) of the graph of Hamiltonian cycle (resp. circuit) of the graph of minimum cost. This TSP is one of the most famous NP-Complete problems, EXAMPLES: The Heawood graph is known to be hamiltonian:: The Heawood graph is known to be Hamiltonian:: sage: g = graphs.HeawoodGraph() sage: tsp = g.traveling_salesman_problem() True On the other hand, the Petersen Graph is known not to be hamiltonian:: be Hamiltonian:: sage: g = graphs.PetersenGraph() sage: tsp = g.traveling_salesman_problem() Traceback (most recent call last): ... ValueError: The given graph is not hamiltonian ValueError: The given graph is not Hamiltonian One easy way to change is is obviously to add to this graph the edges corresponding to a hamiltonian cycle. graph the edges corresponding to a Hamiltonian cycle. If we do this by setting the cost of these new edges to `2`, while the others are set to `1`, we notice return tsp except MIPSolverException: raise ValueError("The given graph is not hamiltonian") raise ValueError("The given graph is not Hamiltonian") def hamiltonian_cycle(self): r""" Returns a hamiltonian cycle/circuit of the current graph/digraph A graph (resp. digraph) is said to be hamiltonian Returns a Hamiltonian cycle/circuit of the current graph/digraph A graph (resp. digraph) is said to be Hamiltonian if it contains as a subgraph a cycle (resp. a circuit) going through all the vertices. Computing a hamiltonian cycle/circuit being NP-Complete, Computing a Hamiltonian cycle/circuit being NP-Complete, this algorithm could run for some time depending on the instance. OUTPUT: Returns a hamiltonian cycle/circuit if it exists. Otherwise, Returns a Hamiltonian cycle/circuit if it exists. Otherwise, raises a ``ValueError`` exception. NOTE: This function, as ``is_hamiltonian``, computes a hamiltonian This function, as ``is_hamiltonian``, computes a Hamiltonian cycle if it exists : the user should *NOT* test for hamiltonicity using ``is_hamiltonian`` before calling this Hamiltonicity using ``is_hamiltonian`` before calling this function, as it would result in computing it twice. EXAMPLES: The Heawood Graph is known to be hamiltonian :: The Heawood Graph is known to be Hamiltonian :: sage: g = graphs.HeawoodGraph() sage: g.hamiltonian_cycle() sage: g.hamiltonian_cycle() Traceback (most recent call last): ... ValueError: The given graph is not hamiltonian ValueError: The given graph is not Hamiltonian """ from sage.numerical.mip import MIPSolverException try: return self.traveling_salesman_problem(weighted = False) except MIPSolverException: raise ValueError("The given graph is not hamiltonian") raise ValueError("The given graph is not Hamiltonian") def flow(self, x, y, value_only=True, integer=False, use_edge_labels=True, vertex_bound=False, method = None, solver=None, verbose=0): r""" def layout_tree(self, tree_orientation = "down", tree_root = None, dim = 2, **options): """ Computes an ordered tree layout for this graph, which should be a tree (no non oriented cycles). be a tree (no non-oriented cycles). INPUT: r""" Tests whether the current graph is Hamiltonian A graph (resp. digraph) is said to be hamiltonian A graph (resp. digraph) is said to be Hamiltonian if it contains as a subgraph a cycle (resp. a circuit) going through all the vertices. Testing for hamiltonicity being NP-Complete, this Testing for Hamiltonicity being NP-Complete, this algorithm could run for some time depending on the instance. OUTPUT: Returns ``True`` if a hamiltonian cycle/circuit exists, and Returns ``True`` if a Hamiltonian cycle/circuit exists, and ``False`` otherwise. NOTE: This function, as ``hamiltonian_cycle`` and ``traveling_salesman_problem``, computes a hamiltonian ``traveling_salesman_problem``, computes a Hamiltonian cycle if it exists : the user should *NOT* test for hamiltonicity using ``is_hamiltonian`` before calling Hamiltonicity using ``is_hamiltonian`` before calling ``hamiltonian_cycle`` or ``traveling_salesman_problem`` as it would result in computing it twice. EXAMPLES: The Heawood Graph is known to be hamiltonian :: The Heawood Graph is known to be Hamiltonian :: sage: g = graphs.HeawoodGraph() sage: g.is_hamiltonian()