solver
This commit is contained in:
parent
677e5f7656
commit
de3e3f0793
2 changed files with 7 additions and 1 deletions
4
run.py
4
run.py
|
@ -32,6 +32,10 @@ def run(show_plots=False):
|
|||
if show_plots:
|
||||
solver.plot_solution()
|
||||
|
||||
if instance.optimal_tour:
|
||||
solver.solution = np.concatenate([instance.optimal_tour, [instance.optimal_tour[0]]])
|
||||
solver.plot_solution()
|
||||
|
||||
index = pd.MultiIndex.from_tuples(index, names=['problem', 'method'])
|
||||
|
||||
return pd.DataFrame(results, index=index, columns=["tour length", "optimal solution", "gap", "time to solve"])
|
||||
|
|
|
@ -17,6 +17,7 @@ class Solver_TSP:
|
|||
|
||||
def __call__(self, instance_, verbose=True, return_value=True):
|
||||
self.instance = instance_
|
||||
self.solved = False
|
||||
if verbose:
|
||||
print(f"### solving with {self.method} ####")
|
||||
self.solution = self.available_methods[self.method](instance_)
|
||||
|
@ -67,7 +68,8 @@ class Solver_TSP:
|
|||
def plot_solution(self):
|
||||
assert self.solved, "You can't plot the solution, you need to solve it first!"
|
||||
plt.figure(figsize=(8, 8))
|
||||
plt.title(f"{self.instance.name} with gap {self.gap}")
|
||||
self._gap()
|
||||
plt.title(f"{self.instance.name} solved with {self.method}, gap {self.gap}")
|
||||
ordered_points = self.instance.points[self.solution]
|
||||
plt.plot(ordered_points[:, 1], ordered_points[:, 2], 'b-')
|
||||
plt.show()
|
||||
|
|
Reference in a new issue