无法在 igraph 上生成 igraph_degree_sequence_game

Can't generate igraph_degree_sequence_game on igraph

我想使用 igraph_degree_sequence_game igraph 图生成器生成网络。 igraph C 库上的示例在我的计算机上运行良好,但如果我更改为其他一些简单的度数分布(请参阅下面的代码),我会收到此错误:

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

我希望这会给我一个具有 4 个节点的无向​​网络,每个节点都有 3 个邻居。我不知道我哪里做错了。感谢您的帮助和回复。

#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;
}

我想应该更新示例,因为 igraph_vector_init_real 不是 public API 的一部分。无论如何,问题是,(顾名思义)这个函数需要真实的(即双精度)文字。 IE。正确的使用方法是

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

顺便说一句。您的代码中的另一个错误是在 indeg 上调用 igraph_vector_destroy,它从未被初始化。这可能会也可能不会生成运行时错误。