获取所有边 ID 的向量

Get a vector of all edges ids

igraph 的 c/c++ 库中,我试图编写一个 returns graph 的随机边的函数。目的是编写一个更大的函数,在每个时间步 "visits" 一个随机边,并在所有边都被访问后停止。每次访问时,都会执行一些外部代码。

为了编写这样的函数,我需要能够首先接收一个列表/向量/任何包含 graph 边的所有 eid 的内容。在手册中,我只看到了 igraph_get_eids,其中 returns 是沿着路径或相对于顶点对向量的边 ID 列表。

当然,我可以手动创建所有顶点对的向量并将其用作上述函数的输入,但这似乎有点矫枉过正,而且可能是更直接(和高效?)的解决方案那里...

igraph 的边 ID 始终是从零到 igraph_ecount(graph)-1(含)的连续整数,因此您可以简单地从该范围生成一个随机整数以从图中绘制随机边。

引用igraph manual

The igraph graphs are multisets of ordered (if directed) or unordered (if undirected) labeled pairs. The labels of the pairs plus the number of vertices always starts with zero and ends with the number of edges minus one.