{ "cells": [ { "attachments": {}, "cell_type": "markdown", "id": "83c2b1e7-b401-4a15-adf0-d43cebf9ad81", "metadata": {}, "source": [ "# **Algorithm project** # \n" ] }, { "attachments": {}, "cell_type": "markdown", "id": "0b4f92e5-ac40-4491-983d-890c4f0f6694", "metadata": {}, "source": [ "## Project context \n" ] }, { "attachments": {}, "cell_type": "markdown", "id": "5f483b31-1246-4f00-ae39-718ef92ce9eb", "metadata": {}, "source": [ "The French Environment and Energy Management Agency (ADEME) has launched a call for expressions of interest to develop mobility solutions adapted to different territories. CesiCDP, in collaboration with partners, specializes in Intelligent Multimodal Mobility. As part of this call, the CesiCDP team is working on the management of delivery routes to " ] }, { "attachments": {}, "cell_type": "markdown", "id": "fc23daaf-9f25-4c5a-bf6c-300a7ed8d623", "metadata": {}, "source": [ "Our aim is to develop an algorithm that will enable us to pass through all the delivery points in an optimized time." ] }, { "attachments": {}, "cell_type": "markdown", "id": "d633beb7-8f26-46d4-9cd9-1d0093e5b5c3", "metadata": {}, "source": [ "## Selected constraint\n" ] }, { "attachments": {}, "cell_type": "markdown", "id": "35fc1c3c-d7a9-4423-a948-aa00ab51dbf4", "metadata": {}, "source": [ "The constraint we chose was the following:\n", "- To have several trucks available simultaneously to make deliveries." ] }, { "attachments": {}, "cell_type": "markdown", "id": "ba356166-604a-4627-ac0f-93b76eb7a22d", "metadata": {}, "source": [ "## Formulation of the problem " ] }, { "attachments": {}, "cell_type": "markdown", "id": "c4d6888b-14e6-4745-880f-0a063ebf7476", "metadata": {}, "source": [ "Consider a graph $G=(V,E)$, where $V$ is the set of cities (or delivery points) and $E$ is the set of roads between cities. There are $k$ trucks available to make deliveries.\n", "\n", "The problem is to find a route for each truck, so that all deliveries are made in the shortest possible time, both to and from the depot.\n", "\n", "The problem we have with the above constraints is the VRP (Vehicle Routing Problem)." ] }, { "attachments": {}, "cell_type": "markdown", "id": "6d392f68", "metadata": {}, "source": [ "## Problem constraints " ] }, { "attachments": {}, "cell_type": "markdown", "id": "f95dba22", "metadata": {}, "source": [ "List of problem constraints:\n", "\n", "- All customers must be served\n", "- A customer can only be served by one vehicle.\n", "- When leaving a customer, a vehicle can only go to one other customer.\n", "\n", "We will therefore assign each customer to a route served by a single vehicle." ] }, { "attachments": {}, "cell_type": "markdown", "id": "c1ca5507", "metadata": {}, "source": [ "## Demonstrating the complexity of the vehicle routing problem (VRP) " ] }, { "attachments": {}, "cell_type": "markdown", "id": "37632b4b", "metadata": {}, "source": [ "#### **Introduction**\n", "\n", "The Vehicle Routing Problem (VRP) is an extension of the Traveling Salesman Problem (TSP), and is known to be an NP-hard problem. We will demonstrate the complexity of VRP based on the Hamiltonian chain problem, which is known to be NP-complete." ] }, { "attachments": {}, "cell_type": "markdown", "id": "6a63522a", "metadata": {}, "source": [ "#### **Preliminary definitions**\n", "\n", "- Hamiltonian chain problem**: the problem consists in determining whether a given undirected graph has a Hamiltonian chain, i.e. a path that visits each vertex exactly once.\n", "\n", "- Traveling Salesman Problem (TSP)**: the problem consists in finding the shortest possible circuit that visits each city in a given set of cities and returns to the original city.\n", "\n", "- Vehicle Routing Problem (VRP)**: the problem consists in delivering a series of customers with several vehicles while minimizing the total cost, such as delivery time or distance traveled." ] }, { "attachments": {}, "cell_type": "markdown", "id": "589a1874", "metadata": {}, "source": [ "#### **Proof of the complexity of the TSP**.\n", "\n", "The TSP is an extension of the Hamiltonian chain problem. In fact, a special case of the TSP is the Hamiltonian chain problem, in which all edges have the same weight (or cost). In this case, finding the shortest circuit in the TSP is equivalent to finding a Hamiltonian chain in the graph. Since the Hamiltonian chain problem is NP-complete, the TSP must be at least as difficult, so the TSP is NP-complete." ] }, { "attachments": {}, "cell_type": "markdown", "id": "92658e81", "metadata": {}, "source": [ "#### **Proof of the complexity of the VRP**.\n", "\n", "The VRP is an extension of the TSP. In fact, a special case of the VRP is the TSP where there is only one vehicle available to make deliveries. In this case, finding the solution to the VRP is the same as finding the solution to the TSP.\n", "\n", "Since the TSP is NP-complete, the VRP must be at least as difficult, so the VRP is NP-difficult. Furthermore, VRP introduces additional constraints, such as multiple vehicles and potentially vehicle capacities and time windows, making it even more complex." ] }, { "attachments": {}, "cell_type": "markdown", "id": "a4106346", "metadata": {}, "source": [ "#### **Conclusion**\n", "\n", "In conclusion, we have shown that VRP is an NP-hard problem by reducing it to the NP-complete TSP problem, which in turn can be reduced to the NP-complete Hamiltonian chain problem. This demonstration highlights the difficulty of solving the VRP, particularly for large instances. In practice, (meta)heuristic and approximate methods are often used to solve the VRP, as we shall see later." ] }, { "attachments": {}, "cell_type": "markdown", "id": "16b3b8a7-4658-4509-a511-7a395654e6f1", "metadata": {}, "source": [ "## Mathematical modeling " ] }, { "attachments": {}, "cell_type": "markdown", "id": "b54bfa8c", "metadata": {}, "source": [ "#### **Set and parameters**" ] }, { "attachments": {}, "cell_type": "markdown", "id": "637eb295", "metadata": {}, "source": [ "$V=\\{0,1,2,...,n_v\\}$ : the set of cities, where 0 is the base (or depot), $1,2,...,n_v$ are the delivery cities. $n_v+1$ will be the depot for the return.
\n", "$K=\\{1,2,...,k\\}$ : all trucks.
\n", "$E$ represents the arcs between two customers $i,j \\in V$
\n", "$G=(V,E)$ : the graph with V as vertices (cities) and E as edges
\n", "$d_{ij}$​ : distance (or travel time) from city i to city $j$ (travel cost)
\n", "$M$ : a great constant." ] }, { "attachments": {}, "cell_type": "markdown", "id": "1219e4f2", "metadata": {}, "source": [ "#### **Decision variables**" ] }, { "attachments": {}, "cell_type": "markdown", "id": "a6d398fa", "metadata": {}, "source": [ "$x_{ijk}$​ : binary variable worth 1 if truck $k$ moves from city $i$ to city $j$, and 0 otherwise." ] }, { "attachments": {}, "cell_type": "markdown", "id": "e635cf14", "metadata": {}, "source": [ "#### **Objective function**" ] }, { "attachments": {}, "cell_type": "markdown", "id": "56652859", "metadata": {}, "source": [ "$$\\min \\sum_{k∈K} \\sum_{⁡i∈V} \\sum_{⁡j∈V} d_{ij} x_{ijk} $$" ] }, { "attachments": {}, "cell_type": "markdown", "id": "a1465000", "metadata": {}, "source": [ "#### **VRP constraints**\n", "\n", "- Each city is visited once and only once:\n", "$$\\sum_{⁡k \\in K} \\sum_{⁡j \\in V} x_{ijk} = 1, \\forall i \\in V, i \\ne 0$$\n", "\n", "- If a truck visits a city, it must leave it:\n", "$$\\sum_{i \\in V} x_{ijk} = \\sum_{j \\in V} x_{ijk}, \\forall k \\in K, \\forall i \\in V, \\forall j \\in V $$\n", "
\n", "\n", "- Sub-tour elimination constraint (to ensure that each truck completes a full tour) :\n", "$$\\sum_{i \\in S, j \\notin S} x_{ijk} \\geq 1, \\forall k \\in K, \\forall \\; subset \\; S \\; de \\; V, 0 \\in S, S \\ne V $$" ] }, { "attachments": {}, "cell_type": "markdown", "id": "7670fdf4-884c-4352-83fa-eed0c8b50074", "metadata": {}, "source": [ "## Resolution algorithm (with coordinates)" ] }, { "attachments": {}, "cell_type": "markdown", "id": "45133ac2", "metadata": {}, "source": [ "#### Importing the necessary libraries" ] }, { "cell_type": "code", "execution_count": 1, "id": "794657d7", "metadata": {}, "outputs": [], "source": [ "from sklearn.cluster import KMeans\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import random, time, math\n", "from tests.libs.clustering import split_tour_across_clusters" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.11.3" } }, "nbformat": 4, "nbformat_minor": 5 }