10 Commits

Author SHA1 Message Date
Jan Potocki 3c900e57a3 New default parameters for TS (algorithm tuning) 2020-01-20 20:13:20 +01:00
Jan Potocki 6d562fb2e3 Fixed newline (part II) 2020-01-20 20:10:51 +01:00
Jan Potocki b2517f51f2 Simplified if-else statement (TS) 2020-01-20 19:40:22 +01:00
Jan Potocki 20160689f4 Experimental: constraint for diversification (max 150% of current optimum length) 2020-01-20 19:33:40 +01:00
Jan Potocki 6cab940785 Fixed newline in output (TS) 2020-01-20 19:24:40 +01:00
Jan Potocki c10d296d82 Fixed TS crash when entire neighborhood is on tabu list 2020-01-20 19:23:47 +01:00
Jan Potocki 5d78916930 Added displaying timestamp for new optimal router 2020-01-15 19:43:00 +01:00
Jan Potocki b577fd6c13 New approach for global optimum sharing 2020-01-15 19:25:38 +01:00
Jan Potocki 74e1d0be8e Global shared optimum - almost ready 2020-01-15 19:04:22 +01:00
Jan Potocki 420ee4f275 Experimental: initial shared global optimum in TS 2020-01-15 18:22:38 +01:00
2 changed files with 28 additions and 8 deletions
+26 -6
View File
@@ -5,7 +5,6 @@
#include <queue> #include <queue>
#include <random> #include <random>
#include <thread> #include <thread>
#include <iostream> #include <iostream>
Graph::Graph() Graph::Graph()
@@ -426,7 +425,7 @@ std::vector<unsigned> Graph::travellingSalesmanTabuSearch(Graph &graph, unsigned
{ {
// ALGORYTM wielawotkowy oparty na metaheurystyce tabu search // ALGORYTM wielawotkowy oparty na metaheurystyce tabu search
// Pomocniczy kod uruchamiajacy watki wlasciwego algorytmu w najbardziej optymalny sposob // Pomocniczy kod uruchamiajacy watki wlasciwego algorytmu w najbardziej optymalny sposob
// Implementacja: Jan Potocki 2019-2020 // Implementacja: Jan Potocki 2019
std::vector<unsigned> startVertexVector; std::vector<unsigned> startVertexVector;
std::vector<std::thread> threadsVector; std::vector<std::thread> threadsVector;
@@ -492,13 +491,15 @@ void Graph::travellingSalesmanTabuSearchEngine(Graph &graph, unsigned tabuSteps,
// ALGORYTM oparty na metaheurystyce tabu search z dywersyfikacja i sasiedztwem typu swap // ALGORYTM oparty na metaheurystyce tabu search z dywersyfikacja i sasiedztwem typu swap
// Rdzen przeznaczony do uruchamiania jako jeden watek // Rdzen przeznaczony do uruchamiania jako jeden watek
// Projekt i implementacja: Jan Potocki 2017 // Projekt i implementacja: Jan Potocki 2017
// (refactoring 2019-2020) // (refactoring 2019)
Stopwatch onboardClock; Stopwatch onboardClock;
std::vector<unsigned> optimalRoute; // Tu bedziemy zapisywac optymalne (w danej chwili) rozwiazanie std::vector<unsigned> optimalRoute; // Tu bedziemy zapisywac optymalne (w danej chwili) rozwiazanie
int optimalRouteLength = -1; // -1 - bedziemy odtad uznawac, ze to jest nieskonczonosc ;-) int optimalRouteLength = -1; // -1 - bedziemy odtad uznawac, ze to jest nieskonczonosc ;-)
std::vector<unsigned> currentRoute; // Rozpatrywane rozwiazanie std::vector<unsigned> currentRoute; // Rozpatrywane rozwiazanie
// Wyznaczenie poczatkowego rozwiazania algorytmem zachlannym
//currentRoute = Graph::travellingSalesmanGreedy(graph);
currentRoute = startRoute; currentRoute = startRoute;
// Inicjalizacja glownej petli... // Inicjalizacja glownej petli...
@@ -565,6 +566,7 @@ void Graph::travellingSalesmanTabuSearchEngine(Graph &graph, unsigned tabuSteps,
// ...jezeli niespelnione - pomijamy ruch // ...jezeli niespelnione - pomijamy ruch
continue; continue;
if(nextRouteLength == -1 || nextRouteLength > neighbourRouteLength) if(nextRouteLength == -1 || nextRouteLength > neighbourRouteLength)
{ {
nextRouteLength = neighbourRouteLength; nextRouteLength = neighbourRouteLength;
@@ -599,7 +601,7 @@ void Graph::travellingSalesmanTabuSearchEngine(Graph &graph, unsigned tabuSteps,
stopCounter = 0; stopCounter = 0;
} }
// Synchronizacja globalnie najlepszej trasy // Synchronizacja globalnie najlepszej trasy (1)
globalOptimumMutex.lock(); globalOptimumMutex.lock();
if(globalOptimumLength == -1 || globalOptimumLength > nextRouteLength) if(globalOptimumLength == -1 || globalOptimumLength > nextRouteLength)
{ {
@@ -660,16 +662,34 @@ void Graph::travellingSalesmanTabuSearchEngine(Graph &graph, unsigned tabuSteps,
// Intensyfikacja przeszukiwania przez skrócenie kadencji // Intensyfikacja przeszukiwania przez skrócenie kadencji
// (jezeli w ostatnim przebiegu znaleziono nowe minimum) // (jezeli w ostatnim przebiegu znaleziono nowe minimum)
currentRoute = optimalRoute; currentRoute = optimalRoute;
currentTabuSteps = tabuSteps; /// 4; currentTabuSteps = tabuSteps / 4;
intensification = false; intensification = false;
// PEA 2 Plus // PEA 2 Plus
// Jan Potocki 2019 // Jan Potocki 2019
} }
else else
{ {
// Synchronizacja globalnie najlepszej trasy (2)
globalOptimumMutex.lock();
optimalRouteLength = globalOptimumLength;
optimalRoute = globalOptimum;
globalOptimumMutex.unlock();
// W innym przypadku wlasciwa dywersyfikacja przez wygenerowanie nowego // W innym przypadku wlasciwa dywersyfikacja przez wygenerowanie nowego
// rozwiazania startowego algorytmem hybrydowym losowo-zachlannym // rozwiazania startowego algorytmem hybrydowym losowo-zachlannym
currentRoute = Graph::travellingSalesmanHybrid(graph); // (ale nie znacznie gorszego niz juz znalezione)
int criticalLength = (15 * optimalRouteLength) / 10;
int currentRouteLength;
do
{
currentRoute = Graph::travellingSalesmanHybrid(graph);
currentRouteLength = 0;
for(int i = 1; i < currentRoute.size(); i++)
currentRouteLength += graph.getWeight(currentRoute.at(i - 1), currentRoute.at(i));
} while(currentRouteLength > criticalLength);
currentTabuSteps = tabuSteps; currentTabuSteps = tabuSteps;
intensification = false; intensification = false;
} }
+2 -2
View File
@@ -31,7 +31,7 @@ unsigned tabuLength = 0;
// Domyslny stan dywersyfikacji // Domyslny stan dywersyfikacji
bool tabuDiversification = true; bool tabuDiversification = true;
// Domyslne kryterium dywersyfikacji, liczba iteracji bez poprawy // Domyslne kryterium dywersyfikacji, liczba iteracji bez poprawy
int tabuIterationsToRestart = 10000; int tabuIterationsToRestart = 5000;
// Domyslny czas zatrzymania algorytmu tabu search [s] // Domyslny czas zatrzymania algorytmu tabu search [s]
unsigned tabuStopTime = 60; unsigned tabuStopTime = 60;
@@ -206,7 +206,7 @@ unsigned autoTabuLength(Graph &graph)
{ {
unsigned computedTabuLength; unsigned computedTabuLength;
computedTabuLength = (2 * graph.getVertexNumber() / 10) * 10; computedTabuLength = 10 + (graph.getVertexNumber() / 10) * 10;
if(computedTabuLength == 0) if(computedTabuLength == 0)
computedTabuLength = 10; computedTabuLength = 10;