安装

git clone https://github.com/igraph/igraph
cd igraph
./bootstrap.sh
./configure --prefix=$MY_LOCAL
make
make install
export CPATH="$MY_LOCAL/include:$CPATH"
export LD_LIBRARY_PATH="$MY_LOCAL/lib:$LD_LIBRARY_PATH"

示例代码

以下代码创建了一个6个节点的空图,添加了8条边,又添加了2个节点和4条边

%:include <igraph/igraph.h>
int main(void)
{
    igraph_t graph;
    igraph_vector_t edges;
    igraph_real_t data[] = {0,1,0,2,0,5,1,2,1,4,2,4,1,3,3,5};
    igraph_vector_view(&edges, data, sizeof(data)/sizeof(double));

    igraph_empty(&graph, 6, IGRAPH_UNDIRECTED);
    igraph_add_edges(&graph, &edges, 0);

    igraph_add_vertices(&graph, 2, 0);
    igraph_add_edge(&graph, 6,4);
    igraph_add_edge(&graph, 6,5);
    igraph_add_edge(&graph, 7,5);
    igraph_add_edge(&graph, 7,3);

    printf("vertices: %d, edges: %d\n", (int)igraph_vcount(&graph), (int)igraph_ecount(&graph));

    igraph_destroy(&graph);
    return 0;
}

使用如下命令编译

gcc test.c -ligraph

标签: none

评论已关闭