Skip to content

Commit

Permalink
deploy: c57920b
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandrozocca committed Jan 12, 2024
1 parent 3a3aa65 commit a94a058
Show file tree
Hide file tree
Showing 76 changed files with 126 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"```{index} single: application; Traveling Salesperson Problem\n",
"```{index} single: application; Traveling Salesman Problem\n",
"```\n",
"```{index} gurobi\n",
"```\n",
"\n",
"# Extra material: Traveling Salesperson Problem\n"
"# Extra material: Traveling Salesman Problem\n"
]
},
{
Expand All @@ -32,24 +32,24 @@
"Note that an important formulation requires an exponential number of constraints, rendering it impractical to explicitly implement.\n",
"In the end, we will delve on how classic optimization techniques can be used to attack this problem in a way that is scalable.\n",
"\n",
"This notebook focuses on the [Traveling Salesperson Problem](https://en.wikipedia.org/wiki/Travelling_Salesperson_problem) which may be the most studied (combinatorial) optimization problem.\n",
"This notebook focuses on the [Traveling Salesman Problem](https://en.wikipedia.org/wiki/Travelling_Salesman_problem) which may be the most studied (combinatorial) optimization problem.\n",
"\n",
"A wonderful [source](https://www.math.uwaterloo.ca/tsp/) you may like to visit is maintained by [Prof. Bill Cook](https://www.math.uwaterloo.ca/~bico/).\n",
"You may consider reading this enlightening and exciting [book on the pursuit](https://press.princeton.edu/books/paperback/9780691163529/in-pursuit-of-the-traveling-Salesperson).\n",
"You may consider reading this enlightening and exciting [book on the pursuit](https://press.princeton.edu/books/paperback/9780691163529/in-pursuit-of-the-traveling-salesman).\n",
"\n",
"The main challenge when modelling the TSP is the _connectivity_ of the solution.\n",
"\n",
"The [WikiPedia page](https://en.wikipedia.org/wiki/Travelling_Salesperson_problem) lists two well-known models, the [Miller–Tucker–Zemlin](https://en.wikipedia.org/wiki/Travelling_Salesperson_problem#Miller%E2%80%93Tucker%E2%80%93Zemlin_formulation[21]) and the [Dantzig–Fulkerson–Johnson](https://en.wikipedia.org/wiki/Travelling_Salesperson_problem#Dantzig%E2%80%93Fulkerson%E2%80%93Johnson_formulation).\n",
"The [Wikipedia page](https://en.wikipedia.org/wiki/Travelling_Salesman_problem) lists two well-known models, the [Miller–Tucker–Zemlin](https://en.wikipedia.org/wiki/Travelling_Salesman_problem#Miller%E2%80%93Tucker%E2%80%93Zemlin_formulation[21]) and the [Dantzig–Fulkerson–Johnson](https://en.wikipedia.org/wiki/Travelling_Salesman_problem#Dantzig%E2%80%93Fulkerson%E2%80%93Johnson_formulation).\n",
"\n",
"These are not the only TSP models, see [this](https://co-enzyme.fr/blog/spanning-tree-flow-based-formulations-for-the-asymmetric-traveling-Salesperson-problem-tsp/) or [this](https://dm872.github.io/assets/dm872-TSP_Formulations.pdf) overviews.\n",
"These are not the only TSP models, see [this](https://co-enzyme.fr/blog/spanning-tree-flow-based-formulations-for-the-asymmetric-traveling-Salesman-problem-tsp/) or [this](https://dm872.github.io/assets/dm872-TSP_Formulations.pdf) overviews.\n",
"A thorough [comparison](https://www.sciencedirect.com/science/article/pii/S2192437620600115) is also available.\n",
"\n",
"Besides the practical computation difficulties, different formulations also have different merits as basis to model different business requirements.\n",
"A good example is this [very rich routing problem](https://onlinelibrary.wiley.com/doi/full/10.1002/net.21962) for which the computational impact of different model choices for the TSP parts of it has also been [studied](https://www.ubvu.vu.nl/scripties/getpdf.cfm?facid=27&id=21392).\n",
"\n",
"As said, we focus on the [MTZ](https://en.wikipedia.org/wiki/Travelling_Salesperson_problem#Miller%E2%80%93Tucker%E2%80%93Zemlin_formulation[21]) and the [DFJ](https://en.wikipedia.org/wiki/Travelling_Salesperson_problem#Dantzig%E2%80%93Fulkerson%E2%80%93Johnson_formulation) models.\n",
"As said, we focus on the [MTZ](https://en.wikipedia.org/wiki/Travelling_Salesman_problem#Miller%E2%80%93Tucker%E2%80%93Zemlin_formulation[21]) and the [DFJ](https://en.wikipedia.org/wiki/Travelling_Salesman_problem#Dantzig%E2%80%93Fulkerson%E2%80%93Johnson_formulation) models.\n",
"\n",
"A first inspection to these models may invite you to choose the former and abandon any consideration of the latter, on the grounds of compactness: the [MTZ](https://en.wikipedia.org/wiki/Travelling_Salesperson_problem#Miller%E2%80%93Tucker%E2%80%93Zemlin_formulation[21]) model consists of a polynomial number of variables and constraints, while the [DFJ](https://en.wikipedia.org/wiki/Travelling_Salesperson_problem#Dantzig%E2%80%93Fulkerson%E2%80%93Johnson_formulation) model requires an exponential number of constraints.\n",
"A first inspection to these models may invite you to choose the former and abandon any consideration of the latter, on the grounds of compactness: the [MTZ](https://en.wikipedia.org/wiki/Travelling_Salesman_problem#Miller%E2%80%93Tucker%E2%80%93Zemlin_formulation[21]) model consists of a polynomial number of variables and constraints, while the [DFJ](https://en.wikipedia.org/wiki/Travelling_Salesman_problem#Dantzig%E2%80%93Fulkerson%E2%80%93Johnson_formulation) model requires an exponential number of constraints.\n",
"\n",
"In the case of the TSP, as this notebook shows, the strength of models is of paramount importance when we need to actually solve the problem.\n",
"\n",
Expand Down Expand Up @@ -209,7 +209,7 @@
"source": [
"def generate_tsp(n: int = 10, seed: int = 2023) -> dict[str, any]:\n",
" \"\"\"\n",
" Generate a Traveling Salesperson Problem (TSP) instance.\n",
" Generate a Traveling Salesman Problem (TSP) instance.\n",
"\n",
" Args:\n",
" n (int, optional): Number of nodes. Defaults to 10.\n",
Expand Down Expand Up @@ -495,7 +495,7 @@
"\n",
"An immediate improvement to the core model is just to fix the `self-loops` to 0, i.e. $x_{ii} = 0$, but that is not enough as pairwise loops $x_{ij} = x_{ji} = 1$ become the next culprit.\n",
"\n",
"An inductive reasoning on how to forbid all this _sub-tours_ leads to the well-known [**Dantzig, Fulkerson and Johnson**](https://en.wikipedia.org/wiki/Travelling_Salesperson_problem#Dantzig%E2%80%93Fulkerson%E2%80%93Johnson_formulation) model\n",
"An inductive reasoning on how to forbid all this _sub-tours_ leads to the well-known [**Dantzig, Fulkerson and Johnson**](https://en.wikipedia.org/wiki/Travelling_Salesman_problem#Dantzig%E2%80%93Fulkerson%E2%80%93Johnson_formulation) model\n",
"and formulates the TSP as:\n",
"$$\n",
"\\begin{array}{rrcll}\n",
Expand All @@ -521,7 +521,7 @@
"\n",
"Since this model requires an exponential number of (so-called sub-tour elimination) constraints we may prefer to start with a more compact model.\n",
"\n",
"Fortunately, a [compact](https://en.wikipedia.org/wiki/Travelling_Salesperson_problem#Miller-Tucker-Zemlin_formulation) model exists.\n",
"Fortunately, a [compact](https://en.wikipedia.org/wiki/Travelling_Salesman_problem#Miller-Tucker-Zemlin_formulation) model exists.\n",
"This ingenious model, devised by C. E. Miller, Alfred E. Tucker and R. A. Zemlin in 1960 adds _sequence_ variables $u_i$ and replace the connectivity (also known as subtour elimination) constraints which are in a exponential number by circa $n^2$ sequence constraints.\n",
"\n",
"$$\n",
Expand Down Expand Up @@ -2362,7 +2362,7 @@
"source": [
"def SymmetricTSPViaGurobi(C, trace):\n",
" \"\"\"\n",
" Solve the symmetric traveling Salesperson problem using Gurobi.\n",
" Solve the symmetric traveling Salesman problem using Gurobi.\n",
"\n",
" Args:\n",
" C: Cost matrix (symmetric).\n",
Expand Down Expand Up @@ -2427,7 +2427,7 @@
"source": [
"def GurobiSymmetric(instance, trace):\n",
" \"\"\"\n",
" Solve the symmetric traveling Salesperson problem using Gurobi.\n",
" Solve the symmetric traveling salesman problem using Gurobi.\n",
"\n",
" Args:\n",
" instance: TSP instance.\n",
Expand Down Expand Up @@ -3394,9 +3394,9 @@
"source": [
"#### Multiple TSP\n",
"\n",
"Suppose that you start at some node with $k$ Salesperson that should partition the other nodes and return to the starting node.\n",
"Suppose that you start at some node with $k$ sales persons that should partition the other nodes and return to the starting node.\n",
"\n",
"Then, it is enough to replicate that node into $k$ replicas, with a prohibitively large cost between all pairs of replicas (to force the Salesperson to go on a route).\n",
"Then, it is enough to replicate that node into $k$ replicas, with a prohibitively large cost between all pairs of replicas (to force the sales person to go on a route).\n",
"\n",
"*Note that this modified TSP stays symmetric if instance given was symmetric!*\n",
"\n",
Expand Down Expand Up @@ -3437,7 +3437,7 @@
"id": "nx5QYrxxu7it"
},
"source": [
"For this instance node $17$ seems to be an ideal candidate for the home base of $2$ Salesperson."
"For this instance node $17$ seems to be an ideal candidate for the home base of $2$ sales persons."
]
},
{
Expand Down Expand Up @@ -3685,7 +3685,7 @@
"source": [
"def AsymmetricTSPViaGurobi(C, trace):\n",
" \"\"\"\n",
" Solve the asymmetric traveling Salesperson problem using Gurobi.\n",
" Solve the asymmetric traveling salesman problem using Gurobi.\n",
"\n",
" Args:\n",
" C: Cost matrix.\n",
Expand Down Expand Up @@ -3752,7 +3752,7 @@
"source": [
"def AsymmetricTSPViaPyomo(C, solver, trace):\n",
" \"\"\"\n",
" Solve the asymmetric traveling Salesperson problem using Pyomo.\n",
" Solve the asymmetric traveling salesman problem using Pyomo.\n",
"\n",
" Args:\n",
" C: Cost matrix.\n",
Expand Down Expand Up @@ -3810,7 +3810,7 @@
"source": [
"def SymmetricTSPViaPyomo(C, solver, trace):\n",
" \"\"\"\n",
" Solve the asymmetric traveling Salesperson problem using Pyomo.\n",
" Solve the asymmetric traveling salesman problem using Pyomo.\n",
"\n",
" Args:\n",
" C: Cost matrix.\n",
Expand Down
6 changes: 3 additions & 3 deletions genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@


<li class="toctree-l2"><a class="reference internal" href="notebooks/04/07-forex-arbitrage.html">Extra material: Forex Arbitrage</a></li>
<li class="toctree-l2"><a class="reference internal" href="notebooks/04/08-traveling-salesperson-problem.html">Extra material: Traveling Salesperson Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="notebooks/04/08-traveling-salesman-problem.html">Extra material: Traveling Salesman Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="notebooks/04/09-shortest-path-road-networks.html">Extra material: Shortest path problem in real life</a></li>


Expand Down Expand Up @@ -510,7 +510,7 @@ <h2 id="A">A</h2>
</li>
<li><a href="notebooks/04/03-gasoline-distribution.html#index-0">transportation</a>
</li>
<li><a href="notebooks/04/08-traveling-salesperson-problem.html#index-0">Traveling Salesperson Problem</a>
<li><a href="notebooks/04/08-traveling-salesman-problem.html#index-0">Traveling Salesman Problem</a>
</li>
</ul></li>
</ul></td>
Expand Down Expand Up @@ -579,7 +579,7 @@ <h2 id="G">G</h2>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="notebooks/04/04-exam-room-scheduling.html#index-3">graph coloring</a>
</li>
<li><a href="notebooks/04/08-traveling-salesperson-problem.html#index-1">gurobi</a>
<li><a href="notebooks/04/08-traveling-salesman-problem.html#index-1">gurobi</a>
</li>
</ul></td>
</tr></table>
Expand Down
2 changes: 1 addition & 1 deletion intro.html
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@


<li class="toctree-l2"><a class="reference internal" href="notebooks/04/07-forex-arbitrage.html">Extra material: Forex Arbitrage</a></li>
<li class="toctree-l2"><a class="reference internal" href="notebooks/04/08-traveling-salesperson-problem.html">Extra material: Traveling Salesperson Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="notebooks/04/08-traveling-salesman-problem.html">Extra material: Traveling Salesman Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="notebooks/04/09-shortest-path-road-networks.html">Extra material: Shortest path problem in real life</a></li>


Expand Down
2 changes: 1 addition & 1 deletion notebooks/01/01-production-planning.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@


<li class="toctree-l2"><a class="reference internal" href="../04/07-forex-arbitrage.html">Extra material: Forex Arbitrage</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/08-traveling-salesperson-problem.html">Extra material: Traveling Salesperson Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/08-traveling-salesman-problem.html">Extra material: Traveling Salesman Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/09-shortest-path-road-networks.html">Extra material: Shortest path problem in real life</a></li>


Expand Down
2 changes: 1 addition & 1 deletion notebooks/01/01.00.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@


<li class="toctree-l2"><a class="reference internal" href="../04/07-forex-arbitrage.html">Extra material: Forex Arbitrage</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/08-traveling-salesperson-problem.html">Extra material: Traveling Salesperson Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/08-traveling-salesman-problem.html">Extra material: Traveling Salesman Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/09-shortest-path-road-networks.html">Extra material: Shortest path problem in real life</a></li>


Expand Down
2 changes: 1 addition & 1 deletion notebooks/01/02-production-planning-basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@


<li class="toctree-l2"><a class="reference internal" href="../04/07-forex-arbitrage.html">Extra material: Forex Arbitrage</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/08-traveling-salesperson-problem.html">Extra material: Traveling Salesperson Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/08-traveling-salesman-problem.html">Extra material: Traveling Salesman Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/09-shortest-path-road-networks.html">Extra material: Shortest path problem in real life</a></li>


Expand Down
2 changes: 1 addition & 1 deletion notebooks/01/03-production-planning-advanced.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@


<li class="toctree-l2"><a class="reference internal" href="../04/07-forex-arbitrage.html">Extra material: Forex Arbitrage</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/08-traveling-salesperson-problem.html">Extra material: Traveling Salesperson Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/08-traveling-salesman-problem.html">Extra material: Traveling Salesman Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/09-shortest-path-road-networks.html">Extra material: Shortest path problem in real life</a></li>


Expand Down
2 changes: 1 addition & 1 deletion notebooks/02/01-bim.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@


<li class="toctree-l2"><a class="reference internal" href="../04/07-forex-arbitrage.html">Extra material: Forex Arbitrage</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/08-traveling-salesperson-problem.html">Extra material: Traveling Salesperson Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/08-traveling-salesman-problem.html">Extra material: Traveling Salesman Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/09-shortest-path-road-networks.html">Extra material: Shortest path problem in real life</a></li>


Expand Down
2 changes: 1 addition & 1 deletion notebooks/02/02-lad-regression.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@


<li class="toctree-l2"><a class="reference internal" href="../04/07-forex-arbitrage.html">Extra material: Forex Arbitrage</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/08-traveling-salesperson-problem.html">Extra material: Traveling Salesperson Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/08-traveling-salesman-problem.html">Extra material: Traveling Salesman Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/09-shortest-path-road-networks.html">Extra material: Shortest path problem in real life</a></li>


Expand Down
2 changes: 1 addition & 1 deletion notebooks/02/02.00.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@


<li class="toctree-l2"><a class="reference internal" href="../04/07-forex-arbitrage.html">Extra material: Forex Arbitrage</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/08-traveling-salesperson-problem.html">Extra material: Traveling Salesperson Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/08-traveling-salesman-problem.html">Extra material: Traveling Salesman Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/09-shortest-path-road-networks.html">Extra material: Shortest path problem in real life</a></li>


Expand Down
2 changes: 1 addition & 1 deletion notebooks/02/03-mad-portfolio-optimization.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@


<li class="toctree-l2"><a class="reference internal" href="../04/07-forex-arbitrage.html">Extra material: Forex Arbitrage</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/08-traveling-salesperson-problem.html">Extra material: Traveling Salesperson Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/08-traveling-salesman-problem.html">Extra material: Traveling Salesman Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/09-shortest-path-road-networks.html">Extra material: Shortest path problem in real life</a></li>


Expand Down
2 changes: 1 addition & 1 deletion notebooks/02/04-bim-maxmin.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@


<li class="toctree-l2"><a class="reference internal" href="../04/07-forex-arbitrage.html">Extra material: Forex Arbitrage</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/08-traveling-salesperson-problem.html">Extra material: Traveling Salesperson Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/08-traveling-salesman-problem.html">Extra material: Traveling Salesman Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/09-shortest-path-road-networks.html">Extra material: Shortest path problem in real life</a></li>


Expand Down
2 changes: 1 addition & 1 deletion notebooks/02/05-bim-fractional.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@


<li class="toctree-l2"><a class="reference internal" href="../04/07-forex-arbitrage.html">Extra material: Forex Arbitrage</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/08-traveling-salesperson-problem.html">Extra material: Traveling Salesperson Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/08-traveling-salesman-problem.html">Extra material: Traveling Salesman Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/09-shortest-path-road-networks.html">Extra material: Shortest path problem in real life</a></li>


Expand Down
2 changes: 1 addition & 1 deletion notebooks/02/06-bim-dual.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@


<li class="toctree-l2"><a class="reference internal" href="../04/07-forex-arbitrage.html">Extra material: Forex Arbitrage</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/08-traveling-salesperson-problem.html">Extra material: Traveling Salesperson Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/08-traveling-salesman-problem.html">Extra material: Traveling Salesman Problem</a></li>
<li class="toctree-l2"><a class="reference internal" href="../04/09-shortest-path-road-networks.html">Extra material: Shortest path problem in real life</a></li>


Expand Down
Loading

0 comments on commit a94a058

Please sign in to comment.