code reworking WIP
This commit is contained in:
parent
4ff369fe2c
commit
d3d41d5923
3 changed files with 6 additions and 5 deletions
4
run.py
4
run.py
|
@ -51,7 +51,9 @@ def run(show_plots=False, verbose=False):
|
||||||
solver.pop()
|
solver.pop()
|
||||||
|
|
||||||
if prob_instance.exist_opt and show_plots:
|
if prob_instance.exist_opt and show_plots:
|
||||||
solver.algorithm_name="optimal"
|
solver = SolverTSP("optimal", prob_instance)
|
||||||
|
# solver.name_method = "optimal" # TODO ask umberto details
|
||||||
|
|
||||||
solver.solution = np.concatenate([prob_instance.optimal_tour, [prob_instance.optimal_tour[0]]])
|
solver.solution = np.concatenate([prob_instance.optimal_tour, [prob_instance.optimal_tour[0]]])
|
||||||
solver.plot_solution()
|
solver.plot_solution()
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ class SolverTSP:
|
||||||
found_length: float
|
found_length: float
|
||||||
|
|
||||||
def __init__(self, algorithm_name, problem_instance):
|
def __init__(self, algorithm_name, problem_instance):
|
||||||
assert algorithm_name in available_solvers, f"the {algorithm_name} initializer is not available currently."
|
# assert algorithm_name in available_solvers, f"the {algorithm_name} initializer is not available currently."
|
||||||
self.duration = np.inf
|
self.duration = np.inf
|
||||||
self.algorithm_name = algorithm_name
|
self.algorithm_name = algorithm_name
|
||||||
self.algorithms = [algorithm_name]
|
self.algorithms = [algorithm_name]
|
||||||
|
|
|
@ -16,7 +16,7 @@ class ProblemInstance:
|
||||||
|
|
||||||
def __init__(self, name_tsp):
|
def __init__(self, name_tsp):
|
||||||
self.read_instance(name_tsp)
|
self.read_instance(name_tsp)
|
||||||
self.exist_opt = None # TODO determine default value
|
self.exist_opt = False # TODO determine default value
|
||||||
self.optimal_tour = None
|
self.optimal_tour = None
|
||||||
|
|
||||||
def read_instance(self, name_tsp):
|
def read_instance(self, name_tsp):
|
||||||
|
@ -40,8 +40,7 @@ class ProblemInstance:
|
||||||
self.points[i, 2] = line_i[2]
|
self.points[i, 2] = line_i[2]
|
||||||
|
|
||||||
self.create_dist_matrix()
|
self.create_dist_matrix()
|
||||||
self.exist_opt = False
|
if name_tsp in ["./problems/eil76.tsp", "./problems/kroA100.tsp"]:
|
||||||
if [name for name in ["eil76", "kroA100"] if name in name_tsp]:
|
|
||||||
self.exist_opt = True
|
self.exist_opt = True
|
||||||
file_object = open(name_tsp.replace(".tsp", ".opt.tour"))
|
file_object = open(name_tsp.replace(".tsp", ".opt.tour"))
|
||||||
data = file_object.read()
|
data = file_object.read()
|
||||||
|
|
Reference in a new issue