need a final check and should be done

This commit is contained in:
Dario Mantegazza 2020-09-28 11:56:36 +02:00
parent d3d41d5923
commit c75ecc3d5b
2 changed files with 14 additions and 13 deletions

22
run.py
View file

@ -1,3 +1,4 @@
import glob
import pandas as pd import pandas as pd
from src.io_tsp import ProblemInstance from src.io_tsp import ProblemInstance
from src.TSP_solver import SolverTSP, available_improvers, available_solvers from src.TSP_solver import SolverTSP, available_improvers, available_solvers
@ -22,8 +23,8 @@ def use_solver_to_compute_solution(solver, improve, index, results, name, verbos
def run(show_plots=False, verbose=False): def run(show_plots=False, verbose=False):
# problems = glob.glob('./problems/*.tsp') problems = glob.glob('./problems/*.tsp')
problems = ["./problems/eil76.tsp"] # problems = ["./problems/eil76.tsp"]
solvers_names = available_solvers.keys() solvers_names = available_solvers.keys()
improvers_names = available_improvers.keys() improvers_names = available_improvers.keys()
results = [] results = []
@ -40,20 +41,19 @@ def run(show_plots=False, verbose=False):
for improve in improvers_names: for improve in improvers_names:
solver = SolverTSP(solver_name, prob_instance) solver = SolverTSP(solver_name, prob_instance)
use_solver_to_compute_solution(solver, improve, index, results, problem_path, verbose, show_plots) use_solver_to_compute_solution(solver, improve, index, results, problem_path, verbose, show_plots)
for improve2 in [j for j in improvers_names if j not in [improve]]: for improve2 in [j for j in improvers_names if j not in [improve]]:
use_solver_to_compute_solution(solver, improve2, index, results, problem_path, verbose, show_plots) use_solver_to_compute_solution(solver, improve2, index, results, problem_path, verbose, show_plots)
for improve3 in [j for j in improvers_names if j not in [improve, improve2]]: for improve3 in [j for j in improvers_names if j not in [improve, improve2]]:
use_solver_to_compute_solution(solver, improve3, index, results, problem_path, verbose, use_solver_to_compute_solution(solver, improve3, index, results, problem_path, verbose,
show_plots) show_plots)
solver.pop() solver.pop()
solver.pop() solver.pop()
if prob_instance.exist_opt and show_plots: if prob_instance.exist_opt and show_plots:
solver = SolverTSP("optimal", prob_instance) solver = SolverTSP("optimal", prob_instance)
# solver.name_method = "optimal" # TODO ask umberto details solver.solved = True
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()

View file

@ -15,9 +15,9 @@ class ProblemInstance:
points: ndarray points: ndarray
def __init__(self, name_tsp): def __init__(self, name_tsp):
self.read_instance(name_tsp) self.exist_opt = False
self.exist_opt = False # TODO determine default value
self.optimal_tour = None self.optimal_tour = None
self.read_instance(name_tsp)
def read_instance(self, name_tsp): def read_instance(self, name_tsp):
# read raw data # read raw data
@ -57,6 +57,7 @@ class ProblemInstance:
print('name: ' + self.name) print('name: ' + self.name)
print('nPoints: ' + str(self.nPoints)) print('nPoints: ' + str(self.nPoints))
print('best_sol: ' + str(self.best_sol)) print('best_sol: ' + str(self.best_sol))
print('exist optimal: ' + str(self.exist_opt))
def plot_data(self): def plot_data(self):
plt.figure(figsize=(8, 8)) plt.figure(figsize=(8, 8))