Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1.  
  2. //optMin = getInitialReduction();
  3. optMin = getInitialGreedy(bestRoute);
  4. cout << "optMin = " << optMin << endl;
  5. currentRoute = bestRoute;
  6. displayRoute(currentRoute);
  7. Czas onboardClock;
  8. int currentCost = optMin;
  9. amountRandomNodes = 5;
  10. onboardClock.start();
  11.  
  12. double temperature = CalculateTemperature();
  13. currentOptMin = optMin;
  14.  
  15. do
  16. {
  17. //getInitialReductionAndRandom(currentRoute);
  18.  
  19. for (auto i = 0; i < matrixSize*matrixSize; i++)
  20. {
  21. vector<unsigned> shuffled = currentRoute;
  22.  
  23. currentCost = currentCost + swapTwoRandomNodes(shuffled);
  24.  
  25. if (currentCost < currentOptMin)
  26. {
  27. currentRoute = shuffled;
  28. currentOptMin = currentCost;
  29. }
  30.  
  31. ///*
  32. else if (static_cast<float>(rand()) / RAND_MAX < CalculateProbability(currentOptMin, currentCost, temperature)) // Metropolis condition
  33. {
  34. currentRoute = shuffled;
  35. currentOptMin = currentCost;
  36. }
  37. //*/
  38.  
  39. }
  40. static_cast<double>(temperature = temperature * 0.95);
  41. //cout << "Temperatura " << temperature << endl;
  42. onboardClock.stop();
  43. //-----sprawdzenie czy uplynal czas------
  44. } while (onboardClock.read() <= 2);
  45.  
  46. bestRoute = currentRoute;
  47. optMin = currentOptMin;
  48.  
  49. cout << endl;
  50. cout << "Min: " << optMin << endl;
  51. cout << "Czas wykonania:" << endl;
  52. cout << "10s" << endl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement