From fa0f705a93286f172873c92b9e34b6390e7113e6 Mon Sep 17 00:00:00 2001 From: AnnePicus Date: Wed, 27 Aug 2025 07:12:56 +0300 Subject: [PATCH] English suggestions to Vehicle Routing --- .../vehicle_routing_problem.ipynb | 468 ++++++++++++------ 1 file changed, 309 insertions(+), 159 deletions(-) diff --git a/applications/logistics/vehicle_routing_problem/vehicle_routing_problem.ipynb b/applications/logistics/vehicle_routing_problem/vehicle_routing_problem.ipynb index 4fc129f0f..61011899a 100644 --- a/applications/logistics/vehicle_routing_problem/vehicle_routing_problem.ipynb +++ b/applications/logistics/vehicle_routing_problem/vehicle_routing_problem.ipynb @@ -4,7 +4,10 @@ "cell_type": "markdown", "id": "86d968ec", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ "# Vehicle Routing Problem (VRP)" @@ -14,14 +17,17 @@ "cell_type": "markdown", "id": "8157a732", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ "The Vehicle Routing Problem (VRP) is a combinatorial optimization problem that aims to determine the optimal routes for a fleet of vehicles to deliver goods to a set of locations while minimizing the total distance traveled or cost incurred. The problem is NP-hard, meaning that finding an exact solution is computationally infeasible for large instances, and heuristic or approximation algorithms are often used to find near-optimal solutions.\n", "\n", "The tutorial showcases how to solve the problem using the Quantum Approximate Optimization Algorithm (QAOA).\n", "\n", - "In the problem, each vehicle start from a different depot, visits a set of cities, and returns to its depot. The goal is to minimize the total travel cost while ensuring that each city is visited exactly once by one vehicle." + "In the problem, each vehicle starts from a different depot, visits a set of cities, and returns to its depot. The goal is to minimize the total travel cost while ensuring that each city is visited exactly once by one vehicle." ] }, { @@ -29,22 +35,22 @@ "id": "8a8ed215-eed4-4f49-a017-7613cbaf6d30", "metadata": {}, "source": [ - "## Mathematical formulation\n", + "## Mathematical Formulation\n", "\n", - "We are given:\n", + "Given:\n", "\n", "- A set of locations:\n", - " $L = {0, 1, \\dots, n-1}$
\n", - " Where the first $m$ locations are depots:
\n", - " $D = {0, 1, \\dots, m-1}$
\n", - " The remaining $n - m$ are cities:
\n", + " $L = {0, 1, \\dots, n-1}$ where
\n", + " - The first $m$ locations are depots: \n", + " $D = {0, 1, \\dots, m-1}$
\n", + " - The remaining $n - m$ are cities:\n", " $C = {m, m+1, \\dots, n-1}$\n", "- Each vehicle $k \\in D$:
\n", - " - Starts and ends its route at its own depot $k$.\n", - " - Visits a sequence of cities.\n", - " - Returns to its depot.\n", + " - Starts and ends its route at its own depot $k$\n", + " - Visits a sequence of cities\n", + " - Returns to its depot\n", "- Each city must be visited exactly once by one vehicle only.\n", - "- Each vehicle route has $P = p + 2$ positions (start + $p$ inner positions + end). You can think about the positions as timesteps. We call the variable `positions` because driving between cities does not take the same amount of time." + "- Each vehicle route has $P = p + 2$ positions (start + $p$ inner positions + end). You can think about the positions as timesteps. The variable are called `positions` because driving between cities does not take the same amount of time." ] }, { @@ -53,7 +59,7 @@ "metadata": {}, "source": [ "### Decision Variables\n", - "Let $x_{u,v}^k \\in \\{0,1\\}$ be a binary variable defined as:\n", + "Let $x_{u,v}^k \\in \\{0,1\\}$ be a binary variable defined as\n", "\n", "$$\n", "x_{u,v}^k =\n", @@ -74,13 +80,13 @@ "id": "184ca2fa-5777-4243-b7aa-1f6512e2529d", "metadata": {}, "source": [ - "### Constraints:\n", + "### Constraints\n", "1. Each city is visited exactly once:\n", "$$\n", "\\sum_{k\\in D}\\sum_{v=1}^{P-2} x_{u,v}^k = 1 \\,\\,\\,\\,\\forall u\\in C\n", "$$\n", - "Each city appears in exactly one vehicle's route, and not at start or end positions.
\n", - "2. Each car visit exactly 1 city in every position:\n", + "Each city appears in exactly one vehicle's route, and not at the start or end positions.
\n", + "2. Each car visits exactly one city in every position:\n", "$$\n", "\\sum_{u\\in C} x_{u,v}^k = 1 \\,\\,\\,\\,\\forall v\\in \\{1,\\dots,P-2\\},\\,\\,\\forall k\\in D\n", "$$\n", @@ -95,11 +101,11 @@ "$$\n", "Each vehicle starts and ends at its own depot only.\n", "\n", - "4. No city at start or end:\n", + "4. No city is at the start or end:\n", "$$\n", "x_{u,0}^k = x_{u,P-1}^k = 1 \\,\\,\\,\\, \\forall u\\in C \\,\\,\\,\\, \\forall k\\in D\n", "$$\n", - " **For constraints (3) and (4), we do not use qubits in the QAOA circuit, because they are pre-determined.** \n" + " **Constraints (3) and (4) do not use qubits in the QAOA circuit, because they are predetermined.** \n" ] }, { @@ -107,16 +113,16 @@ "id": "92db8cce-7617-4b3f-95f0-50a9ec4bf62e", "metadata": {}, "source": [ - "### Objective function\n", + "### Objective Function\n", "\n", - "We aim to minimize total travel cost, defined as:\n", + "The aim is to minimize total travel cost, defined as\n", "\n", "$$\n", "\\min_x \\quad \\sum_{k \\in D} \\sum_{v = 0}^{P - 2} \\sum_{u \\in L} \\sum_{w \\in L} \\text{dist}(u, w) \\cdot x_{u,v}^k \\cdot x_{w,v+1}^k\n", "$$\n", "\n", - "Where:\n", - "- $\\text{dist}(u, w)$ is the Euclidean distance between location $u$ and $w$.\n", + "where:\n", + "- $\\text{dist}(u, w)$ is the Euclidean distance between locations $u$ and $w$.\n", "- The sum computes all transitions $(u \\rightarrow w)$ for each vehicle between consecutive positions." ] }, @@ -125,9 +131,9 @@ "id": "d5814996-2a21-4513-9159-775ddf2e4f8f", "metadata": {}, "source": [ - "### The constraint functions\n", + "### Constraint Functions\n", "\n", - "All cities visited only once:\n", + "All cities are visited only once:\n", "\n", "$$\n", "\\sum_{u \\in C} \\left( \\sum_{k \\in D} \\sum_{v=0}^{P-2} x_{u,v}^k -1 \\right)^2=0\n", @@ -139,17 +145,20 @@ "\\sum_{k \\in D} \\sum_{v=1}^{P-2} \\left(\\sum_{u \\in C} x_{u,v}^k -1 \\right)^2=0\n", "$$\n", "\n", - "**These are added as penalty terms and multiplied by a scaling factor later in the notebook at the `cost` function. We ensure they will are actually equal to zero by adding them as penlty terms.**" + "**These are added as penalty terms and multiplied by a scaling factor later on in the `cost` function. Ensure they are actually equal to zero by adding them as penalty terms.**" ] }, { "cell_type": "markdown", "id": "9415dcb5", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ - "## Generating problem data" + "## Generating Problem Data" ] }, { @@ -161,7 +170,10 @@ "end_time": "2025-08-05T15:30:12.480901Z", "start_time": "2025-08-05T15:30:11.869651Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -193,11 +205,14 @@ "cell_type": "markdown", "id": "6c314be3", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ - "### Definition of positions\n", - "Assuming the cities are evenly divided among vehicles (more or less), we will use `possible_number_of_cities_per_vehicle`." + "### Defining Positions\n", + "Assuming the cities are more or less evenly divided among the vehicles, use `possible_number_of_cities_per_vehicle`:" ] }, { @@ -209,7 +224,10 @@ "end_time": "2025-08-05T15:30:12.488008Z", "start_time": "2025-08-05T15:30:11.882201Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -220,10 +238,13 @@ "cell_type": "markdown", "id": "c2273a2f", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ - "The total number of positions `num_positions` (or time slots) in a car route. We add $2$ for the start (depot) and end (return to depot) positions." + "The total number of positions `num_positions` (or time slots) in a car route. Add $2$ for the start (depot) and end (return to depot) positions:" ] }, { @@ -235,7 +256,10 @@ "end_time": "2025-08-05T15:30:12.489672Z", "start_time": "2025-08-05T15:30:11.895925Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -246,7 +270,10 @@ "cell_type": "markdown", "id": "1df0ae27", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ "All valid routes (time slots) positions that a vehicle can take:\n", @@ -264,7 +291,10 @@ "end_time": "2025-08-05T15:30:12.492656Z", "start_time": "2025-08-05T15:30:11.908650Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -280,7 +310,10 @@ "end_time": "2025-08-05T15:30:12.492770Z", "start_time": "2025-08-05T15:30:11.911185Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [ { @@ -299,7 +332,10 @@ "cell_type": "markdown", "id": "9a2bf7f7", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ "The inner positions are the positions that can be occupied by cities, excluding the start and end depots." @@ -314,7 +350,10 @@ "end_time": "2025-08-05T15:30:12.494254Z", "start_time": "2025-08-05T15:30:11.921800Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [ { @@ -335,13 +374,16 @@ "cell_type": "markdown", "id": "a5a96058", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ - "### Setting locations of cities\n", + "### Setting City Locations\n", "\n", - "Setting random locations in a square of size `(0, max_x_y)`$\\times$`(0, max_x_y)`.\n", - "To have the same result, we set the random seed. To have different results, change/delete the seed." + "Set random locations in a square of size `(0, max_x_y)`$\\times$`(0, max_x_y)`.\n", + "To have the same result, set the random seed. To have different results, change or delete the seed:" ] }, { @@ -353,7 +395,10 @@ "end_time": "2025-08-05T15:30:12.519705Z", "start_time": "2025-08-05T15:30:12.005181Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -372,7 +417,10 @@ "end_time": "2025-08-05T15:30:12.531957Z", "start_time": "2025-08-05T15:30:12.011762Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [ { @@ -419,7 +467,10 @@ "end_time": "2025-08-05T15:30:12.536002Z", "start_time": "2025-08-05T15:30:12.088961Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -458,7 +509,10 @@ "end_time": "2025-08-05T15:30:12.536211Z", "start_time": "2025-08-05T15:30:12.091786Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [ { @@ -482,12 +536,15 @@ "cell_type": "markdown", "id": "e17e96de", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ "The maximal cost of any candidate is `num_locations`$\\times$ `max_distance`.\n", "The minimal cost of any candidate is `num_locations`$\\times$ `min_distance`.\n", - "Hence, the maximal difference of eigenvalues of the total cost Hamiltonian is:" + "Hence, this is the maximal difference of eigenvalues of the total cost Hamiltonian:" ] }, { @@ -499,7 +556,10 @@ "end_time": "2025-08-05T15:30:12.538231Z", "start_time": "2025-08-05T15:30:12.095767Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -510,10 +570,13 @@ "cell_type": "markdown", "id": "3ed44d24", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ - "In order to set the maximal difference of eigenvalues of the total cost Hamiltonian to 1, we must scale the distances by `DISTANCE_NORMALISATION`:" + "To set the maximal difference of eigenvalues of the total cost Hamiltonian to 1, scale the distances by `DISTANCE_NORMALISATION`:" ] }, { @@ -525,7 +588,10 @@ "end_time": "2025-08-05T15:30:12.538305Z", "start_time": "2025-08-05T15:30:12.098216Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -541,7 +607,10 @@ "end_time": "2025-08-05T15:30:12.538376Z", "start_time": "2025-08-05T15:30:12.100843Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [ { @@ -566,12 +635,12 @@ "id": "ef378b4a-0d56-4003-8c7f-1240c4180b5d", "metadata": {}, "source": [ - "## Normalising the cost and mixer Hamiltonians.\n", - "**This normalisation improve the probability to find good solutions.**\n", - "**If it is too much information, ignore it for now, and go to \"VRP objective function definition\" to focus on the VRP problem itself.**\n", + "## Normalizing the Cost and Mixer Hamiltonians\n", + "**This normalization improves the probability of finding good solutions.**\n", + "If this is too much information right now, skip it and focus on the VRP problem itself under \"Defining the VRP Objective Function\".\n", "\n", "The mixer Hamiltonian is effectively $X/2$ and has eigenvalues $-0.5$ and $+0.5$. So the difference between minimum and maximum eigenvalues is exactly 1.\n", - "This can be rescaled by a global scaling parameter." + "You can rescale it using a global scaling parameter:" ] }, { @@ -589,10 +658,10 @@ "id": "419a9bab-a8d9-4588-8923-c6efc26ef9d6", "metadata": {}, "source": [ - "The cost Hamiltonian should be similar in eigenvalue difference to the mixer Hamiltonian and should be normalised to about 1.\n", - "This will be taken care off later by the distance normalisation.\n", + "The cost Hamiltonian should be similar in eigenvalue difference to the mixer Hamiltonian and should be normalized to about 1.\n", + "The distance normalization will take care of it later.\n", "\n", - "To find the exact normalisation requires solving this NP hard problem, so we always use approximation. Since this is approximate, there is a relative scaling parameter we can tweak." + "To find the exact normalization requires solving this NP-hard problem, so always use approximation. Since it is approximate, you can tweak the relative scaling parameter." ] }, { @@ -610,7 +679,7 @@ "id": "2d5c3788-c039-43ff-bed6-24de1b4372f9", "metadata": {}, "source": [ - "The overall normalization of the total cost is thus:" + "The overall normalization of the total cost is therefore:" ] }, { @@ -640,7 +709,7 @@ "metadata": {}, "source": [ "The constraint Hamiltonian has the property that a minimal constraint violation is 1 and no constraint violation is 0.\n", - "We wish to normalise the constraint Hamiltonian relative to the total cost Hamiltonian such that the constraint violation will be 1~2 x larger than the maximal difference between total cost values." + "Normalize the constraint Hamiltonian relative to the total cost Hamiltonian such that the constraint violation is 1~2 x larger than the maximal difference between total cost values:" ] }, { @@ -658,7 +727,7 @@ "id": "21ebfec4-dc8c-4fda-b259-1fb291959727", "metadata": {}, "source": [ - "The overall normalisation of the constraint Hamiltonian is similarly:" + "The overall normalization of the constraint Hamiltonian is similarly:" ] }, { @@ -688,24 +757,27 @@ "id": "6e44e226-5b6b-4404-8402-1b7f2228445a", "metadata": {}, "source": [ - "The normalisation coefficients are hyperparamaters that can be tuned to improve the performance of the QAOA algorithm.\n", - "Let us summarize how the normalisation coefficients together with the cost and mixer Hamiltonians:\n", + "The normalization coefficients are hyperparameters that can be tuned to improve the performance of QAOA.\n", + "Summarize the normalization coefficients together with the cost and mixer Hamiltonians:\n", "$$\n", "H = C_{gsp} \\cdot \\left(\\beta\\cdot H_{mixer} + \\gamma \\cdot C_{ron} \\left(H_{objective} + C_{rcn}\\cdot H_{constraints}\\right)\\right)\n", "$$\n", "\n", - "Where $\\beta$ and $\\gamma$ are the QAOA's variational parameters. $C_{gsp}$ is the global scaling parameter, $C_{ron}$ is the relative objective normalisation, and $C_{rcn}$ is the relative constraint normalisation coefficients. In this method, we normalise both the entire Hamiltonian and each individual term—including the constraints Hamiltonian, to ensure the solution satisfies the constraints, and the objective Hamiltonian, to increase the probability of finding the optimal objective value." + "Where $\\beta$ and $\\gamma$ are the QAOA's variational parameters. $C_{gsp}$ is the global scaling parameter, $C_{ron}$ is the relative objective normalization, and $C_{rcn}$ is the relative constraint normalization coefficients. This method normalizes both the entire Hamiltonian and each individual term—including the constraint Hamiltonian to ensure the solution satisfies the constraints, and the objective Hamiltonian to increase the probability of finding the optimal objective value." ] }, { "cell_type": "markdown", "id": "f4eb654b", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ - "## VRP objective function definition\n", - "First, define number of functions that compose the objective function.\n", + "## Defining the VRP Objective Function\n", + "First, define number of functions that comprise the objective function.\n", "\n", "A major difficulty is to map 3D (city, position, vehicle) to 1D index in the array of decision variables." ] @@ -714,15 +786,19 @@ "cell_type": "markdown", "id": "897e5b98", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ - "##### Find the right index in array\n", - "Access the value of the binary decision variable x that encodes whether city (or depot) u is visited at position v by vehicle k.\n", - "`u`- city\n", - "`v` - position (time slot)\n", - "`x` is the array of decision variables\n", - "`k` is the vehicle number" + "### Finding the Right Index in the Array\n", + "Access the value of the binary decision variable x that encodes whether city (or depot) `u` is visited at position `v` by vehicle `k`.\n", + "\n", + "- `u` - city\n", + "- `v` - position (time slot)\n", + "- `x` - the array of decision variables\n", + "- `k` - the vehicle number " ] }, { @@ -734,7 +810,10 @@ "end_time": "2025-08-05T15:30:12.538410Z", "start_time": "2025-08-05T15:30:12.105033Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -762,7 +841,7 @@ " return 0\n", " # Handle city logic (when `u` is a city and `v` is an inner position)\n", " else:\n", - " # We map 3D (city, position, vehicle) to 1D index\n", + " # Map 3D (city, position, vehicle) to 1D index\n", " city_index = u - num_vehicles\n", " pos_index = v - 1\n", " flat_index = (\n", @@ -777,12 +856,15 @@ "cell_type": "markdown", "id": "8ba54db8", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ - "Making sure we satisfy the following constraints:\n", - "1. Each city is assigned to exactly one vehicle and one route position.\n", - "2. Each inner position of a route (per vehicle) is filled by exactly one city." + "Make sure to satisfy these constraints:\n", + "- Each city is assigned to exactly one vehicle and one route position.\n", + "- Each inner position of a route (per vehicle) is filled by exactly one city." ] }, { @@ -794,7 +876,10 @@ "end_time": "2025-08-05T15:30:12.539943Z", "start_time": "2025-08-05T15:30:12.108685Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -841,10 +926,13 @@ "cell_type": "markdown", "id": "a9c70763", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ - "### Total travel cost for all vehicle routes" + "### Determining Total Travel Cost for All Vehicle Routes" ] }, { @@ -856,7 +944,10 @@ "end_time": "2025-08-05T15:30:12.539997Z", "start_time": "2025-08-05T15:30:12.111331Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -869,7 +960,7 @@ " \"\"\"\n", " total_travel_cost = 0\n", "\n", - " # Loop through each position in the route except the last (we look ahead to position + 1)\n", + " # Loop through each position in the route except the last (look ahead to position + 1)\n", " for position in range(num_positions - 1):\n", "\n", " # Consider every pair of locations\n", @@ -892,10 +983,13 @@ "cell_type": "markdown", "id": "78ba9f47", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ - "### Definition of the constraints" + "### Defining Constraints" ] }, { @@ -907,7 +1001,10 @@ "end_time": "2025-08-05T15:30:12.540034Z", "start_time": "2025-08-05T15:30:12.115852Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -982,10 +1079,13 @@ "cell_type": "markdown", "id": "46ab2932", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ - "##### Total cost function for the VRP is the sum of the total travel cost and the constraints." + "The total cost function for the VRP is the sum of the total travel cost and the constraints:" ] }, { @@ -997,7 +1097,10 @@ "end_time": "2025-08-05T15:30:12.541635Z", "start_time": "2025-08-05T15:30:12.125695Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -1014,11 +1117,14 @@ "cell_type": "markdown", "id": "9d1c641a", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ - "## Building the QAOA model\n", - "**Define the number of layers**" + "## Building the QAOA Model\n", + "Define the number of layers:" ] }, { @@ -1030,7 +1136,10 @@ "end_time": "2025-08-05T15:30:12.543201Z", "start_time": "2025-08-05T15:30:12.139978Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -1056,10 +1165,13 @@ "cell_type": "markdown", "id": "7ade94ce", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ - "## Synthesizing the model" + "## Synthesizing the Model" ] }, { @@ -1071,7 +1183,10 @@ "end_time": "2025-08-05T15:31:47.723440Z", "start_time": "2025-08-05T15:30:12.226742Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [ { @@ -1091,12 +1206,15 @@ "cell_type": "markdown", "id": "80c01d15", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ - "## Execution\n", - "**After we have the QAOA circuit, we can execute it in the hybrid scheme.**\n", - "**First, define the `ExecutionSession` for the optimization process, and the initial parameters.**" + "## Executing\n", + "When you have the QAOA circuit, execute it in the hybrid scheme.\n", + "First, define `ExecutionSession` for the optimization process and the initial parameters:" ] }, { @@ -1108,7 +1226,10 @@ "end_time": "2025-08-05T15:31:47.740367Z", "start_time": "2025-08-05T15:31:47.729115Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -1143,11 +1264,14 @@ "cell_type": "markdown", "id": "2d6f908a", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ - "#### The cost function definition for the execution\n", - "For each measurement state, the cost function is calculated by the `objective` function of the VRP problem." + "**The cost function definition for the execution:** \n", + "For each measurement state, the cost function is calculated by the `objective` function of the VRP problem:" ] }, { @@ -1159,7 +1283,10 @@ "end_time": "2025-08-05T15:31:47.757928Z", "start_time": "2025-08-05T15:31:47.741162Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -1170,12 +1297,15 @@ "cell_type": "markdown", "id": "6b224073", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ - "**A function to estimate the cost function in each iteration.**\n", + "**A function estimates the cost function in each iteration.**\n", "\n", - "This is done by the `estimate_cost` method of the `ExecutionSession` class." + "Use the `estimate_cost` method of the `ExecutionSession` class:" ] }, { @@ -1187,7 +1317,10 @@ "end_time": "2025-08-05T15:31:47.758292Z", "start_time": "2025-08-05T15:31:47.746Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -1211,11 +1344,14 @@ "cell_type": "markdown", "id": "9f918d0b", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ - "### Running the optimization process\n", - "Using `scipy.optimize.minimize` to minimize the cost function.\n", + "### Running the Optimization Process\n", + "Use `scipy.optimize.minimize` to minimize the cost function.\n", "\n", "**You may increase the `max_iterations` to have more iterations.**" ] @@ -1229,7 +1365,10 @@ "end_time": "2025-08-05T15:32:11.180348Z", "start_time": "2025-08-05T15:31:47.754088Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -1248,11 +1387,14 @@ "cell_type": "markdown", "id": "522ca95c", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ - "## Analyzing the results\n", - "**It is possible to make a convergences graph if you have more iterations.**" + "## Analyzing the Results\n", + "If you have more iterations you can make a convergence graph:" ] }, { @@ -1264,7 +1406,10 @@ "end_time": "2025-08-05T15:32:11.182596Z", "start_time": "2025-08-05T15:32:11.180181Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -1278,11 +1423,14 @@ "cell_type": "markdown", "id": "4ea9a257", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ - "#### Optimized parameters\n", - "It is relevant to watch for 4 or more circuit layers." + "### Optimizing Parameters\n", + "Watch for four or more circuit layers:" ] }, { @@ -1294,7 +1442,10 @@ "end_time": "2025-08-05T15:32:11.384266Z", "start_time": "2025-08-05T15:32:11.189650Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [ { @@ -1331,10 +1482,13 @@ "cell_type": "markdown", "id": "de939124", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ - "Accumulating the statistic with the final optimized parameters" + "Accumulate the statistics with the final optimized parameters:" ] }, { @@ -1346,7 +1500,10 @@ "end_time": "2025-08-05T15:32:26.569559Z", "start_time": "2025-08-05T15:32:11.333103Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -1362,7 +1519,10 @@ "end_time": "2025-08-05T15:33:41.096615Z", "start_time": "2025-08-05T15:33:33.498543Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [ { @@ -1411,10 +1571,13 @@ "cell_type": "markdown", "id": "0a0bf11d", "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "source": [ - "### The best solution found" + "### Best Solution " ] }, { @@ -1426,7 +1589,10 @@ "end_time": "2025-08-05T15:32:33.386362Z", "start_time": "2025-08-05T15:32:33.383524Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [ { @@ -1453,7 +1619,10 @@ "end_time": "2025-08-05T15:32:33.389228Z", "start_time": "2025-08-05T15:32:33.386972Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [ { @@ -1496,7 +1665,10 @@ "end_time": "2025-08-05T15:32:33.484010Z", "start_time": "2025-08-05T15:32:33.464124Z" }, - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [ { @@ -1570,28 +1742,6 @@ "\n", "plt.title(\"Cities Colored by Visiting Vehicle + Directed Routes\")" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b13a4d30", - "metadata": { - "ExecuteTime": { - "end_time": "2025-08-05T15:32:33.484111Z", - "start_time": "2025-08-05T15:32:33.476699Z" - }, - "collapsed": false - }, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "64ced1ba-7f0e-44b6-8dc6-dc1df08e3621", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": {