Hi, I'm pretty sure that the identifiers that you use in your graph are stored in the "name" vertex attribute and the integer IDs in igraph are assigned arbitrarily (since both Graph.Read_Ncol and Graph.TupleList accepts arbitrary names as vertex identifiers, not only integers). Since the vertex IDs in your file seem to be integers from zero to |V|-1, use Graph.Read_Edgelist -- this will use the integer IDs from your file as is, and the edge lookups by ID will behave as expected.
T. On 04/05, Stefano Scerra wrote: > (Sorry for accidentally double posting) > Hello, > I'm having a really strange problem with the library and I was hoping to > get some advice. > > After loading a large 19 million edges graph, the library returns an > inconsistent edge list. > More precisely, nonexistent edges appear in the graph's edge sequence. > > I try to load the graph in two different ways, by using Graph.Read_Ncol, > and by manually reading the edgelist and then using Graph.TupleList. In > both cases, iterating on the graph's edge sequence (the es attribute) > yields inconsistent results: for instance, the nonexisting edge 10->11 is > returned. > > I'm using igraph 0.7.1-4 on Python 3.4.3 64 bit on Windows 7 SP1 64 bit > Link to the graph: > https://drive.google.com/file/d/0B0afrBfsijreOS1BZkVfdE10TlE/view?usp=sharing > > Here's the code: > > from igraph import Graph > import csv > import timeit > > def create_graph(file_graph): > # load graph using Graph.Read_Ncol > with open(file_graph, "r") as in_file: > g = Graph.Read_Ncol(in_file, weights=False, directed=True) > return g > > def create_graph2(file_graph): > # load graph using Graph.TupleList > edges = [] > with open(file_graph, "r") as in_file: > reader = csv.reader(in_file, delimiter=" ") > i = 0 > for row in reader: > if row: > edges.append([int(row[0]), int(row[1])]) > i += 1 > if i % 100000 == 0: print(i) > return Graph.TupleList(edges=edges, directed=True) > > > def generate_weighted_graph(input, output): > g = create_graph2(input) > print("ecount:", g.ecount(), "vcount:", g.vcount()) > with open(output, "w") as output_file: > writer = csv.writer(output_file, delimiter=" ") > for e in g.es: > i, j = e.source, e.target > writer.writerow([i, j]) > > if __name__ == "__main__": > generate_weighted_graph("C:/datasets/network", > "C:/datasets/network_weighted") > > > Could this possibly be a bug? > Any help would be appreciated, thank you! > Stefano > _______________________________________________ > igraph-help mailing list > [email protected] > https://lists.nongnu.org/mailman/listinfo/igraph-help -- T. _______________________________________________ igraph-help mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/igraph-help
