[Networkit] Read simple edgelist

Maximilian Vogel maximilian.vogel at student.kit.edu
Fri Oct 2 20:26:58 CEST 2015

On 02.10.2015 11:32, Christian Staudt wrote:
> On 01 Oct 2015, at 22:21, Jérôme Deschênes <jeromedesch at gmail.com 
> <mailto:jeromedesch at gmail.com>> wrote:
>> So, is there a way in Networkit to get back the old ids?
>> Sorry for my newbyness!
> Hi Jerome,
> this is not newbyness, this is an obvious issue anyone who applies 
> NetworKit’s algorithms to do actual network analysis runs into.
> We’ve discussed this before and saw that we could improve support 
> here. Some work in this direction has already been done, I think there 
> is a working solution in case graph file reader preserves the mapping 
> from old to new id.
> @Max: Can you reply with some details?
Sure. It is possible, but not completely integrated into NetworKit. If 
the EdgeListReader reads a file with the parameter continuous=False, a 
mapping is created:file node ids -> graph node ids. But the workflow 
slightly changes:

reader = graphio.EdgeListReader(separator=' ',firstNode=0, continuous=False)
graph = reader.read(path)
mapping = reader.getNodeMap()

(Note: The parameter firstNode is ignored when continuous=False. It's 
not convenient that it has to passed and should be changed...)
Now, for the attachments there are some functions that should help. Feel 
free to integrate them in your scripts as their functionality is not yet 
in NetworKit.
Regarding your desired workflow:

results = []
# ...
# if you want a header row, describing the contents
helper.exportNodeValues("your_file.csv", mapping, results, 
# else this is sufficient
helper.exportNodeValues("your_file.csv", mapping, results)

You can also specifiy a different than the default delimiter=','. This 
should then produce the file in the desired format.

I hope this helps,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ira.uni-karlsruhe.de/mailman/private/networkit/attachments/20151002/62221188/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: helper.py
Type: text/x-python-script
Size: 2774 bytes
Desc: not available
URL: <https://lists.ira.uni-karlsruhe.de/mailman/private/networkit/attachments/20151002/62221188/attachment.bin>

More information about the NetworKit mailing list