Algorithm for cluster analysis in distribution systems