public double targetFunctionValue(int k, int n, Point[] centres, Point[] points) {
        int i = 0;
        double sum = 0.0;
        for (i = 0; i < n; i++) {
            double nearestCost = -1.0;
            int j = 0;
            for (j = 0; j < k; j++) {
                double distance = 0.0;
                int l = 0;
                for (l = 0; l < points[i].dimension; l++) {
                    //Centroid coordinate of the point
                    double centroidCoordinatePoint;
                    if (points[i].weight != 0.0) {
                        centroidCoordinatePoint = points[i].coordinates[l] / points[i].weight;
                    } else {
                        centroidCoordinatePoint = points[i].coordinates[l];
                    }
                    //Centroid coordinate of the centre
                    double centroidCoordinateCentre;
                    if (centres[j].weight != 0.0) {
                        centroidCoordinateCentre = centres[j].coordinates[l] / centres[j].weight;
                    } else {
                        centroidCoordinateCentre = centres[j].coordinates[l];
                    }
                    distance += (centroidCoordinatePoint - centroidCoordinateCentre) *
                            (centroidCoordinatePoint - centroidCoordinateCentre);

                }
                if (nearestCost < 0 || distance < nearestCost) {
                    nearestCost = distance;
                }
            }
            sum += nearestCost * points[i].weight;
        }
        return sum;
    }