This commit is contained in:
UmbertoJr 2019-12-02 08:54:34 +01:00
parent 573bc9a38f
commit 37803af2de
2 changed files with 9 additions and 3 deletions

2
run.py
View file

@ -19,8 +19,8 @@ def run(show_plots=False, verbose=False):
instance.plot_data() instance.plot_data()
for init in initializers: for init in initializers:
solver = Solver_TSP(init)
for improve in improvements: for improve in improvements:
solver = Solver_TSP(init)
solver.bind(improve) solver.bind(improve)
solver(instance, return_value=False, verbose=verbose) solver(instance, return_value=False, verbose=verbose)

View file

@ -32,14 +32,20 @@ class Solver_TSP:
# "best_nn": self.best_nn, "multi_fragment": self.mf} # "best_nn": self.best_nn, "multi_fragment": self.mf}
self.initializer = initializer self.initializer = initializer
self.methods = [initializer] self.methods = [initializer]
self.name_method = "initialize with " + initializer self.name_method = "initialized with " + initializer
self.solved = False self.solved = False
assert initializer in self.available_initializers, f"the {initializer} initializer is not available currently." assert initializer in self.available_initializers, f"the {initializer} initializer is not available currently."
def bind(self, local_or_meta): def bind(self, local_or_meta):
assert local_or_meta in self.available_improvements, f"the {local_or_meta} method is not available currently." 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.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): def __call__(self, instance_, verbose=True, return_value=True):
self.instance = instance_ self.instance = instance_