Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3c900e57a3 | |||
| 6d562fb2e3 | |||
| b2517f51f2 | |||
| 20160689f4 | |||
| 6cab940785 | |||
| c10d296d82 | |||
| 5d78916930 | |||
| b577fd6c13 | |||
| 74e1d0be8e | |||
| 420ee4f275 |
@@ -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
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user