Skip to content

Commit

Permalink
Trac #25994: Blocks_and_cut_vertices - bug with directed graphs and B…
Browse files Browse the repository at this point in the history
…oost interface

While using the Boost interface to compute the blocks and cut vertices,
the output is wrong if the input is a directed graph.
{{{
sage: from sage.graphs.connectivity import blocks_and_cut_vertices
sage: rings = graphs.CycleGraph(10)
sage: rings.merge_vertices([0, 5])
sage: blocks_and_cut_vertices(rings, algorithm="Tarjan_Boost")
([[0, 1, 4, 2, 3], [0, 6, 9, 7, 8]], [0])
}}}
{{{
sage: from sage.graphs.connectivity import blocks_and_cut_vertices
sage: rings = graphs.CycleGraph(10)
sage: rings.merge_vertices([0, 5])
sage: rings = rings.to_directed()
sage: blocks_and_cut_vertices(rings, algorithm="Tarjan_Boost")
([[0, 1, 4, 2, 3, 6, 7, 8, 9], [0, 6, 9, 7, 8]], [0, 9, 8, 6, 7])
}}}

If the input graph is a directed graph, the blocks and cut vertices are
computed on the underlying simple graph.

URL: https://trac.sagemath.org/25994
Reported by: meghanamreddy
Ticket author(s): Meghana M Reddy
Reviewer(s): David Coudert
  • Loading branch information
Release Manager authored and vbraun committed Sep 1, 2018
2 parents 3d864f4 + 7c76517 commit 522f70a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/sage/graphs/base/boost_graph.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ cpdef blocks_and_cut_vertices(g):
if not isinstance(g, GenericGraph):
raise TypeError("the input must be a Sage graph")

if g.allows_loops() or g.allows_multiple_edges():
if g.allows_loops() or g.allows_multiple_edges() or g.is_directed():
g = g.to_simple()

cdef BoostVecGraph g_boost
Expand Down
8 changes: 8 additions & 0 deletions src/sage/graphs/connectivity.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,14 @@ def blocks_and_cut_vertices(G, algorithm="Tarjan_Boost"):
sage: blocks_and_cut_vertices(g)
([[1, 2, 3], [5, 6], [5, 7], [5, 8], [4]], [5])
A directed graph with Boost's algorithm (:trac:`25994`)::
sage: rings = graphs.CycleGraph(10)
sage: rings.merge_vertices([0, 5])
sage: rings = rings.to_directed()
sage: blocks_and_cut_vertices(rings, algorithm="Tarjan_Boost")
([[0, 1, 4, 2, 3], [0, 6, 9, 7, 8]], [0])
TESTS::
sage: blocks_and_cut_vertices(Graph(0))
Expand Down

0 comments on commit 522f70a

Please sign in to comment.