# 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
|
b
|
|
3834 | 3834 | |
3835 | 3835 | def vertex_cut(self, s, t, value_only=True, vertices=False, solver=None, verbose=0): |
3836 | 3836 | r""" |
3837 | | Returns a minimum vertex cut between non adjacent vertices `s` and `t` |
| 3837 | Returns a minimum vertex cut between non-adjacent vertices `s` and `t` |
3838 | 3838 | represented by a list of vertices. |
3839 | 3839 | |
3840 | | A vertex cut between two non adjacent vertices is a set `U` |
| 3840 | A vertex cut between two non-adjacent vertices is a set `U` |
3841 | 3841 | of vertices of self such that the graph obtained by removing |
3842 | 3842 | `U` from self is disconnected. For more information, see the |
3843 | 3843 | `Wikipedia article on cuts |
… |
… |
|
4134 | 4134 | only the size of a minimum vertex cover is returned. Otherwise, |
4135 | 4135 | a minimum vertex cover is returned as a list of vertices. |
4136 | 4136 | |
4137 | | - ``log`` -- non negative integer (default: ``0``). Set the level |
| 4137 | - ``log`` -- non-negative integer (default: ``0``). Set the level |
4138 | 4138 | of verbosity you want from the linear program solver. Since the |
4139 | 4139 | problem of computing a vertex cover is `NP`-complete, its solving |
4140 | 4140 | may take some time depending on the graph. A value of 0 means |
… |
… |
|
4352 | 4352 | |
4353 | 4353 | Given a graph (resp. a digraph) `G` with weighted edges, |
4354 | 4354 | the traveling salesman problem consists in finding a |
4355 | | hamiltonian cycle (resp. circuit) of the graph of |
| 4355 | Hamiltonian cycle (resp. circuit) of the graph of |
4356 | 4356 | minimum cost. |
4357 | 4357 | |
4358 | 4358 | This TSP is one of the most famous NP-Complete problems, |
… |
… |
|
4390 | 4390 | |
4391 | 4391 | EXAMPLES: |
4392 | 4392 | |
4393 | | The Heawood graph is known to be hamiltonian:: |
| 4393 | The Heawood graph is known to be Hamiltonian:: |
4394 | 4394 | |
4395 | 4395 | sage: g = graphs.HeawoodGraph() |
4396 | 4396 | sage: tsp = g.traveling_salesman_problem() |
… |
… |
|
4413 | 4413 | True |
4414 | 4414 | |
4415 | 4415 | On the other hand, the Petersen Graph is known not to |
4416 | | be hamiltonian:: |
| 4416 | be Hamiltonian:: |
4417 | 4417 | |
4418 | 4418 | sage: g = graphs.PetersenGraph() |
4419 | 4419 | sage: tsp = g.traveling_salesman_problem() |
4420 | 4420 | Traceback (most recent call last): |
4421 | 4421 | ... |
4422 | | ValueError: The given graph is not hamiltonian |
| 4422 | ValueError: The given graph is not Hamiltonian |
4423 | 4423 | |
4424 | 4424 | One easy way to change is is obviously to add to this |
4425 | | graph the edges corresponding to a hamiltonian cycle. |
| 4425 | graph the edges corresponding to a Hamiltonian cycle. |
4426 | 4426 | |
4427 | 4427 | If we do this by setting the cost of these new edges |
4428 | 4428 | to `2`, while the others are set to `1`, we notice |
… |
… |
|
4569 | 4569 | return tsp |
4570 | 4570 | |
4571 | 4571 | except MIPSolverException: |
4572 | | raise ValueError("The given graph is not hamiltonian") |
| 4572 | raise ValueError("The given graph is not Hamiltonian") |
4573 | 4573 | |
4574 | 4574 | |
4575 | 4575 | def hamiltonian_cycle(self): |
4576 | 4576 | r""" |
4577 | | Returns a hamiltonian cycle/circuit of the current graph/digraph |
4578 | | |
4579 | | A graph (resp. digraph) is said to be hamiltonian |
| 4577 | Returns a Hamiltonian cycle/circuit of the current graph/digraph |
| 4578 | |
| 4579 | A graph (resp. digraph) is said to be Hamiltonian |
4580 | 4580 | if it contains as a subgraph a cycle (resp. a circuit) |
4581 | 4581 | going through all the vertices. |
4582 | 4582 | |
4583 | | Computing a hamiltonian cycle/circuit being NP-Complete, |
| 4583 | Computing a Hamiltonian cycle/circuit being NP-Complete, |
4584 | 4584 | this algorithm could run for some time depending on |
4585 | 4585 | the instance. |
4586 | 4586 | |
… |
… |
|
4590 | 4590 | |
4591 | 4591 | OUTPUT: |
4592 | 4592 | |
4593 | | Returns a hamiltonian cycle/circuit if it exists. Otherwise, |
| 4593 | Returns a Hamiltonian cycle/circuit if it exists. Otherwise, |
4594 | 4594 | raises a ``ValueError`` exception. |
4595 | 4595 | |
4596 | 4596 | NOTE: |
4597 | 4597 | |
4598 | | This function, as ``is_hamiltonian``, computes a hamiltonian |
| 4598 | This function, as ``is_hamiltonian``, computes a Hamiltonian |
4599 | 4599 | cycle if it exists : the user should *NOT* test for |
4600 | | hamiltonicity using ``is_hamiltonian`` before calling this |
| 4600 | Hamiltonicity using ``is_hamiltonian`` before calling this |
4601 | 4601 | function, as it would result in computing it twice. |
4602 | 4602 | |
4603 | 4603 | EXAMPLES: |
4604 | 4604 | |
4605 | | The Heawood Graph is known to be hamiltonian :: |
| 4605 | The Heawood Graph is known to be Hamiltonian :: |
4606 | 4606 | |
4607 | 4607 | sage: g = graphs.HeawoodGraph() |
4608 | 4608 | sage: g.hamiltonian_cycle() |
… |
… |
|
4614 | 4614 | sage: g.hamiltonian_cycle() |
4615 | 4615 | Traceback (most recent call last): |
4616 | 4616 | ... |
4617 | | ValueError: The given graph is not hamiltonian |
| 4617 | ValueError: The given graph is not Hamiltonian |
4618 | 4618 | """ |
4619 | 4619 | from sage.numerical.mip import MIPSolverException |
4620 | 4620 | |
4621 | 4621 | try: |
4622 | 4622 | return self.traveling_salesman_problem(weighted = False) |
4623 | 4623 | except MIPSolverException: |
4624 | | raise ValueError("The given graph is not hamiltonian") |
| 4624 | raise ValueError("The given graph is not Hamiltonian") |
4625 | 4625 | |
4626 | 4626 | def flow(self, x, y, value_only=True, integer=False, use_edge_labels=True, vertex_bound=False, method = None, solver=None, verbose=0): |
4627 | 4627 | r""" |
… |
… |
|
11800 | 11800 | def layout_tree(self, tree_orientation = "down", tree_root = None, dim = 2, **options): |
11801 | 11801 | """ |
11802 | 11802 | Computes an ordered tree layout for this graph, which should |
11803 | | be a tree (no non oriented cycles). |
| 11803 | be a tree (no non-oriented cycles). |
11804 | 11804 | |
11805 | 11805 | INPUT: |
11806 | 11806 | |
… |
… |
|
13856 | 13856 | r""" |
13857 | 13857 | Tests whether the current graph is Hamiltonian |
13858 | 13858 | |
13859 | | A graph (resp. digraph) is said to be hamiltonian |
| 13859 | A graph (resp. digraph) is said to be Hamiltonian |
13860 | 13860 | if it contains as a subgraph a cycle (resp. a circuit) |
13861 | 13861 | going through all the vertices. |
13862 | 13862 | |
13863 | | Testing for hamiltonicity being NP-Complete, this |
| 13863 | Testing for Hamiltonicity being NP-Complete, this |
13864 | 13864 | algorithm could run for some time depending on |
13865 | 13865 | the instance. |
13866 | 13866 | |
… |
… |
|
13870 | 13870 | |
13871 | 13871 | OUTPUT: |
13872 | 13872 | |
13873 | | Returns ``True`` if a hamiltonian cycle/circuit exists, and |
| 13873 | Returns ``True`` if a Hamiltonian cycle/circuit exists, and |
13874 | 13874 | ``False`` otherwise. |
13875 | 13875 | |
13876 | 13876 | NOTE: |
13877 | 13877 | |
13878 | 13878 | This function, as ``hamiltonian_cycle`` and |
13879 | | ``traveling_salesman_problem``, computes a hamiltonian |
| 13879 | ``traveling_salesman_problem``, computes a Hamiltonian |
13880 | 13880 | cycle if it exists : the user should *NOT* test for |
13881 | | hamiltonicity using ``is_hamiltonian`` before calling |
| 13881 | Hamiltonicity using ``is_hamiltonian`` before calling |
13882 | 13882 | ``hamiltonian_cycle`` or ``traveling_salesman_problem`` |
13883 | 13883 | as it would result in computing it twice. |
13884 | 13884 | |
13885 | 13885 | EXAMPLES: |
13886 | 13886 | |
13887 | | The Heawood Graph is known to be hamiltonian :: |
| 13887 | The Heawood Graph is known to be Hamiltonian :: |
13888 | 13888 | |
13889 | 13889 | sage: g = graphs.HeawoodGraph() |
13890 | 13890 | sage: g.is_hamiltonian() |