From 37803af2decefd3014b185c7eca77bfd03d53492 Mon Sep 17 00:00:00 2001 From: UmbertoJr Date: Mon, 2 Dec 2019 08:54:34 +0100 Subject: [PATCH] solver --- run.py | 2 +- src/TSP_solver.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/run.py b/run.py index 7279436..ab724bd 100644 --- a/run.py +++ b/run.py @@ -19,8 +19,8 @@ def run(show_plots=False, verbose=False): instance.plot_data() for init in initializers: - solver = Solver_TSP(init) for improve in improvements: + solver = Solver_TSP(init) solver.bind(improve) solver(instance, return_value=False, verbose=verbose) diff --git a/src/TSP_solver.py b/src/TSP_solver.py index 1604113..894ebd7 100644 --- a/src/TSP_solver.py +++ b/src/TSP_solver.py @@ -32,14 +32,20 @@ class Solver_TSP: # "best_nn": self.best_nn, "multi_fragment": self.mf} self.initializer = initializer self.methods = [initializer] - self.name_method = "initialize with " + initializer + self.name_method = "initialized with " + initializer self.solved = False assert initializer in self.available_initializers, f"the {initializer} initializer is not available currently." def bind(self, local_or_meta): assert local_or_meta in self.available_improvements, f"the {local_or_meta} method is not available currently." self.methods.append(local_or_meta) - self.name_method += ", improve with " + local_or_meta + self.name_method += ", improved with " + local_or_meta + ' + + def pop(self): + self.methods.pop() + self.name_method = self.name_method[::-1][self.name_method[::-1].find("improved"[::-1]) + len("improved") + 1:][ + ::-1] def __call__(self, instance_, verbose=True, return_value=True): self.instance = instance_