Notebooks lectures

This commit is contained in:
Dario Mantegazza 2020-10-01 18:03:04 +02:00
parent bba6d0f428
commit f2eaab99dc
8 changed files with 223 additions and 9 deletions

4
.gitignore vendored
View file

@ -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

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

60
Student_lecture 1.ipynb Normal file
View file

@ -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
}

4
run.py
View file

@ -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 = []

View file

@ -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