How to import/read a graph, written as edges list and saved as a txt file, into Networkit?

454 Views Asked by At

Hi, how can I read/import a graph, stored in a text file, mygraph.txt, and written in a form of edges list (column 1: node u, column 2: node v)

1 2  
1 3  
1 4 
2 5 
3 4 
3 5 

into Networkit?

I guess something like this?

G = readGraph("/home/JohnRambo/Documents/myFolder/mygraph.txt")

P.S.: After several attempts I am not able yet to make it work...and I did not find clear instructions in the networkit guide!

1

There are 1 best solutions below

0
Ommo On

I found this solution:

from networkit import *  
import networkit as nk 
G = nk.readGraph("/home/JohnRambo/Documents/myFolder/mygraph.txt",nk.Format.SNAP)
print(G.numberOfNodes(), G.numberOfEdges())

Output:

5 6