On 27.06.2015 18:08, kenanh wrote:
Hi,
I'm loading directed weighted graph from csv file into graph-tool graph graph. The organization of the input csv file is:
1,2,300 2,4,432 3,89,1.24 ...
Where the fist two entries of a line identify source and target of an edge and the third number is the weight of the edge.
Currently I'm using:
import csv g = gt.Graph() e_weight = g.new_edge_property("float") f_network = open(in_file_directory+ '/'+network_input, 'r') reader_network = csv.reader(f_network, delimiter=delimiter) for edge in reader_network: e = g.add_edge(int(edge[0]), int(edge[1])) e_weight[e] = float(edge[2]) f_network.close()
However it takes quite long to load the data (I have network of 10 millions of nodes). I have tried to make it faster by using g.add_edge_list, but this works only for unweighted graphs. Any suggestion how to make it faster?
Yes, use g.add_edge_list() for the edges, and put the weights separately via the array interface for property maps: e_weight.a = weight_list The weight list should have the same ordering as the edges you passed to g.add_edge_list(). Best, Tiago -- Tiago de Paula Peixoto <tiago@skewed.de>