Nig*_*Fox 5 c graph igraph minimum-spanning-tree weighted
问题:我想.csv使用igraph 从存储在文件中的邻接矩阵制作加权无向图,然后对其进行最小生成树和其他算法.
我开始制作一个有10个顶点和5个边的有向图.默认情况下,igraph不允许边缘权重,你必须使用一些对我来说没有意义的属性(类似于igraph_i_set_attribute_table).
有人可以帮我解决这个问题.
void print_vector(igraph_vector_t *v, FILE *f) {
long int i;
for (i=0; i<igraph_vector_size(v); i++) {
fprintf(f, " %li", (long int) VECTOR(*v)[i]);
}
fprintf(f, "\n");
}
int main(int argc, char* argv[])
{
igraph_t g;
igraph_vector_t v;
int ret;
igraph_es_t es;
/* Initialize the vector for edges */
igraph_vector_init(&v,10);
VECTOR(v)[0]=0;VECTOR(v)[1]=1;
VECTOR(v)[2]=1;VECTOR(v)[3]=3;
VECTOR(v)[4]=1;VECTOR(v)[5]=5;
VECTOR(v)[6]=2;VECTOR(v)[7]=3;
VECTOR(v)[8]=2;VECTOR(v)[9]=5;
igraph_create(&g,&v,0,IGRAPH_DIRECTED);
print_vector(&v,stdout);
/* igraph_i_set_attribute_table(&igraph_cattribute_table); */
igraph_vector_destroy(&v);
igraph_destroy(&g);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
首先,一般来说,使用 R 或 Python 中的 igraph 会更好,属性得到更好的支持。例如,您可以根据属性值轻松选择顶点或边等。在 C 中,对属性的支持很少,并且在使用它们时,您大多需要自己进行操作。所以,除非你真的需要 C,否则我建议使用 R 或 Python。
如果您仍然想要 C,那么首先要记住的是您需要包括
igraph_i_set_attribute_table(&igraph_cattribute_table);
Run Code Online (Sandbox Code Playgroud)
在显式或隐式对属性执行任何操作之前,在代码中执行此操作。IE。即使您没有显式操作属性,但创建一个可能具有某些属性的图表,例如。读取 GraphML 文件中的图形,您之前需要此调用,否则属性将被删除。最好将调用包含在函数的开头main()。
您必须使用任何属性都是不正确的,我不确定您的意思。
至于属性的设置和查询见examples/simple目录下的文件:
https://github.com/igraph/igraph/blob/master/examples/simple/cattributes.c https://github.com/igraph/igraph/blob/master/examples/simple/cattributes2.c https:// github.com/igraph/igraph/blob/master/examples/simple/cattributes3.c https://github.com/igraph/igraph/blob/master/examples/simple/cattributes4.c
这些示例很大程度上是人为的,因为它们主要用于测试目的,但它们显示了基本用法。
| 归档时间: |
|
| 查看次数: |
1885 次 |
| 最近记录: |