|
From: | Christian Gonzalez |
Subject: | Re: [igraph] Using dynamics vectors to storage my graph's edges |
Date: | Thu, 16 Jul 2009 14:33:37 -0430 |
User-agent: | Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b3pre) Gecko/20090513 Fedora/3.0-2.3.beta2.fc11 Lightning/1.0pre Thunderbird/3.0b2 |
Hi Gábor, To begin with I want to thanks you for your soon answer, I omitted information in my last email, becouse I use eclipse IDE, but the correct information is: Source code: #include <stdlib.h> #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 = (igraph_real_t*)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; } line to compiling: #gcc test.c -std=gnu99 -I/usr/include -I/usr/include/igraph -L/usr/lib -ligraph -o test Thanks, Christian El 16/07/09 04:51, Gábor Csárdi escribió: Hi Christian, your code does not compile with gcc 4.3.3 (or g++ 4.3.3), which compiler do you actually use? On which platform? On Linux I get address@hidden:/tmp$ gcc test.c -I /home/csardi/works/igraph/0.5-main/include/ -ligraph -L /home/csardi/works/igraph/0.5-main/src/.libs/ -o test test.c: In function ‘main’: test.c:31: warning: incompatible implicit declaration of built-in function ‘calloc’ test.c:79: error: ‘for’ loop initial declaration used outside C99 mode test.c:91: error: ‘EXIT_SUCCESS’ undeclared (first use in this function) test.c:91: error: (Each undeclared identifier is reported only once test.c:91: error: for each function it appears in.) address@hidden:/tmp$ g++ test.c -I /home/csardi/works/igraph/0.5-main/include/ -ligraph -L /home/csardi/works/igraph/0.5-main/src/.libs/ -o test test.c: In function ‘int main(int, char**)’: test.c:31: error: ‘calloc’ was not declared in this scope test.c:91: error: ‘EXIT_SUCCESS’ was not declared in this scope After defining EXIT_SUCCESS, including stdlib.h and getting rid of the c++ style loop variable, I could compile it. See more below. On Wed, Jul 15, 2009 at 11:59 PM, Christian Gonzalez<address@hidden> wrote: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.[...]if ( (ptr_edges = calloc(9 * 2, sizeof(igraph_real_t))) == NULL)This should be != NULL instead of == NULL, I guess. Btw, why don't you quit or report an error if calloc returns with an error? [...]*(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;Why do you fill the vector this way? You don't need to define it as a view, you can add elements to the vector directly, e.g. VECTOR(edges)[0]=100; VECTOR(edges)[1]=200; etc.igraph_vector_view(&edges, ptr_edges, sizeof(9 * 2, sizeof(igraph_real_t))/sizeof(igraph_real_t));This does not make sense, one 'sizeof' is not needed, just think about it. This should be igraph_vector_view(&edges, ptr_edges, 9*2); [...]igraph_vector_fill(&weights, w);If all the weights are the same, then you can just pass a null pointer instead of the weights vector. [...]igraph_destroy(&graph); igraph_vector_destroy(&result); igraph_vector_destroy(&weights); igraph_vector_ptr_destroy(&result_vector);You forgot to free ptr_edges.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[...] Best, Gabor |
[Prev in Thread] | Current Thread | [Next in Thread] |