Skip to content

Commit 79c4c60

Browse files
committed
feat: add is_complete()
1 parent ccb057a commit 79c4c60

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# igraph Python interface changelog
22

3+
### Added
4+
5+
- Added `Graph.is_complete()` to test if there is a connection between all distinct pair of vertices.
6+
37
### Changed
48

59
- Error messages issued when an attribute is not found now mention the name and type of that attribute.

src/_igraph/graphobject.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,25 @@ PyObject *igraphmodule_Graph_is_simple(igraphmodule_GraphObject* self, PyObject*
548548
}
549549

550550

551+
/** \ingroup python_interface_graph
552+
* \brief Checks whether an \c igraph.Graph object is a complete graph.
553+
* \return \c True if the graph is complete, \c False otherwise.
554+
* \sa igraph_is_complete
555+
*/
556+
PyObject *igraphmodule_Graph_is_complete(igraphmodule_GraphObject* self, PyObject* Py_UNUSED(_null)) {
557+
igraph_bool_t res;
558+
559+
if (igraph_is_complete(&self->g, &res)) {
560+
igraphmodule_handle_igraph_error();
561+
return NULL;
562+
}
563+
564+
if (res)
565+
Py_RETURN_TRUE;
566+
Py_RETURN_FALSE;
567+
}
568+
569+
551570
/** \ingroup python_interface_graph
552571
* \brief Determines whether a graph is a (directed or undirected) tree
553572
* \sa igraph_is_tree
@@ -13625,6 +13644,16 @@ struct PyMethodDef igraphmodule_Graph_methods[] = {
1362513644
"@return: C{True} if it is simple, C{False} otherwise.\n"
1362613645
"@rtype: boolean"},
1362713646

13647+
/* interface to igraph_is_complete */
13648+
{"is_complete", (PyCFunction) igraphmodule_Graph_is_complete,
13649+
METH_NOARGS,
13650+
"is_complete()\n--\n\n"
13651+
"Checks whether the graph is complete, i.e. whether there is at least one\n"
13652+
"connection between all distinct pairs of vertices. In directed graphs,\n"
13653+
"ordered pairs are considered.\n\n"
13654+
"@return: C{True} if it is complete, C{False} otherwise.\n"
13655+
"@rtype: boolean"},
13656+
1362813657
/* interface to igraph_is_tree */
1362913658
{"is_tree", (PyCFunction) igraphmodule_Graph_is_tree,
1363013659
METH_VARARGS | METH_KEYWORDS,

src/igraph/adjacency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def _get_biadjacency(graph, types="type", *args, **kwds):
140140
bipartite adjacency matrix is an M{n} times M{m} matrix, where M{n} and
141141
M{m} are the number of vertices in the two vertex classes.
142142
143-
@param types: an igraph vector containing the vertex types, or an
143+
@param types: a vector containing the vertex types, or an
144144
attribute name. Anything that evalulates to C{False} corresponds to
145145
vertices of the first kind, everything else to the second kind.
146146
@return: the bipartite adjacency matrix and two lists in a triplet. The

tests/test_bipartite.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ def testBipartiteProjection(self):
172172
g = Graph.Full_Bipartite(10, 5)
173173

174174
g1, g2 = g.bipartite_projection()
175+
self.assertTrue(g1.is_complete())
175176
self.assertTrue(g1.isomorphic(Graph.Full(10)))
177+
self.assertTrue(g2.is_complete())
176178
self.assertTrue(g2.isomorphic(Graph.Full(5)))
177179
self.assertTrue(g.bipartite_projection(which=0).isomorphic(g1))
178180
self.assertTrue(g.bipartite_projection(which=1).isomorphic(g2))
@@ -183,15 +185,19 @@ def testBipartiteProjection(self):
183185
self.assertTrue(g.bipartite_projection_size() == (10, 45, 5, 10))
184186

185187
g1, g2 = g.bipartite_projection(probe1=10)
188+
self.assertTrue(g1.is_complete())
186189
self.assertTrue(g1.isomorphic(Graph.Full(5)))
190+
self.assertTrue(g2.is_complete())
187191
self.assertTrue(g2.isomorphic(Graph.Full(10)))
188192
self.assertTrue(g.bipartite_projection(which=0).isomorphic(g2))
189193
self.assertTrue(g.bipartite_projection(which=1).isomorphic(g1))
190194
self.assertTrue(g.bipartite_projection(which=False).isomorphic(g2))
191195
self.assertTrue(g.bipartite_projection(which=True).isomorphic(g1))
192196

193197
g1, g2 = g.bipartite_projection(multiplicity=False)
198+
self.assertTrue(g1.is_complete())
194199
self.assertTrue(g1.isomorphic(Graph.Full(10)))
200+
self.assertTrue(g2.is_complete())
195201
self.assertTrue(g2.isomorphic(Graph.Full(5)))
196202
self.assertTrue(g.bipartite_projection(which=0).isomorphic(g1))
197203
self.assertTrue(g.bipartite_projection(which=1).isomorphic(g2))

tests/test_generators.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def testFull(self):
110110
g = Graph.Full(20, directed=True)
111111
el = g.get_edgelist()
112112
el.sort()
113+
self.assertTrue(g.is_complete())
113114
self.assertTrue(
114115
g.get_edgelist() == [(x, y) for x in range(20) for y in range(20) if x != y]
115116
)

0 commit comments

Comments
 (0)