Search code examples
pythongraphigraphnetwork-analysis

Unable to import undirected graph from EdgeList file in igraph-python


I am using the igraph-python's Graph.Read_Ncol function. Below is my code for reading the data.

def loadData(filename):
    data = None
    data = ig.Graph.Read_Ncol(filename, directed=False)
    return data

I am using this dataset from SNAP group: https://snap.stanford.edu/data/ca-GrQc.html As mentioned the dataset has 14496 edges and 5242 nodes.

However when I do data.summary() on my graph I get the following output.

>>> data.summary()
'IGRAPH UN-- 5242 28980 -- \n+ attr: name (v)'

Even when I am doing data.to_undirected() and trying data.summary() again I am getting the same result as above.

>>> data.to_undirected()
>>> data.summary()
'IGRAPH UN-- 5242 28980 -- \n+ attr: name (v)'

When I am loading the graph using the SNAP library in an undirected fashion then I am getting the correct output.

def loadData(filename):
    data = None
    data = snap.LoadEdgeList(snap.PUNGraph,filename,0,1)

    return data

What am I doing wrong? Or is there an issue with the igraph API?


Solution

  • Most of the edges appear twice in your network, and igraphs adds them as multiple edges. Call simplify() on the graph to remove these multiple edges. http://igraph.org/python/doc/igraph.GraphBase-class.html#simplify