Deleting an edge in graph for C

五迷三道 提交于 2020-01-17 06:18:27

问题


I'm trying to delete a randomly selected edge form a igraph (http://igraph.org/c/) graph called "g".

Igraph's manual for "igraph_delete_edges" function is here: http://igraph.org/c/doc/igraph-Basic.html#igraph_delete_edges But it's still not enough for me to figure it out.

I've got this:

#include <stdio.h>
#include <igraph/igraph.h>

int main() {

igraph_t g;
igraph_vector_t v;

igraph_vector_t edges;
igraph_vector_init(&edges,0);

igraph_vector_t indices;
igraph_vector_init(&indices, 0);

igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, 100, .10,IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS); // Create a random graph

igraph_get_edgelist(&g, &edges, 0); // Put the graph's list of indices in "edges"
int r = rand() % igraph_vector_size(&edges); // Get a random edge index

igraph_vector_push_back(&indices, r); // create a vector of size 1 in which to put the random index found above

igraph_delete_edges(&g, igraph_es_vector(&indices)); // Delete that edge
}

This doesn't seem to be the way to use igraph_delete_edges (and it sure is very wordy for such a simple operation...) What's the proper way to do use igraph_delete_edges in igraph for C?

来源:https://stackoverflow.com/questions/36366716/deleting-an-edge-in-graph-for-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!