Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3691314819 | |||
| 2d45eaf383 | |||
| 0b6e9418f9 | |||
| 01f2e91aac | |||
| 4292c63a15 | |||
| babb720caa |
@@ -5,6 +5,7 @@
|
||||
#include <queue>
|
||||
#include <random>
|
||||
#include <thread>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
Graph::Graph()
|
||||
@@ -425,7 +426,7 @@ std::vector<unsigned> Graph::travellingSalesmanTabuSearch(Graph &graph, unsigned
|
||||
{
|
||||
// ALGORYTM wielawotkowy oparty na metaheurystyce tabu search
|
||||
// Pomocniczy kod uruchamiajacy watki wlasciwego algorytmu w najbardziej optymalny sposob
|
||||
// Implementacja: Jan Potocki 2019
|
||||
// Implementacja: Jan Potocki 2019-2020
|
||||
std::vector<unsigned> startVertexVector;
|
||||
std::vector<std::thread> threadsVector;
|
||||
|
||||
@@ -491,15 +492,13 @@ void Graph::travellingSalesmanTabuSearchEngine(Graph &graph, unsigned tabuSteps,
|
||||
// ALGORYTM oparty na metaheurystyce tabu search z dywersyfikacja i sasiedztwem typu swap
|
||||
// Rdzen przeznaczony do uruchamiania jako jeden watek
|
||||
// Projekt i implementacja: Jan Potocki 2017
|
||||
// (refactoring 2019)
|
||||
// (refactoring 2019-2020)
|
||||
Stopwatch onboardClock;
|
||||
|
||||
std::vector<unsigned> optimalRoute; // Tu bedziemy zapisywac optymalne (w danej chwili) rozwiazanie
|
||||
int optimalRouteLength = -1; // -1 - bedziemy odtad uznawac, ze to jest nieskonczonosc ;-)
|
||||
std::vector<unsigned> currentRoute; // Rozpatrywane rozwiazanie
|
||||
|
||||
// Wyznaczenie poczatkowego rozwiazania algorytmem zachlannym
|
||||
//currentRoute = Graph::travellingSalesmanGreedy(graph);
|
||||
currentRoute = startRoute;
|
||||
|
||||
// Inicjalizacja glownej petli...
|
||||
@@ -566,15 +565,7 @@ void Graph::travellingSalesmanTabuSearchEngine(Graph &graph, unsigned tabuSteps,
|
||||
// ...jezeli niespelnione - pomijamy ruch
|
||||
continue;
|
||||
|
||||
|
||||
if(nextRouteLength == -1)
|
||||
{
|
||||
nextRouteLength = neighbourRouteLength;
|
||||
nextRoute = neighbourRoute;
|
||||
nextTabu.at(1) = i;
|
||||
nextTabu.at(2) = j;
|
||||
}
|
||||
else if(nextRouteLength > neighbourRouteLength)
|
||||
if(nextRouteLength == -1 || nextRouteLength > neighbourRouteLength)
|
||||
{
|
||||
nextRouteLength = neighbourRouteLength;
|
||||
nextRoute = neighbourRoute;
|
||||
@@ -608,7 +599,7 @@ void Graph::travellingSalesmanTabuSearchEngine(Graph &graph, unsigned tabuSteps,
|
||||
stopCounter = 0;
|
||||
}
|
||||
|
||||
// Synchronizacja globalnie najlepszej trasy (1)
|
||||
// Synchronizacja globalnie najlepszej trasy
|
||||
globalOptimumMutex.lock();
|
||||
if(globalOptimumLength == -1 || globalOptimumLength > nextRouteLength)
|
||||
{
|
||||
@@ -669,7 +660,7 @@ void Graph::travellingSalesmanTabuSearchEngine(Graph &graph, unsigned tabuSteps,
|
||||
// Intensyfikacja przeszukiwania przez skrócenie kadencji
|
||||
// (jezeli w ostatnim przebiegu znaleziono nowe minimum)
|
||||
currentRoute = optimalRoute;
|
||||
currentTabuSteps = tabuSteps / 4;
|
||||
currentTabuSteps = tabuSteps; /// 4;
|
||||
intensification = false;
|
||||
// PEA 2 Plus
|
||||
// Jan Potocki 2019
|
||||
@@ -681,12 +672,6 @@ void Graph::travellingSalesmanTabuSearchEngine(Graph &graph, unsigned tabuSteps,
|
||||
currentRoute = Graph::travellingSalesmanHybrid(graph);
|
||||
currentTabuSteps = tabuSteps;
|
||||
intensification = false;
|
||||
|
||||
// Synchronizacja globalnie najlepszej trasy (2)
|
||||
globalOptimumMutex.lock();
|
||||
optimalRouteLength = globalOptimumLength;
|
||||
optimalRoute = globalOptimum;
|
||||
globalOptimumMutex.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -439,6 +439,7 @@ int main(int argc, char *argv[])
|
||||
// Wyswietlenie trasy
|
||||
unsigned distFromStart = 0;
|
||||
unsigned length = 0;
|
||||
cout << endl;
|
||||
cout << route.at(0) << '\t' << length << '\t' << distFromStart << endl;
|
||||
for(int i = 1; i < route.size(); i++)
|
||||
{
|
||||
@@ -448,7 +449,6 @@ int main(int argc, char *argv[])
|
||||
cout << route.at(i) << '\t' << length << '\t' << distFromStart << endl;
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
cout << "Dlugosc trasy: " << distFromStart << endl;
|
||||
cout << endl;
|
||||
cout << "Czas wykonania algorytmu [s]: " << clock.read() << endl;
|
||||
|
||||
Reference in New Issue
Block a user