Input: Ids, locations, weights |
Output: collection point clusters |
(1) | % initalize each point as a clusters |
(2) | clus←Ids |
(3) | cluWts←weights |
(4) | CPs←locations |
(5) | % obtain the distance matrix C |
(6) | C← distance (CPs[i], CPs[J]) |
(7) | % obtain pairs P that will be merged (getP) |
(8) | X, Y←obtain the two closest clusters according to C |
(9) | % obtain the cluster Z after X and Y are merged |
(10) | Z←merge (clus [X], clus [Y]) |
(11) | % obtain the operating cost of the cluster Z |
(12) | costZ←get cost (Z) |
(13) | % obtain the operating cost of the clus [X] and the clus [Y] |
(14) | costX←get cost (clus [X]) |
(15) | costY←get cost (clus [Y]) |
(16) | if (clusWts [X] + clusWts [Y]) ≤ M and costZ ≤ (costX + costY) then |
(17) | P append ((X, Y)) |
(18) | end if |
(19) | % If P is not empty, loop to merge clusters |
(20) | While P←getP () is not null do |
(21) | % Merge the clusters (X, Y) in P, and update related variables |
(22) | clus [X]←Z |
(23) | remove clus [Y] |
(24) | CPs [X]←get Center (clus [X]) |
(25) | removeCPs [Y] |
(26) | clusWts [X]←(clusWts [X] + clusWts[Y]) |
(27) | remove clusWts [Y] |
(28) | update C |
(29) | P clear () |
(30) | end While |
(31) | return clus |