igraph-help
[Top][All Lists]

## Re: [igraph] Re: shortest path length

 From: Gábor Csárdi Subject: Re: [igraph] Re: shortest path length Date: Thu, 18 Jun 2009 13:49:00 +0200

Yong,

you need to allocate the vector(s) for the result before calling the function. I.e. in this case you need:

igraph_ptr_t results_paths;
igraph_vector_t result_path;

[...]

igraph_vector_init(&result_path, 0);
igraph_vector_ptr_init(&result_paths, 1);
VECTOR(result_paths)[0] = &result_path;

[...]

Btw. igraph_get_shortest_path will just return _one_ shortest path for every vertex included in 'to'.

Gabor

On Thu, Jun 18, 2009 at 10:32 AM, Yong Zou wrote:
Hi Tamas,

Thanks a lot for helping me. I tried to understand how to write a
correct code. It seems that I always get a
message:"structural_properties.c:873 :Size of the `res' and the `to'
should match".

igraph_t graph;
igraph_vector_ptr_t result_paths;
igraph_vector_t *result_path;
igraph_integer_t from_node;
igraph_integer_t to_node;

igraph_vector_ptr_init(&result_paths, 0);
from_node = 10;
to_node = 1000;
igraph_get_shortest_paths(&graph, &result_paths, from_node,
igraph_vss_1(to_node), IGRAPH_ALL);
result_path = igraph_vector_ptr_e(&result_paths, 0);   // get the
first path in the result vector
for (i=0; i<igraph_vector_size(result_path); i++) {
printf("%ld ", (long)igraph_vector_e(result_path, i));
}
printf("\n");
igraph_vector_destroy(result_path);        // destroy the path
igraph_vector_ptr_destroy(result_paths);   // free all the pointers
and destroy the pointer list

Best,

_______________________________________________
igraph-help mailing list