public void Iterate() { if (IsCompleted) { return; } Generation++; var indexToSwap1 = (int)Math.Round((CurrentSolution.Route.Count() - 1) * picker.NextDouble()); var indexToSwap2 = (int)Math.Round((CurrentSolution.Route.Count() - 1) * picker.NextDouble()); var newSolution = CurrentSolution.Swap(indexToSwap1, indexToSwap2); if (ShouldUse(newSolution)) { Console.WriteLine("{2} - Replacing {0} with {1}", CurrentSolution.TotalDistance, newSolution.TotalDistance, Generation); CurrentSolution = newSolution; } if (newSolution.IsBestThan(BestSolution)) { Console.WriteLine("Reducing distance from {0} to {1}", BestSolution.TotalDistance, newSolution.TotalDistance); BestSolution = newSolution; } CurrentTemperature *= (1 - CoolingRate); }