简体   繁体   中英

Can't generate igraph_degree_sequence_game on igraph

I want to use the igraph_degree_sequence_game igraph graph generator to generate a network. The example on the igraph C library works well on my computer, but if I change to some other simple degree distributions (see the code below), I got this error:

Error at games.c:830 :degree sequence game (simple), Out of memory.

I expect this gives me an undirected network with 4 nodes and each of it has 3 neighbors. I don't know where did I do wrong. Thank you for your kind help and response.

#include <igraph.h>

int main() {
  igraph_t g;
  igraph_vector_t outdeg, indeg, vec;
  igraph_bool_t is_simple;

  igraph_vector_init_real(&outdeg, 4,3,3,3,3);
  igraph_vector_init(&vec, 0);

  /* checking the simple method, undirected graphs */
  igraph_degree_sequence_game(&g, &outdeg, 0, IGRAPH_DEGSEQ_SIMPLE);
  if (igraph_is_directed(&g) || igraph_vcount(&g) != 4)
  return 1;
  if (igraph_degree(&g, &vec, igraph_vss_all(), IGRAPH_OUT, 1))
  return 2;
  igraph_vector_print(&vec);
  igraph_destroy(&g);


  igraph_vector_destroy(&vec);
  igraph_vector_destroy(&outdeg);
  igraph_vector_destroy(&indeg);

  return 0;
}

I guess the example should be updated, because igraph_vector_init_real is not part of the public API. Anyway, the problem is, that (as the name suggests), this function expects real (ie double) literals. Ie the correct way to use it is

igraph_vector_init_real(&outdeg, 4, 3.0, 3.0, 3.0, 3.0);

Btw. another error in your code is calling igraph_vector_destroy on indeg , which was never initialized. This might or might not generate a runtime error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM