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