29 {
30 int ncluster = clusters_.size();
31 double minwgt = cutoff;
32
33 std::sort(clusters_.begin(), clusters_.end(), compClusters);
34 do {
35 bool any = false;
36 size_t mi(0), mj(0);
37
38 int nseeds = 0;
39
40 for (size_t i = 0; i < clusters_.size(); i++) {
41 if (clusters_[i].empty()) continue;
42
43 bool iseed = (clusters_[i].centroid().E() >= seed_threshold);
44 if (iseed) {
45 nseeds++;
46 } else {
47
48
49 break;
50 }
51
52 for (size_t j = i + 1; j < clusters_.size(); j++) {
53 if (clusters_[j].empty() ||
54 (!iseed && clusters_[j].centroid().E() < seed_threshold))
55 continue;
56 double wgt = wgt_(clusters_[i], clusters_[j]);
57 if (!any || wgt < minwgt) {
58 any = true;
59 minwgt = wgt;
60 mi = i;
61 mj = j;
62 }
63 }
64 }
65
66 nseeds_ = nseeds;
67 transitionWeights_.insert(std::pair<int, double>(ncluster, minwgt));
68
69 if (any && minwgt < cutoff) {
70
71 if (clusters_[mi].centroid().E() < clusters_[mj].centroid().E()) {
72 std::swap(mi, mj);
73 }
74
75 clusters_[mi].add(clusters_[mj]);
76 clusters_[mj].clear();
77
78 ncluster--;
79 }
80
81 } while (minwgt < cutoff && ncluster > 1);
82 finalwgt_ = minwgt;
83 }