public static void Solve() { StringBuilder iterBuilder = new StringBuilder(); var progress = new ProgressBar(); int i_to_fin = 1; double oldPerc = 0; double currentPerc = 0; double temp_T = MainLoopTemperature; while (temp_T > 0.001) { temp_T *= MainLoopAlpha; i_to_fin++; } Stopwatch algorithmTimer = Stopwatch.StartNew(); double temperature = _mainLoopTemperature; int iteration = 0; Locomotive.BetterFlowingContractsList = new List <List <DelieveryContract> >(); Locomotive.BetterFlowingStatusList = new List <Status>(); for (int i = 0; i <= MaxCityVisited; i++) { Locomotive.BetterFlowingContractsList.Add(new List <DelieveryContract>()); Locomotive.BetterFlowingStatusList.Add(new Status(0, 0)); } Locomotive.TheBestCityRoute = GenerateTemplateCityRoute(); Locomotive.NewCityRoute = new List <int>(); List <List <int> > bestContractSet = FindBestContractsSet(Locomotive.TheBestCityRoute); iteration++; List <List <int> > newContractSet; Locomotive.TheBestCash = CalculateSolutionValue(bestContractSet); Locomotive.NewCash = 0; //loging the first iteration DataIO.DataOutput.SaveData(iteration, Locomotive.NewCityRoute, Locomotive.NewFlowingContractsList, Locomotive.TheBestCash, Locomotive.NewCash, temperature); while (temperature > 0.001) { Locomotive.NewCityRoute = GenerateNextCityRoute(Locomotive.TheBestCityRoute); newContractSet = FindBestContractsSet(Locomotive.NewCityRoute); Locomotive.NewCash = CalculateSolutionValue(newContractSet); if (Locomotive.NewCash > Locomotive.TheBestCash) { Locomotive.TheBestCash = Locomotive.NewCash; bestContractSet = newContractSet; Locomotive.TheBestCityRoute = new List <int>(Locomotive.NewCityRoute); Locomotive.TheBestCompleatedContractsIDs = new List <int>(Locomotive.NewCompleatedContractsIDs); Locomotive.TheBestFlowingContractsList = new List <List <DelieveryContract> >(Locomotive.NewFlowingContractsList); Locomotive.TheBestFlowingStatusList = new List <Status>(Locomotive.NewFlowingStatusList); DataOutput.SaveSigmaBest(Locomotive.TheBestCash, 1); } else if (_random.NextDouble() < Math.Pow(Math.E, (Locomotive.NewCash - Locomotive.TheBestCash) / temperature)) { Locomotive.TheBestCash = Locomotive.NewCash; bestContractSet = newContractSet; Locomotive.TheBestCityRoute = new List <int>(Locomotive.NewCityRoute); Locomotive.TheBestCompleatedContractsIDs = new List <int>(Locomotive.NewCompleatedContractsIDs); Locomotive.TheBestFlowingContractsList = new List <List <DelieveryContract> >(Locomotive.NewFlowingContractsList); Locomotive.TheBestFlowingStatusList = new List <Status>(Locomotive.NewFlowingStatusList); DataOutput.SaveSigmaBest(Locomotive.TheBestCash, -1); } else { DataOutput.SaveSigmaBest(Locomotive.TheBestCash, 0); } temperature *= _mainLoopAlpha; iteration++; DataIO.DataOutput.SaveData(iteration, Locomotive.NewCityRoute, Locomotive.NewFlowingContractsList, Locomotive.TheBestCash, Locomotive.NewCash, temperature); // Algorytm zapisuje sobie prawdziwie najlepsze solucje :V if (Locomotive.TheBestCash > _bestSolutionValue) { _theBestIteration = iteration; _bestSolutionValue = Locomotive.TheBestCash; _bestContractSet = new List <List <int> >(bestContractSet); _bestCityRoute = new List <int>(Locomotive.TheBestCityRoute); _bestCompleatedContractsIDs = new List <int>(Locomotive.TheBestCompleatedContractsIDs); _bestFlowingContractsList = new List <List <DelieveryContract> >(Locomotive.TheBestFlowingContractsList); _bestFlowingStatusList = new List <Status>(Locomotive.TheBestFlowingStatusList); } currentPerc = ((double)iteration / (double)i_to_fin); if (oldPerc < currentPerc) { oldPerc = currentPerc; progress.Report(oldPerc); if (oldPerc >= 1) { progress.Dispose(); Console.WriteLine("[##########] 100%"); } //Console.WriteLine(oldPerc + "%"); } } DataIO.DataOutput.SaveTheBestSolution(_theBestIteration, _bestSolutionValue, _bestCompleatedContractsIDs, _bestCityRoute, _bestFlowingContractsList, _bestFlowingStatusList); DataIO.DataOutput.SaveCounters(algorithmTimer.ElapsedMilliseconds); algorithmTimer.Stop(); //Console.WriteLine("\nFinal solution value: " + _bestSolutionValue); Console.WriteLine("Solution took: " + algorithmTimer.ElapsedMilliseconds + " miliseconds"); }