public override string Solve() { Vertex[] extendedVertices = null; List <Facility> facilities = null; double solutionCost = 0.0; int iterationIndex = 1; /* Algorithm parameter - number of clusters */ int initialNumberOfClusters = 4; int maxNumberOfClusters = 15; double bestSolution = Double.MaxValue; int bestNumberOfClusters = 0; StreamWriter writer = new StreamWriter("Vysledky.txt", true); writer.WriteLine("*************************************************"); writer.WriteLine("************* NOVE VYSLEDKY K-MEANS *************"); writer.WriteLine("*************************************************"); /* *** ITERATING number of clusters *** */ for (int actualNumberOfClusters = initialNumberOfClusters; actualNumberOfClusters <= maxNumberOfClusters; actualNumberOfClusters++) { algorithm = new KMeans(); Console.WriteLine("Iteration number " + iterationIndex); extendedVertices = fillExtendedVerticesArray(actualNumberOfClusters); /* Setting properties */ properties = new Dictionary <string, object>(); properties.Add("boundingBox", boundingBox); properties.Add("numberOfClusters", actualNumberOfClusters); properties.Add("randomSeed", 1234); algorithm.SetProperties(properties); /* Computation */ algorithm.ComputeClustering(extendedVertices); facilities = algorithm.GetFacilities(); solutionCost = Analysis.ComputeClusterSolution(boundingBox, facilities, extendedVertices); writer.WriteLine("Solution cost: " + solutionCost); writer.WriteLine("Number of clusters: " + actualNumberOfClusters); if (solutionCost < bestSolution) { bestSolution = solutionCost; bestNumberOfClusters = actualNumberOfClusters; } iterationIndex++; } Console.WriteLine("********************************************"); Console.WriteLine("Best solution cost: " + bestSolution); Console.WriteLine("With number of clusters: " + bestNumberOfClusters); writer.WriteLine("********************************************"); writer.WriteLine("Best solution cost: " + bestSolution); writer.WriteLine("With number of clusters: " + bestNumberOfClusters); IterateOverNWeights(bestNumberOfClusters, bestSolution); writer.WriteLine("************** KONEC VYSLEDKU **************"); writer.Flush(); writer.Close(); return(""); }