[Top][All Lists]

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

Re: [igraph] Specifying edge weights

From: Tamas Nepusz
Subject: Re: [igraph] Specifying edge weights
Date: Fri, 12 Feb 2010 23:36:44 +0000


> I am trying to use igraph to find the shortest path in a directed weighted 
> graph. I don't see how to specify the edge weights though. I see quite well 
> that I should pass "const igraph_vector_t *weights" to the shortest paths 
> function (in this case "igraph_get_shortest_paths_dijkstra") but the 
> documentation doesn't describe how to construct such a vector so that igraph 
> understands it (or, at least the docs available at 
> http://igraph.sourceforge.net/doc/html/).
The weights vector must contain a single value for each edge in the graph; the 
first element of the vector corresponds to the edge with ID 0, the second to 
the edge with ID 1 and so on. (Remember, igraph uses numeric IDs for the edges, 
starting from zero).

> The contents of the result vector are described poorly as well. It apparently 
> contains more vectors... which contain? And if it contains the path, how do I 
> know which edges were used?
The result will contain one vector for each target vertex, exactly in the order 
in which they were returned by the original vertex selector that you passed in 
the "to" argument. (igraph_vss_all() returns the vertices in increasing order 
of their IDs, if you happen to use that). IIRC the vectors themselves contain 
vertex IDs along the shortest paths; if you need the edge IDs, you can use 
igraph_get_eids in consecutive vertex IDs to obtain the edge IDs. Note that 
igraph 0.6 will change the API of igraph_get_shortest_paths_dijkstra slightly, 
there will be a possibility to retrieve the vertex IDs, the edge IDs or both 
along the shortet paths.


reply via email to

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