Hello everybody,
I'm trying to use "dynamics vector" to store my graph's edges, because
I have a lot of edges. But the "igraph library" doesn't handle it.
there is some way to store my edges in the heap memory?
this is my code.
#include <igraph/igraph.h>
int
main(int argc, char* argv[])
{
igraph_t graph;
igraph_vector_t result;
igraph_vector_t weights;
igraph_real_t w = 10;
igraph_vector_ptr_t result_vector;
igraph_integer_t from = 100;
igraph_integer_t to = 400;
igraph_vector_t edges;
igraph_real_t *ptr_edges;
//igraph_real_t *ptr_edge[18];
/*igraph_real_t edges_v[] = {
100, 200,
100, 300,
200, 400,
300, 600,
300, 500,
400, 300,
500, 700,
700, 600,
800, 600
};*/
if ( (ptr_edges = calloc(9 * 2, sizeof(igraph_real_t))) == NULL)
{
/*
ptr_edge[0] = 100; ptr_edge[1] = 200;
ptr_edge[2] = 100; ptr_edge[3] = 300;
ptr_edge[4] = 200; ptr_edge[5] = 400;
ptr_edge[6] = 300; ptr_edge[7] = 600;
ptr_edge[8] = 300; ptr_edge[9] = 500;
ptr_edge[10] = 400; ptr_edge[11] = 300;
ptr_edge[12] = 500; ptr_edge[13] = 700;
ptr_edge[14] = 700; ptr_edge[15] = 600;
ptr_edge[16] = 800; ptr_edge[17] = 600;
*/
*(ptr_edges+0) = 100; *(ptr_edges+1) = 200;
*(ptr_edges+2) = 100; *(ptr_edges+3) = 300;
*(ptr_edges+4) = 200; *(ptr_edges+5) = 400;
*(ptr_edges+6) = 300; *(ptr_edges+7) = 600;
*(ptr_edges+8) = 300; *(ptr_edges+9) = 500;
*(ptr_edges+10) = 400; *(ptr_edges+11) = 300;
*(ptr_edges+12) = 500; *(ptr_edges+13) = 700;
*(ptr_edges+14) = 700; *(ptr_edges+15) = 600;
*(ptr_edges+16) = 800; *(ptr_edges+17) = 600;
}
igraph_vector_view(&edges, ptr_edges, sizeof(9 * 2,
sizeof(igraph_real_t))/sizeof(igraph_real_t));
igraph_create( &graph, &edges, 0, IGRAPH_DIRECTED);
igraph_vector_init(&result, 0);
igraph_vector_ptr_init(&result_vector, 1);
VECTOR(result_vector)[0] = &result;
igraph_vector_init( &weights, igraph_ecount(&graph) );
printf("vertices: %i, lados: %i\n", (int)igraph_vcount(&graph),
(int)igraph_ecount(&graph));
igraph_vector_fill(&weights, w);
igraph_get_shortest_paths_dijkstra( &graph,
&result_vector,
from,
igraph_vss_1(to),
&weights,
IGRAPH_OUT);
for (int i = 0; i < igraph_vector_size(&result); i++)
{
printf("%ld ", (long) igraph_vector_e(&result, i));
}
printf("\n");
igraph_destroy(&graph);
igraph_vector_destroy(&result);
igraph_vector_destroy(&weights);
igraph_vector_ptr_destroy(&result_vector);
return EXIT_SUCCESS;
}
this is my output:
address@hidden igraphtest]$ build/myigraph
vertices: 0, lados: 0
Error at iterators.c:709 :Cannot create iterator, invalid vertex id,
Invalid vertex id
Abortado
_______________________________________________
igraph-help mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/igraph-help