From 0fbff999b1f327a0d60011b25bd9401119767c26 Mon Sep 17 00:00:00 2001 From: KevinMonk Date: Sat, 23 Feb 2019 15:27:38 +0000 Subject: [PATCH] Update tabu_search.rb The tabu list pops the edge that you just pushed. If you shift the array then it will pop the oldest tabu item instead of popping the most recent. I could have this completely wrong! :) --- src/algorithms/stochastic/tabu_search.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/algorithms/stochastic/tabu_search.rb b/src/algorithms/stochastic/tabu_search.rb index 349b3196..fc4ff5f7 100644 --- a/src/algorithms/stochastic/tabu_search.rb +++ b/src/algorithms/stochastic/tabu_search.rb @@ -74,7 +74,7 @@ def search(cities, tabu_list_size, candidate_list_size, max_iter) current = best_candidate best = best_candidate if best_candidate[:cost] < best[:cost] best_candidate_edges.each {|edge| tabu_list.push(edge)} - tabu_list.pop while tabu_list.size > tabu_list_size + tabu_list.shift while tabu_list.size > tabu_list_size end puts " > iteration #{(iter+1)}, best=#{best[:cost]}" end @@ -99,4 +99,4 @@ def search(cities, tabu_list_size, candidate_list_size, max_iter) # execute the algorithm best = search(berlin52, tabu_list_size, max_candidates, max_iter) puts "Done. Best Solution: c=#{best[:cost]}, v=#{best[:vector].inspect}" -end \ No newline at end of file +end