Skip to content

Commit 3739f7d

Browse files
authored
Merge pull request #755 from igraph/feat/is_biconnected
feat: is_biconnected()
2 parents 766a156 + fae0631 commit 3739f7d

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/_igraph/graphobject.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,27 @@ PyObject *igraphmodule_Graph_is_connected(igraphmodule_GraphObject * self,
14211421
Py_RETURN_FALSE;
14221422
}
14231423

1424+
/** \ingroup python_interface_graph
1425+
* \brief Decides whether a graph is biconnected.
1426+
* \return Py_True if the graph is biconnected, Py_False otherwise
1427+
* \sa igraph_is_biconnected
1428+
*/
1429+
PyObject *igraphmodule_Graph_is_biconnected(igraphmodule_GraphObject *self, PyObject* Py_UNUSED(_null))
1430+
{
1431+
igraph_bool_t res;
1432+
1433+
if (igraph_is_biconnected(&self->g, &res)) {
1434+
igraphmodule_handle_igraph_error();
1435+
return NULL;
1436+
}
1437+
1438+
if (res) {
1439+
Py_RETURN_TRUE;
1440+
} else {
1441+
Py_RETURN_FALSE;
1442+
}
1443+
}
1444+
14241445
/** \ingroup python_interface_graph
14251446
* \brief Decides whether there is an edge from a given vertex to an other one.
14261447
* \return Py_True if the vertices are directly connected, Py_False otherwise
@@ -15275,6 +15296,20 @@ struct PyMethodDef igraphmodule_Graph_methods[] = {
1527515296
"@param mode: whether we should calculate strong or weak connectivity.\n"
1527615297
"@return: C{True} if the graph is connected, C{False} otherwise.\n"},
1527715298

15299+
/* interface to igraph_is_biconnected */
15300+
{"is_biconnected", (PyCFunction) igraphmodule_Graph_is_biconnected,
15301+
METH_NOARGS,
15302+
"is_biconnected()\n--\n\n"
15303+
"Decides whether the graph is biconnected.\n\n"
15304+
"A graph is biconnected if it stays connected after the removal of\n"
15305+
"any single vertex.\n\n"
15306+
"Note that there are different conventions in use about whether to\n"
15307+
"consider a graph consisting of two connected vertices to be biconnected.\n"
15308+
"igraph does consider it biconnected.\n\n"
15309+
"@return: C{True} if it is biconnected, C{False} otherwise.\n"
15310+
"@rtype: boolean"
15311+
},
15312+
1527815313
/* interface to igraph_linegraph */
1527915314
{"linegraph", (PyCFunction) igraphmodule_Graph_linegraph,
1528015315
METH_VARARGS | METH_KEYWORDS,

tests/test_structural.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ class BiconnectedComponentTests(unittest.TestCase):
242242
g1 = Graph.Full(10)
243243
g2 = Graph(5, [(0, 1), (1, 2), (2, 3), (3, 4)])
244244
g3 = Graph(6, [(0, 1), (1, 2), (2, 3), (3, 0), (2, 4), (2, 5), (4, 5)])
245+
g4 = Graph.Full(2)
246+
g5 = Graph.Full(1)
245247

246248
def testBiconnectedComponents(self):
247249
s = self.g1.biconnected_components()
@@ -260,6 +262,14 @@ def testArticulationPoints(self):
260262
self.assertTrue(self.g1.articulation_points() == [])
261263
self.assertTrue(self.g2.cut_vertices() == [1, 2, 3])
262264
self.assertTrue(self.g3.articulation_points() == [2])
265+
self.assertTrue(self.g4.articulation_points() == [])
266+
267+
def testIsBiconnected(self):
268+
self.assertTrue(self.g1.is_biconnected())
269+
self.assertFalse(self.g2.is_biconnected())
270+
self.assertFalse(self.g3.is_biconnected())
271+
self.assertTrue(self.g4.is_biconnected())
272+
self.assertFalse(self.g5.is_biconnected())
263273

264274

265275
class CentralityTests(unittest.TestCase):

0 commit comments

Comments
 (0)