diff --git a/pink/kruskal.c b/pink/kruskal.c index 470615a..18375aa 100644 --- a/pink/kruskal.c +++ b/pink/kruskal.c @@ -48,7 +48,7 @@ list * MSF_Kruskal(MergeTree * MT) // max_weight /* maximum weight value */ int i, j, k, x, y, e1, e2; int nb_markers; int nb_leafs; long N, M; - + float val=1; //weight parameter for leafs. mtree * T= MT->tree; float * W = MT->weights; // mergeTreePrint(T); @@ -89,11 +89,10 @@ list * MSF_Kruskal(MergeTree * MT) // max_weight /* maximum weight value */ { SeededNodes[j]= i+CT->nbnodes; Mrk[SeededNodes[j]] = 1; - //printf("seeded node %d \n", SeededNodes[j]); - j++; + j++; } - Mrk[M] = 0; - + Mrk[M] = 1; + uint32_t * Rnk = (uint32_t*)calloc(N, sizeof(uint32_t)); if (Rnk == NULL) { fprintf(stderr, "kruskal : malloc failed\n"); exit(0); } uint32_t * Fth = (uint32_t*)malloc(N*sizeof(uint32_t)); @@ -110,10 +109,8 @@ list * MSF_Kruskal(MergeTree * MT) // max_weight /* maximum weight value */ sorted_weights[k]=W[k]; for(k=0;knbnodes+k]=0.5; - //fprintf(stderr,"%f\n", sorted_weights[CT->nbnodes+k]); - } + sorted_weights[CT->nbnodes+k]=val; + TriRapideStochastique_dec(sorted_weights,Es, 0, M-1); free(sorted_weights); @@ -122,7 +119,7 @@ list * MSF_Kruskal(MergeTree * MT) // max_weight /* maximum weight value */ long cpt_aretes = 0; // beginning of main loop - while (nb_arete < N-nb_markers+1) + while (nb_arete < N-nb_markers) { e_max=Es[cpt_aretes]; cpt_aretes=cpt_aretes+1; @@ -130,11 +127,13 @@ list * MSF_Kruskal(MergeTree * MT) // max_weight /* maximum weight value */ if (e_maxnbnodes) e2= CT->tabnodes[e_max].father; else e2= e_max-CT->nbnodes; if (e2==-1)e2=M; //e2 = Edges[1][e_max]; + //printf("(%d %d)\n", e1,e2); x = element_find(e1, Fth ); y = element_find(e2, Fth ); if ((x != y) && (!(Mrk[x]>=1 && Mrk[y]>=1))) { root = element_link( x,y, Rnk, Fth); + //printf("link\n"); nb_arete=nb_arete+1; if ( Mrk[x]>=1) Mrk[root]= Mrk[x]; else if ( Mrk[y]>=1) Mrk[root]= Mrk[y]; @@ -145,11 +144,9 @@ list * MSF_Kruskal(MergeTree * MT) // max_weight /* maximum weight value */ // (find the root vertex of each tree) int * Map2 = (int *)malloc(N*sizeof(int)); int * Map = (int *)malloc(N*sizeof(int)); - for (i=0; iindex); @@ -244,6 +243,7 @@ int nb_neighbors(int x, JCctree *CT, int nb_leafs) int neighbor(int x, int k, JCctree *CT, int nb_leafs, int * SeededNodes) /*================================================*/ { + JCsoncell *s;int i, tmp; if (xnbnodes) { @@ -257,6 +257,7 @@ int neighbor(int x, int k, JCctree *CT, int nb_leafs, int * SeededNodes) if (k==tmp) return CT->tabnodes[x].father; s = CT->tabnodes[x].sonlist; for (i=0;inext; // INEFFICACE A REFAIRE + //fprintf(stderr," ici "); return s->son; } } @@ -296,25 +297,6 @@ int element_find(int x, uint32_t *Fth ) return Fth[x]; } -/* // Printing the merge tree - int32_t i; - JCsoncell *s; - JCctree *CT = MT->CT; - printf("root = %d ; nbnodes: %d ; nbsoncells: %d\n", CT->root, CT->nbnodes, CT->nbsoncells); - for (i = 0; i < CT->nbnodes; i++) - { - printf("node: %d ; level %d ; nbsons: %d ; father: %d ; mergeEdge %d", - i, CT->tabnodes[i].data, CT->tabnodes[i].nbsons, CT->tabnodes[i].father, MT->mergeEdge[i]); - if (CT->tabnodes[i].nbsons > 0) - { - printf("sons: "); - for (s = CT->tabnodes[i].sonlist; s != NULL; s = s->next) - printf("%d ", s->son); - } - printf("\n"); - } -*/ - /* =============================================================== */ long Partitionner_dec(float *A, uint32_t * I, long p, long r) /* =============================================================== */ @@ -358,7 +340,6 @@ long PartitionStochastique_dec (float *A, uint32_t * I, long p, long r) long q; q = p + (genrand64_int64() % (r - p + 1)); /* rand must be 64-bit safe, should be OK now */ - // assert((q >= p) && (q <= r)) ; /* you'd be surprised */ t = A[p]; /* echange A[p] et A[q] */ A[p] = A[q]; A[q] = t;