Check if graph is connected in Igraph in Python

In Python (I did not check R), Igraph tells me that the graph G is not connected to G.is_connected (), and Networkx tells me that it is connected using nx.is_connected (G).

Knowing my schedule, I know that networkx is on this.

Is there a known bug somewhere, or do two packages have different definitions of what a connected graph is?

In fact, I would like to know if my graph is connected in the sense that there is a path from any vertex to any other vertices in the graph.

How to do it with igraph?

Here is my code:

from igraph import *
import networkx as nx

(read_a_graph_and_put_it_in_G)

G = G.to_undirected()               
print nx.is_connected(G)

adjG = nx.to_numpy_matrix(G.to_undirected())
G = Graph.Adjacency(adjG.tolist())
G.to_undirected()
print G.is_connected()

The first print gives TRUE, the second gives FALSE

+4
source share

Source: https://habr.com/ru/post/1531342/


All Articles