From 32e0a376b30151114d131f47de0a0a013ee6e76c Mon Sep 17 00:00:00 2001 From: Sam Hadow Date: Wed, 16 Oct 2024 22:12:46 +0200 Subject: [PATCH] print results --- main.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index f69e639..3439406 100644 --- a/main.py +++ b/main.py @@ -42,7 +42,7 @@ def tabu_search(initial_solution, n_max): cost_best = cost tabu = [solution,] n = 0 - while n <= n_max: + while n < n_max: neighbors_list = [] for s in neighbors(solution): if check_validity(s) and s not in tabu: @@ -61,11 +61,14 @@ def tabu_search(initial_solution, n_max): n += 1 tabu.append(solution) + print("tabu list:") + for e in tabu: + print(e, calculate_cost(e)) + print("solution found:") + print(best, cost_best) return (best, cost_best) -print("when not degrading the current solution:") -print(tabu_search(solution, 0)) -print("tabu search accepting 1 degradation:") -print(tabu_search(solution, 1)) +print("tabu search accepting 1 degradation: (find a local optimum)") +tabu_search(solution, 1) print("tabu search accepting 2 degradations:") -print(tabu_search(solution, 2)) +tabu_search(solution, 2)