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 <random>
#include <thread>
#include <iostream>
Graph::Graph()
@@ -426,7 +425,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-2020
// Implementacja: Jan Potocki 2019
std::vector<unsigned> startVertexVector;
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
// Rdzen przeznaczony do uruchamiania jako jeden watek
// Projekt i implementacja: Jan Potocki 2017
// (refactoring 2019-2020)
// (refactoring 2019)
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...
@@ -565,6 +566,7 @@ void Graph::travellingSalesmanTabuSearchEngine(Graph &graph, unsigned tabuSteps,
// ...jezeli niespelnione - pomijamy ruch
continue;
if(nextRouteLength == -1 || nextRouteLength > neighbourRouteLength)
{
nextRouteLength = neighbourRouteLength;
@@ -599,7 +601,7 @@ void Graph::travellingSalesmanTabuSearchEngine(Graph &graph, unsigned tabuSteps,
stopCounter = 0;
}
// Synchronizacja globalnie najlepszej trasy
// Synchronizacja globalnie najlepszej trasy (1)
globalOptimumMutex.lock();
if(globalOptimumLength == -1 || globalOptimumLength > nextRouteLength)
{
@@ -660,16 +662,34 @@ 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
}
else
{
// Synchronizacja globalnie najlepszej trasy (2)
globalOptimumMutex.lock();
optimalRouteLength = globalOptimumLength;
optimalRoute = globalOptimum;
globalOptimumMutex.unlock();
// W innym przypadku wlasciwa dywersyfikacja przez wygenerowanie nowego
// 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;
intensification = false;
}
+2 -2
View File
@@ -31,7 +31,7 @@ unsigned tabuLength = 0;
// Domyslny stan dywersyfikacji
bool tabuDiversification = true;
// Domyslne kryterium dywersyfikacji, liczba iteracji bez poprawy
int tabuIterationsToRestart = 10000;
int tabuIterationsToRestart = 5000;
// Domyslny czas zatrzymania algorytmu tabu search [s]
unsigned tabuStopTime = 60;
@@ -206,7 +206,7 @@ unsigned autoTabuLength(Graph &graph)
{
unsigned computedTabuLength;
computedTabuLength = (2 * graph.getVertexNumber() / 10) * 10;
computedTabuLength = 10 + (graph.getVertexNumber() / 10) * 10;
if(computedTabuLength == 0)
computedTabuLength = 10;