Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
trac #32805: revert some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoudert committed Nov 11, 2021
1 parent ed7a24b commit 8e192f7
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions src/sage/graphs/generic_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -4098,12 +4098,11 @@ def eulerian_circuit(self, return_vertices=False, labels=True, path=False):
return edges

def min_spanning_tree(self,
by_weight=False,
weight_function=None,
check_weight=True,
algorithm="Prim_Boost",
starting_vertex=None,
check=False):
check=False,
by_weight=False):
r"""
Return the edges of a minimum spanning tree.

Expand All @@ -4116,9 +4115,6 @@ def min_spanning_tree(self,

INPUT:

- ``by_weight`` -- boolean (default: ``False``); if ``True``, the edges
in the graph are weighted, otherwise all edges have weight 1

- ``weight_function`` -- function (default: ``None``); a function that
takes as input an edge ``(u, v, l)`` and outputs its weight. If not
``None``, ``by_weight`` is automatically set to ``True``. If ``None``
Expand All @@ -4127,8 +4123,8 @@ def min_spanning_tree(self,
be used to transform the label into a weight (note that, if the weight
returned is not convertible to a float, an error is raised)

- ``check_weight`` -- boolean (default: ``True``); whether to check that
the ``weight_function`` outputs a number for each edge.
- ``by_weight`` -- boolean (default: ``False``); if ``True``, the edges
in the graph are weighted, otherwise all edges have weight 1

- ``algorithm`` -- string (default: ``"Prim_Boost"``); the algorithm to
use in computing a minimum spanning tree of ``G``. The following
Expand Down Expand Up @@ -4300,82 +4296,88 @@ def min_spanning_tree(self,
sage: g.min_spanning_tree(algorithm="Prim_Boost")
Traceback (most recent call last):
...
ValueError: the weight function cannot find the weight of...
ValueError: could not convert string to float:...
sage: g.min_spanning_tree(algorithm="Prim_fringe")
Traceback (most recent call last):
...
ValueError: the weight function cannot find the weight of...
ValueError: could not convert string to float:...
sage: g.min_spanning_tree(algorithm="Prim_edge")
Traceback (most recent call last):
...
ValueError: the weight function cannot find the weight of...
ValueError: could not convert string to float:...
sage: g.min_spanning_tree(algorithm="Kruskal")
Traceback (most recent call last):
...
ValueError: the weight function cannot find the weight of...
ValueError: could not convert string to float:...
sage: g.min_spanning_tree(algorithm="Filter_Kruskal")
Traceback (most recent call last):
...
ValueError: the weight function cannot find the weight of...
ValueError: could not convert string to float:...
sage: g.min_spanning_tree(algorithm="Kruskal_Boost")
Traceback (most recent call last):
...
ValueError: the weight function cannot find the weight of...
ValueError: could not convert string to float:...
sage: g.min_spanning_tree(algorithm="NetworkX")
Traceback (most recent call last):
...
ValueError: the weight function cannot find the weight of...
ValueError: could not convert string to float:...
sage: g.min_spanning_tree(algorithm="Boruvka")
Traceback (most recent call last):
...
ValueError: the weight function cannot find the weight of...
ValueError: could not convert string to float:...

sage: g = Graph([(0, 1, 1), (1, 2, [1, 2, 3])], weighted=True)

sage: g.min_spanning_tree(algorithm="Prim_Boost")
Traceback (most recent call last):
...
ValueError: the weight function cannot find the weight of...
TypeError: float() argument must be a string or a... number...
sage: g.min_spanning_tree(algorithm="Prim_fringe")
Traceback (most recent call last):
...
ValueError: the weight function cannot find the weight of...
TypeError: float() argument must be a string or a... number...
sage: g.min_spanning_tree(algorithm="Prim_edge")
Traceback (most recent call last):
...
ValueError: the weight function cannot find the weight of...
TypeError: float() argument must be a string or a... number...
sage: g.min_spanning_tree(algorithm="Kruskal")
Traceback (most recent call last):
...
ValueError: the weight function cannot find the weight of...
TypeError: float() argument must be a string or a... number...
sage: g.min_spanning_tree(algorithm="Filter_Kruskal")
Traceback (most recent call last):
...
ValueError: the weight function cannot find the weight of...
TypeError: float() argument must be a string or a... number...
sage: g.min_spanning_tree(algorithm="Kruskal_Boost")
Traceback (most recent call last):
...
ValueError: the weight function cannot find the weight of...
TypeError: float() argument must be a string or a... number...
sage: g.min_spanning_tree(algorithm="NetworkX")
Traceback (most recent call last):
...
ValueError: the weight function cannot find the weight of...
TypeError: float() argument must be a string or a... number...

sage: graphs.EmptyGraph().min_spanning_tree()
[]
"""
if not self.order():
return []
if weight_function is not None:
by_weight = True

# for weighted graphs
if self.weighted():
by_weight = True

by_weight, weight_function = self._get_weight_function(by_weight=by_weight,
weight_function=weight_function,
check_weight=check_weight)
if weight_function is None and by_weight:
def weight_function(e):
return 1 if e[2] is None else e[2]

if not by_weight:
weight_function = lambda e: 1

wfunction_float = lambda e: float(weight_function(e))
def wfunction_float(e):
return float(weight_function(e))

if algorithm in ["Kruskal", "Filter_Kruskal", "Kruskal_Boost", "Prim_Boost", "Boruvka"]:
if self.is_directed():
Expand Down

0 comments on commit 8e192f7

Please sign in to comment.