I am trying to get the shortest path from one node to another in a weighted graph. Using the function igraph_get_shortest_path_dijkstra I need to get the edges weight as one of the arguments, but I dont understand how to get them. I am using a graph initialized with igraph_adjacency using a weighted matrix, shouldnt weights be already present in the graph? Is there a way to get the weights that match exactly the edges? I have tried using the macro EANV to query for the attribute of all edges but I get segmentation fault.
So far this it my code
#include <igraph.h>
int main()
{
igraph_matrix_t connectome;
igraph_vector_t vertices, weights;
const char *att = "weight";
igraph_t graph;
igraph_matrix_init(&connectome, 82, 82);
igraph_matrix_set(&connectome, 0, 1, 5);
igraph_matrix_set(&connectome, 0, 2, 1);
igraph_matrix_set(&connectome, 1, 2, 1);
igraph_weighted_adjacency(&graph, &connectome, IGRAPH_ADJ_UNDIRECTED, att, 1);
igraph_vector_init(&vertices, 0);
igraph_vector_init(&weights, 82 * 81 / 2);
EANV(&graph, att, &weights);
igraph_get_shortest_path_dijkstra(&graph, &vertices, NULL, 0, 1, 0, IGRAPH_ALL);
printf("Shortest path between 1 and 0 is");
for (int i = 0; i < igraph_vector_size(&vertices); i++)
{
printf(" %g ", (double)igraph_vector_e(&vertices, i));
}
printf("\n");
igraph_matrix_destroy(&connectome);
igraph_vector_destroy(&vertices);
igraph_destroy(&graph);
return 0;
}
Its just a silly test to try the weighted shortest path. I get segmentation fault when the program runs EANV. If someone could help me I would appreciate it.
Thanks in advance