6 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
2 changed files with 25 additions and 19 deletions
+22 -17
View File
@@ -517,7 +517,9 @@ void Graph::travellingSalesmanTabuSearchEngine(Graph &graph, unsigned tabuSteps,
while(cheeseSupplied == true)
{
std::vector<unsigned> nextRoute;
std::vector<unsigned> nextRoute = currentRoute;
// ...na wszelki wypadek, gdyby cale sasiedztwo bylo na liscie tabu
// (zeby algorytm sie nie wywalil)
int nextRouteLength = -1;
std::vector<unsigned> nextTabu(3, 0);
@@ -565,14 +567,7 @@ void Graph::travellingSalesmanTabuSearchEngine(Graph &graph, unsigned tabuSteps,
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;
@@ -674,23 +669,33 @@ void Graph::travellingSalesmanTabuSearchEngine(Graph &graph, unsigned tabuSteps,
}
else
{
// W innym przypadku wlasciwa dywersyfikacja przez wygenerowanie nowego
// rozwiazania startowego algorytmem hybrydowym losowo-zachlannym
currentRoute = Graph::travellingSalesmanHybrid(graph);
currentTabuSteps = tabuSteps;
intensification = false;
// 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
// (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;
}
}
// Reset licznika iteracji przed restartem
stopCounter = 0;
}
std::cout << std::endl;
}
+3 -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;
@@ -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++)
{