[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[igraph] C code on attributes is confusing me
From: |
Marco |
Subject: |
[igraph] C code on attributes is confusing me |
Date: |
Tue, 19 Apr 2011 13:37:33 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.16) Gecko/20110307 Icedove/3.0.11 |
Hi,
consider the following code (which I wrote taking code from an old
program a wrote a while ago and which didn't work out as I expected):
#include <stdio.h>
#include <math.h>
#include <igraph.h>
#include <stdlib.h>
#include <string.h>
const char *state = "state";
int main (int argc, char ** argv){
igraph_vs_t g_vs;
igraph_vit_t g_vit;
igraph_t graph;
igraph_i_set_attribute_table(&igraph_cattribute_table);
igraph_tree(&graph,100,3,IGRAPH_TREE_UNDIRECTED);
igraph_vs_all(&g_vs);
igraph_vit_create(&graph,g_vs,&g_vit);
while (!IGRAPH_VIT_END(g_vit)) {
SETVAN(&graph, state, IGRAPH_VIT_GET(g_vit), -1);
IGRAPH_VIT_NEXT(g_vit);
}
IGRAPH_VIT_RESET(g_vit);
while (!IGRAPH_VIT_END(g_vit)){
fprintf(stderr, "%d, %d\n", (int)
IGRAPH_VIT_GET(g_vit),VAN(&graph,state, (int) IGRAPH_VIT_GET(g_vit)));
IGRAPH_VIT_NEXT(g_vit);
}
return 0;
}
The idea is to create a tree, visit each node (with vs and vit), and set
the (numeric) attribute for each node (attribute is called "state"), to -1.
Then visit it again from the start, and get the index of the node and
the value of "state" for each node.
The result of this code on my machine is like this:
0, 0
1, 0
2, 0
3, 0
......
96, 0
97, 0
98, 0
99, 0
Which is not exactly what I expected (I expected something like #node, -1).
Obviously I am wrong somewhere, but I don't understand where. Can you
point it out?
Thanks in advance,
marco
- [igraph] C code on attributes is confusing me,
Marco <=