(a) generate: Generate multiple copies of all the combinations as . Append as the position numbers of . Then append and to store the energies. (b) energy: Compute the dissimilarities of the clusters and store the energy. (c) prune: Discard unfeasible partitions, that is, those where there exists empty clusters. (d) find: Find the best solution. Now we present algorithms to implement the above procedures. (a) Generation of all the possible solutions. Append values in order to store the energies. generate for   to     do for     to     do endfor for     to     do endfor for     to     do endfor for     downto     do endfor endfor . for     to     do endfor (b) Energy computation. The problem is to compute totals of energy for those     where   . Hence and   . The total energy is stored in   .  At the same time, the counting number of each bin is stored in the following     stickers. energy for    to      do endfor for     to     do for     to     do if     yes  then endif endfor endfor for     to     do for     to     do for     to     do endfor endfor endfor (c) The third step is to eliminate unfeasible partitions. This is done by checking the last     stickers. prune , for     to     do endfor (d) The last step is to find the best solution with least energy. If yes in the final step, then we get the optimal solution. find , for     to     do , if     no then else endif endfor .
Algorithm 2