Creating a weighted undirected graph in "igraph" in C / C ++

Problem: I want to make a weighted undirected graph from an adjacency matrix stored in a file .csvusing igraph, and then run a minimal spanning tree and some other algorithms on it.

I started by creating a directed graph with 10 vertices and 5 edges. By default, igraph does not allow weight for edges, and you should use some attributes that do not make sense to me (something like igraph_i_set_attribute_table) in the documentation.

Can someone please help me with this.

void print_vector(igraph_vector_t *v, FILE *f) {
  long int i;
  for (i=0; i<igraph_vector_size(v); i++) {
    fprintf(f, " %li", (long int) VECTOR(*v)[i]);
  }
  fprintf(f, "\n");
}

int main(int argc, char* argv[])
{
  igraph_t g;
  igraph_vector_t v;
  int ret;
  igraph_es_t es;

  /* Initialize the vector for edges */
  igraph_vector_init(&v,10);

  VECTOR(v)[0]=0;VECTOR(v)[1]=1;
  VECTOR(v)[2]=1;VECTOR(v)[3]=3;
  VECTOR(v)[4]=1;VECTOR(v)[5]=5;
  VECTOR(v)[6]=2;VECTOR(v)[7]=3;
  VECTOR(v)[8]=2;VECTOR(v)[9]=5;

  igraph_create(&g,&v,0,IGRAPH_DIRECTED);

  print_vector(&v,stdout);

  /* igraph_i_set_attribute_table(&igraph_cattribute_table); */

  igraph_vector_destroy(&v);
  igraph_destroy(&g);

  return 0;
}
+5
source share
1 answer

All Articles