From f2eaab99dc330ef1c228bb4e877ee97121a0b77d Mon Sep 17 00:00:00 2001 From: Dario Mantegazza Date: Thu, 1 Oct 2020 18:03:04 +0200 Subject: [PATCH] Notebooks lectures --- .gitignore | 4 +++ Lectures/Student_lecture 1.ipynb | 46 ++++++++++++++++++++++++ Lectures/Student_lecture 2.ipynb | 37 ++++++++++++++++++++ Lectures/Student_lecture 3.ipynb | 37 ++++++++++++++++++++ Lectures/Student_lecture 4.ipynb | 37 ++++++++++++++++++++ Student_lecture 1.ipynb | 60 ++++++++++++++++++++++++++++++++ run.py | 4 +-- src/TSP_solver.py | 7 ---- 8 files changed, 223 insertions(+), 9 deletions(-) create mode 100644 Lectures/Student_lecture 1.ipynb create mode 100644 Lectures/Student_lecture 2.ipynb create mode 100644 Lectures/Student_lecture 3.ipynb create mode 100644 Lectures/Student_lecture 4.ipynb create mode 100644 Student_lecture 1.ipynb diff --git a/.gitignore b/.gitignore index 82ca545..92425bf 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,7 @@ /.idea/vcs.xml /.idea/workspace.xml /results.csv +/Complete_lecture 1.ipynb +/Complete notebooks/ +/Lectures/.ipynb_checkpoints/ +/.ipynb_checkpoints/Student_lecture 1-checkpoint.ipynb diff --git a/Lectures/Student_lecture 1.ipynb b/Lectures/Student_lecture 1.ipynb new file mode 100644 index 0000000..e1cb21f --- /dev/null +++ b/Lectures/Student_lecture 1.ipynb @@ -0,0 +1,46 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "collapsed": true, + "pycharm": { + "name": "#%% md\n" + } + }, + "source": [ + "## First Lecture\\n\",\n", + " What we are going to do today:\\n\n", + " - read TSP data\\n\n", + " - store nodes in data structure\\n\n", + " - plot raw data\\n\n", + " - define distance function\\n\n", + " - create distance matrix\\n\n", + " - generate naive solution \\n\n", + " - check if the solution is valid\\n\n", + " - evaluate solution!" + ] + } + ], + "metadata": { + "kernelspec": { + "name": "pycharm-61970693", + "language": "python", + "display_name": "PyCharm (AI2020BsC)" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.3" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} \ No newline at end of file diff --git a/Lectures/Student_lecture 2.ipynb b/Lectures/Student_lecture 2.ipynb new file mode 100644 index 0000000..552eee2 --- /dev/null +++ b/Lectures/Student_lecture 2.ipynb @@ -0,0 +1,37 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "collapsed": true, + "pycharm": { + "name": "#%% md\n" + } + }, + "source": [ + "## Second Lecture" + ] + } + ], + "metadata": { + "kernelspec": { + "name": "pycharm-61970693", + "language": "python", + "display_name": "PyCharm (AI2020BsC)" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.3" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} \ No newline at end of file diff --git a/Lectures/Student_lecture 3.ipynb b/Lectures/Student_lecture 3.ipynb new file mode 100644 index 0000000..6ef8662 --- /dev/null +++ b/Lectures/Student_lecture 3.ipynb @@ -0,0 +1,37 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "collapsed": true, + "pycharm": { + "name": "#%% md\n" + } + }, + "source": [ + "## Third Lecture" + ] + } + ], + "metadata": { + "kernelspec": { + "name": "pycharm-61970693", + "language": "python", + "display_name": "PyCharm (AI2020BsC)" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.3" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} \ No newline at end of file diff --git a/Lectures/Student_lecture 4.ipynb b/Lectures/Student_lecture 4.ipynb new file mode 100644 index 0000000..9a71243 --- /dev/null +++ b/Lectures/Student_lecture 4.ipynb @@ -0,0 +1,37 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "collapsed": true, + "pycharm": { + "name": "#%% md\n" + } + }, + "source": [ + "## Fourth Lecture" + ] + } + ], + "metadata": { + "kernelspec": { + "name": "pycharm-61970693", + "language": "python", + "display_name": "PyCharm (AI2020BsC)" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.3" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} \ No newline at end of file diff --git a/Student_lecture 1.ipynb b/Student_lecture 1.ipynb new file mode 100644 index 0000000..eee57ad --- /dev/null +++ b/Student_lecture 1.ipynb @@ -0,0 +1,60 @@ +{ + "cells": [ + { + "attachments": {}, + "cell_type": "markdown", + "metadata": { + "collapsed": true + }, + "source": [ + "## First Lecture\n", + "What we are going to do today:\n", + "- read TSP data\n", + "- store nodes in data structure\n", + "- plot raw data\n", + "- define distance function\n", + "- create distance matrix\n", + "- generate naive solution \n", + "- check if the solution is valid\n", + "- evaluate solution!" + ] + }, + { + "cell_type": "markdown", + "source": [ + "### Read TSP data\n" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Read TSP data\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.3" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} \ No newline at end of file diff --git a/run.py b/run.py index 3537dd8..1c9975c 100644 --- a/run.py +++ b/run.py @@ -23,8 +23,8 @@ def use_solver_to_compute_solution(solver, improve, index, results, name, verbos def run(show_plots=False, verbose=False): - problems = glob.glob('./problems/*.tsp') - # problems = ["./problems/eil76.tsp"] + # problems = glob.glob('./problems/*.tsp') + problems = ["./problems/eil76.tsp"] solvers_names = available_solvers.keys() improvers_names = available_improvers.keys() results = [] diff --git a/src/TSP_solver.py b/src/TSP_solver.py index ef37313..406752c 100644 --- a/src/TSP_solver.py +++ b/src/TSP_solver.py @@ -19,7 +19,6 @@ available_improvers = {"2-opt": loop2opt, class SolverTSP: - def __init__(self, algorithm_name, problem_instance): # assert algorithm_name in available_solvers, f"the {algorithm_name} initializer is not available currently." self.duration = np.inf @@ -57,12 +56,6 @@ class SolverTSP: self.solved = True self.evaluate_solution() self._gap() - # if verbose: - # print(f"### solution found with {self.gap} % gap in {self.duration} seconds ####", - # f"the total length for the solution found is {self.found_length}", - # f"while the optimal length is {prob_instance.best_sol}", - # f"the gap is {self.gap}%") - if return_value: return self.solution