Skip to content

Instantly share code, notes, and snippets.

@disa-mhembere
Last active August 29, 2015 14:03
Show Gist options
  • Save disa-mhembere/4d0536793f42ed04c153 to your computer and use it in GitHub Desktop.
Save disa-mhembere/4d0536793f42ed04c153 to your computer and use it in GitHub Desktop.
Iterate all edges and src, target and weight
#include <igraph.h>
#include <stdio.h>
void custom_warning_handler (const char *reason, const char *file,
int line, int igraph_errno) {
printf("Warning: %s\n", reason);
}
int main(int argc, char* argv[])
{
char * in_graph_fn;
char * out_graph_fn;
if (argc < 3) {
printf("[ERROR] usage: mm-writer in_graph_fn out_graph_fn\n");
exit(-1);
}
else {
in_graph_fn = &argv[1][0];
out_graph_fn = &argv[2][0];
}
igraph_t g;
long int i;
igraph_integer_t size;
igraph_vs_t vs; // Vertex selector
igraph_vit_t vit; // Vertex iterator
igraph_error_handler_t* oldhandler;
igraph_warning_handler_t* oldwarnhandler;
int result;
FILE *ifile, *ofile;
ifile = fopen(in_graph_fn, "r");
if (ifile == 0) {
return 10;
}
igraph_read_graph_graphml(&g, ifile, 0);
fclose(ifile);
igraph_to_directed(&g, IGRAPH_TO_DIRECTED_ARBITRARY);
printf("The graph stats:\n");
printf("Vertices: %li\n", (long int) igraph_vcount(&g));
printf("Edges: %li\n", (long int) igraph_ecount(&g));
printf("Directed: %i\n", (int) igraph_is_directed(&g));
igraph_i_set_attribute_table(&igraph_cattribute_table);
if ( igraph_cattribute_has_attr(&g, IGRAPH_ATTRIBUTE_EDGE, "weight") ) { // SEG FAULT here :/
printf("Got it\n");
}
else {
printf("Don't!\n");
}
igraph_vit_destroy(&vit);
igraph_vs_destroy(&vs);
igraph_destroy(&g);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment