Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //optMin = getInitialReduction();
- optMin = getInitialGreedy(bestRoute);
- cout << "optMin = " << optMin << endl;
- currentRoute = bestRoute;
- displayRoute(currentRoute);
- Czas onboardClock;
- int currentCost = optMin;
- amountRandomNodes = 5;
- onboardClock.start();
- double temperature = CalculateTemperature();
- currentOptMin = optMin;
- do
- {
- //getInitialReductionAndRandom(currentRoute);
- for (auto i = 0; i < matrixSize*matrixSize; i++)
- {
- vector<unsigned> shuffled = currentRoute;
- currentCost = currentCost + swapTwoRandomNodes(shuffled);
- if (currentCost < currentOptMin)
- {
- currentRoute = shuffled;
- currentOptMin = currentCost;
- }
- ///*
- else if (static_cast<float>(rand()) / RAND_MAX < CalculateProbability(currentOptMin, currentCost, temperature)) // Metropolis condition
- {
- currentRoute = shuffled;
- currentOptMin = currentCost;
- }
- //*/
- }
- static_cast<double>(temperature = temperature * 0.95);
- //cout << "Temperatura " << temperature << endl;
- onboardClock.stop();
- //-----sprawdzenie czy uplynal czas------
- } while (onboardClock.read() <= 2);
- bestRoute = currentRoute;
- optMin = currentOptMin;
- cout << endl;
- cout << "Min: " << optMin << endl;
- cout << "Czas wykonania:" << endl;
- cout << "10s" << endl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement