Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3c900e57a3 | |||
| 6d562fb2e3 | |||
| b2517f51f2 | |||
| 20160689f4 |
@@ -567,14 +567,7 @@ void Graph::travellingSalesmanTabuSearchEngine(Graph &graph, unsigned tabuSteps,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
||||||
if(nextRouteLength == -1)
|
if(nextRouteLength == -1 || nextRouteLength > neighbourRouteLength)
|
||||||
{
|
|
||||||
nextRouteLength = neighbourRouteLength;
|
|
||||||
nextRoute = neighbourRoute;
|
|
||||||
nextTabu.at(1) = i;
|
|
||||||
nextTabu.at(2) = j;
|
|
||||||
}
|
|
||||||
else if(nextRouteLength > neighbourRouteLength)
|
|
||||||
{
|
{
|
||||||
nextRouteLength = neighbourRouteLength;
|
nextRouteLength = neighbourRouteLength;
|
||||||
nextRoute = neighbourRoute;
|
nextRoute = neighbourRoute;
|
||||||
@@ -676,17 +669,29 @@ void Graph::travellingSalesmanTabuSearchEngine(Graph &graph, unsigned tabuSteps,
|
|||||||
}
|
}
|
||||||
else
|
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)
|
// Synchronizacja globalnie najlepszej trasy (2)
|
||||||
globalOptimumMutex.lock();
|
globalOptimumMutex.lock();
|
||||||
optimalRouteLength = globalOptimumLength;
|
optimalRouteLength = globalOptimumLength;
|
||||||
optimalRoute = globalOptimum;
|
optimalRoute = globalOptimum;
|
||||||
globalOptimumMutex.unlock();
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -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;
|
||||||
|
|
||||||
@@ -439,6 +439,7 @@ int main(int argc, char *argv[])
|
|||||||
// Wyswietlenie trasy
|
// Wyswietlenie trasy
|
||||||
unsigned distFromStart = 0;
|
unsigned distFromStart = 0;
|
||||||
unsigned length = 0;
|
unsigned length = 0;
|
||||||
|
cout << endl;
|
||||||
cout << route.at(0) << '\t' << length << '\t' << distFromStart << endl;
|
cout << route.at(0) << '\t' << length << '\t' << distFromStart << endl;
|
||||||
for(int i = 1; i < route.size(); i++)
|
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 << route.at(i) << '\t' << length << '\t' << distFromStart << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << endl;
|
|
||||||
cout << "Dlugosc trasy: " << distFromStart << endl;
|
cout << "Dlugosc trasy: " << distFromStart << endl;
|
||||||
cout << endl;
|
cout << endl;
|
||||||
cout << "Czas wykonania algorytmu [s]: " << clock.read() << endl;
|
cout << "Czas wykonania algorytmu [s]: " << clock.read() << endl;
|
||||||
|
|||||||
Reference in New Issue
Block a user