Improvement of a C function based in igraph [closed]
Related with the question "Edge - weight association" and the Tamás's answer, I wrote the below code to get the arc weigth of the mst tree extracted from the original vector weigth. I开发者_如何学编程 will use this code while I move to igraph 0.6.
Some one see some mistake or improvement in the code, both general like in the igraph use.
Thanks, Guillermo. The code:
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;
}
精彩评论