2

I have a csv file that represent a direct graph, it's an edgelist with non continuous id nodes and i read it in a neworkit graph with the method

reader = nk.graphio.EdgeListReader(',',1,'#',directed=True,continuous=False)

The problem is that networkit change the nodes id, it should be caused by the fact that the nodes of my graph start from an arbitrary number (not 0 or 1) and are not continuous. I wonder if there is a way to prevent this from happening without having to change the numbering of my nodes.

Here a view of my edgelist

#from_address,to_address
39243,1040
39244,39245
39246,30
39247,39248
39249,1040
39250,2611

And here the code to see nodes id are changed

reader = nk.graphio.EdgeListReader(',',1,'#',directed=True,continuous=False)
try:
    g = reader.read(fname)
except: 
    print("File not exist")
    exit()
i = 0
for u, v in g.iterEdges():
    if i > 5:
        print('...')
        break
    print(u, v)
    i += 1

>
0 1
2 3
4 5
6 7
8 1
9 10
...
4

1 回答 1

2

NetworKit 节点 ID 始终在 [0, n-1] 区间内。但是,您仍然可以通过从您的 id 检索映射到具有reader.getNodeMap(). 这是一个例子:

import networkit as nk

reader = nk.graphio.EdgeListReader(',',1,'#',directed=True,continuous=False)
g = reader.read('edgelist.txt')
map = reader.getNodeMap()

# Using your example, this is the resulting map:
# {'1040': 1, '2611': 10, '30': 5, '39243': 0, '39244': 2, '39245': 3, '39246': 4, '39247': 6, '39248': 7, '39249': 8, '39250': 9}
于 2021-10-29T20:15:12.093 回答