added method for calculating clustering cost