26 {
27 int ncluster = clusters_.size();
28 double minwgt = cutoff;
29 std::sort(clusters_.begin(), clusters_.end(), compClusters);
30 do {
31 bool any = false;
32 unsigned int mi(0), mj(0);
33
34 int nseeds = 0;
35
36 for (unsigned int i = 0; i < clusters_.size(); i++) {
37
38 if (clusters_[i].empty()) continue;
39
40 bool iseed = (clusters_[i].centroid().E() >= seed_threshold);
41 if (iseed) {
42 nseeds++;
43
44 } else {
45
46
47 break;
48 }
49
50 for (unsigned int j = i + 1; j < clusters_.size(); j++) {
51 if (clusters_[j].empty() or
52 (!iseed and clusters_[j].centroid().E() < seed_threshold))
53 continue;
54
55 double wgt = wgt_(clusters_[i], clusters_[j]);
56 if (!any or
57 wgt < minwgt) {
58
59
60 any = true;
61 minwgt = wgt;
62 mi = i;
63 mj = j;
64 }
65 }
66 }
67
68
69
70
71 nseeds_ = nseeds;
72 transitionWeights_.insert(std::pair<int, double>(ncluster, minwgt));
73 if (any and 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
85 } while (minwgt < cutoff and ncluster > 1);
86 finalwgt_ = minwgt;
87 }