igraph-help
[Top][All Lists]
Advanced

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

[igraph] Re: shortest path length


From: Tamas Nepusz
Subject: [igraph] Re: shortest path length
Date: Thu, 18 Jun 2009 12:22:54 +0100
User-agent: Mutt/1.5.17 (2007-11-01)

Hi,

Whoops. Looks like you should prepare the result vector in advance so it
has exactly as many initialized vectors as needed. Since you are asking
for the shortest paths for a single target vertex, you should do this:

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, 1);
// The next statement is a shortcut macro for setting an element of an
// igraph vector
VECTOR(*result_paths)[0] = result_path;
from_node = 10;
to_node = 1000;
igraph_get_shortest_paths(&graph, &result_paths, from_node,
                          igraph_vss_1(to_node), IGRAPH_ALL);
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);   // destroy the pointer vector

Hope this works,
-- 
Tamas

Attachment: pgp0C8zsWz_5o.pgp
Description: PGP signature


reply via email to

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