[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[igraph] create a (weighted) graph in C from txt files

From: Francois Bastardie
Subject: [igraph] create a (weighted) graph in C from txt files
Date: Mon, 29 Nov 2010 17:56:10 +0100

Dear all ,


I am a R user of the igraph library which I found very useful, thank you very much to the authors.


I would like now to switch to C/C++ because I would like to speed up my entire code which actually includes the igraph library only as a subroutine. However I am not very proficient in C/C++ and then I would like to ask you if you can help me for the beginning. I managed to compile igraph in a .dll using the microsoft visual C++ software and then I launched some examples embedded  with the library.


Here it is: I would like to translate these following lines from R to some equivalent lines in C++. It is about a spatial network of nodes:




coord <- matrix(c(10, 9, 2, 4, 7,8, 45,34), ncol=2) # fake

graph <- matrix(c(1,2,34,2,3,35,3,1,37, 4,1,30),ncol=3, byrow=TRUE) #fake

 vertices    <- data.frame(name=as.character(unique(graph[,1])), x=coord[,1], y=coord[,2])  # name of the node, longitude, latitude

 edges        <- data.frame(from=c(graph[,1]),


                        dist.km=graph[,3]) # name of the departure node, name of the arrival node, distance in km

 g <- graph.data.frame(edges, directed=FALSE, vertices=vertices)


I do not want to enter this by hand actually because I have more than 15000 nodes in my actual data...


My first guess is that I have to use the following C method to get back a graph with weighted edges (i.e. the distances between nodes)?

int igraph_read_graph_ncol(igraph_t *graph, FILE *instream,

                          igraph_strvector_t *predefnames,

                          igraph_bool_t names, igraph_bool_t weights, igraph_bool_t directed);


In addition, I´m always struggling with the import/export of the files and that was one of the (many) reasons why I mainly used R for my work because with R we do not have to bother very much for importing and creating objects.

Could you please give me some clues/examples to do that i.e. how to import the coordinates of the nodes and the distances between nodes in C/C++, and then create the graph I want?


Thank you very much,

Best regards,





reply via email to

[Prev in Thread] Current Thread [Next in Thread]