与问题“边缘 - 权重关联”和Tamás的答案相关,我编写了下面的代码来获得从原始向量权重中提取的mst树的弧度。当我移动到igraph 0.6时,我将使用此代码。
有些人看到代码中的一些错误或改进,一般都像igraph使用一样。
谢谢,吉列尔莫。 代码:
int igraph_get_weight_subtree( igraph_t subtree, igraph_t grafo, igraph_vector_t vector_pesos_grafo, igraph_vector_t *vector_pesos_subtree){
igraph_vector_t vector_arcos_grafo, vector_arcos_subtree;
int i,j,k;
igraph_real_t sub_tree_nodo1, sub_tree_nodo2;
printf("\nigraph_get_weight_subtree: Imprimiendo arcos de subtree...\n");
igraph_write_graph_edgelist(&subtree, stdout);
printf("[OK]\n");
printf("\nigraph_get_weight_subtree: Imprimiendo arcos de grafo...\n");
igraph_write_graph_edgelist(&grafo, stdout);
printf("[OK]\n");
//Inicializa los vectores vector_arcos_subtree y vector_arcos_grafo
igraph_vector_init(&vector_arcos_subtree,1);
igraph_vector_init(&vector_arcos_grafo,1);
//Extrae los arcos desde los grafos de entrada. Los convierte en Vector
igraph_get_edgelist(&subtree, &vector_arcos_subtree, 0);
igraph_get_edgelist(&grafo, &vector_arcos_grafo, 0);
for (i=0; i< igraph_vector_size(&vector_arcos_subtree); i=i+2){
sub_tree_nodo1= VECTOR(vector_arcos_subtree)[i];
sub_tree_nodo2= VECTOR(vector_arcos_subtree)[i+1];
//Busca arco de subtree en grafo
j=0;
k=0;
while(j< igraph_vector_size(&vector_arcos_grafo)){
if( ((sub_tree_nodo1==VECTOR(vector_arcos_grafo)[j])&& (sub_tree_nodo2==VECTOR(vector_arcos_grafo)[j+1]))|| ((sub_tree_nodo2==VECTOR(vector_arcos_grafo)[j])&&(sub_tree_nodo1==VECTOR(vector_arcos_grafo)[j+1]))) {
igraph_vector_push_back (vector_pesos_subtree, VECTOR(vector_pesos_grafo)[k]);
break;
}//End if
j=j+2;
k=k+1;
}//End while
}
//Destruye los vectore en desuso
igraph_vector_destroy(&vector_arcos_subtree);
igraph_vector_destroy(&vector_arcos_grafo);
return 0;
}