From 11d61c9b4b5242630878481b7e189b084c1b6f9c Mon Sep 17 00:00:00 2001
From: awenjb <126257927+awenjb@users.noreply.github.com>
Date: Wed, 2 Apr 2025 16:17:23 +0200
Subject: [PATCH] Some fixes in Jupyter files

---
 python/visualisation_benchmark.ipynb | 100 ++++++++++++++++++++++++---
 src/config.h                         |   4 +-
 src/lns/solution/solution.cpp        |  15 ++--
 src/lns/solution/solution.h          |   4 +-
 src/mains/main.cpp                   |  12 ++--
 5 files changed, 110 insertions(+), 25 deletions(-)

diff --git a/python/visualisation_benchmark.ipynb b/python/visualisation_benchmark.ipynb
index 9647956..80065dd 100644
--- a/python/visualisation_benchmark.ipynb
+++ b/python/visualisation_benchmark.ipynb
@@ -2,7 +2,7 @@
  "cells": [
   {
    "cell_type": "code",
-   "execution_count": 12,
+   "execution_count": 28,
    "metadata": {},
    "outputs": [
     {
@@ -53,7 +53,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 13,
+   "execution_count": 29,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -65,9 +65,53 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 14,
+   "execution_count": 30,
    "metadata": {},
    "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "   Instance  Vehicles  Distance Reference       Date\n",
+      "0     lc101        10    828.94    Li&Lim       2001\n",
+      "1     lc102        10    828.94    Li&Lim       2001\n",
+      "2     lc103         9   1035.35       BVH  27-jun-03\n",
+      "3     lc201         3    591.56    Li&Lim       2001\n",
+      "4     lc202         3    591.56    Li&Lim       2001\n",
+      "5     lc203         3    591.17  SAM::OPT  11-mar-03\n",
+      "6     lr101        19   1650.80    Li&Lim       2001\n",
+      "7     lr102        17   1487.57    Li&Lim       2001\n",
+      "8     lr103        13   1292.68    Li&Lim       2001\n",
+      "9     lr201         4   1253.23  SAM::OPT  28-feb-03\n",
+      "10    lr202         3   1197.67    Li&Lim       2001\n",
+      "11    lr203         3    949.40    Li&Lim       2001\n",
+      "12   lrc101        14   1708.80    Li&Lim       2001\n",
+      "13   lrc102        12   1558.07  SAM::OPT  19-feb-03\n",
+      "14   lrc103        11   1258.74    Li&Lim       2001\n",
+      "15   lrc201         4   1406.94  SAM::OPT  28-feb-03\n",
+      "16   lrc202         3   1374.27    Li&Lim       2001\n",
+      "17   lrc203         3   1089.07    Li&Lim       2001\n",
+      "   Instance  Vehicles  Distance Reference        Date\n",
+      "0     lc101        10    828.94       ...  31-03-2025\n",
+      "1     lc102        10    828.94       ...  31-03-2025\n",
+      "2     lc103        10    827.87       ...  31-03-2025\n",
+      "3     lc201         3    591.56       ...  31-03-2025\n",
+      "4     lc202         3    591.56       ...  31-03-2025\n",
+      "5     lc203         3    591.18       ...  31-03-2025\n",
+      "6     lr101        19   1650.80       ...  31-03-2025\n",
+      "7     lr102        17   1495.52       ...  31-03-2025\n",
+      "8     lr103        13   1306.89       ...  31-03-2025\n",
+      "9     lr201         4   1267.46       ...  31-03-2025\n",
+      "10    lr202         4   1269.80       ...  31-03-2025\n",
+      "11    lr203         3    962.05       ...  31-03-2025\n",
+      "12   lrc101        14   1708.81       ...  31-03-2025\n",
+      "13   lrc102        13   1566.59       ...  31-03-2025\n",
+      "14   lrc103        12   1308.83       ...  31-03-2025\n",
+      "15   lrc201         5   1464.26       ...  31-03-2025\n",
+      "16   lrc202         4   1407.81       ...  31-03-2025\n",
+      "17   lrc203         4   1093.84       ...  31-03-2025\n"
+     ]
+    },
     {
      "name": "stderr",
      "output_type": "stream",
@@ -106,12 +150,18 @@
     "\n",
     "best_known_df = best_known_df[best_known_df['Instance'].isin(solutions_df['Instance'])]\n",
     "solutions_df.sort_values(by=[\"Instance\"], inplace=True)\n",
-    "best_known_df.sort_values(by=[\"Instance\"], inplace=True)\n"
+    "best_known_df.sort_values(by=[\"Instance\"], inplace=True)\n",
+    "\n",
+    "solutions_df.reset_index(drop=True, inplace=True)\n",
+    "best_known_df.reset_index(drop=True, inplace=True)\n",
+    "\n",
+    "print(best_known_df)\n",
+    "print(solutions_df)"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 15,
+   "execution_count": 31,
    "metadata": {},
    "outputs": [
     {
@@ -119,9 +169,11 @@
      "output_type": "stream",
      "text": [
       "Vehicle difference: 7\n",
-      "Mean Absolute Error (distance): 358.8829\n",
-      "Mean Relative Error (distance): 0.4845\n",
-      "Mean Approximation Ratio (distance): 1.0033\n"
+      "Mean Absolute Error (distance): 26.8283\n",
+      "Mean Relative Error (distance): 0.0231\n",
+      "Mean Approximation Ratio (distance): 1.0033\n",
+      "Percentage Error (vehicles): 4.86%\n",
+      "Percentage Error (distances): 0.33%\n"
      ]
     }
    ],
@@ -150,10 +202,40 @@
     "mr_vehicles = mean_vehicles_solution / mean_vehicles_best_known\n",
     "mr_distances = mean_distance_solution / mean_distance_best_known\n",
     "\n",
+    "# Percentage error is calculated as (MAE / Actual value) * 100\n",
+    "percentage_error_vehicles = ((mean_vehicles_solution - mean_vehicles_best_known) / mean_vehicles_best_known) * 100\n",
+    "percentage_error_distances = ((mean_distance_solution - mean_distance_best_known) / mean_distance_best_known) * 100\n",
+    "\n",
+    "\n",
     "print(f\"Vehicle difference: {sum_vehicles_solution - sum_vehicles_best_known}\")\n",
     "print(f\"Mean Absolute Error (distance): {mae_distances:.4f}\")\n",
     "print(f\"Mean Relative Error (distance): {mre_distances:.4f}\")\n",
-    "print(f\"Mean Approximation Ratio (distance): {mr_distances:.4f}\")"
+    "print(f\"Mean Approximation Ratio (distance): {mr_distances:.4f}\")\n",
+    "print(f\"Percentage Error (vehicles): {percentage_error_vehicles:.2f}%\")\n",
+    "print(f\"Percentage Error (distances): {percentage_error_distances:.2f}%\")"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "5000 iterations\n",
+    "- Vehicle difference: 7\n",
+    "- Mean Absolute Error (distance): 26.8283\n",
+    "- Mean Relative Error (distance): 0.0231\n",
+    "- Mean Approximation Ratio (distance): 1.0033\n",
+    "- Percentage Error (vehicles): 4.86%\n",
+    "- Percentage Error (distances): 0.33%\n",
+    "\n",
+    "10000 iterations\n",
+    "- Vehicle difference: 6\n",
+    "- Mean Absolute Error (distance): 21.3128\n",
+    "- Mean Relative Error (distance): 0.0188\n",
+    "- Mean Approximation Ratio (distance): 0.9985\n",
+    "- Percentage Error (vehicles): 4.17%\n",
+    "- Percentage Error (distances): -0.15%\n",
+    "\n",
+    "negative % error due to some solution having more routes but less travel distances\n"
    ]
   }
  ],
diff --git a/src/config.h b/src/config.h
index f41a5fb..3e55b46 100644
--- a/src/config.h
+++ b/src/config.h
@@ -12,7 +12,7 @@ int const ROUTE_PENALTY = 0;
 int const NUMBER_VEHICLE = 50;
 
 // Number of iterations for the algorithm or simulation to run.
-int const NUMBER_ITERATION = 100000;
+int const NUMBER_ITERATION = 10000;
 
 // Flags
 
@@ -33,4 +33,4 @@ bool const COMPLETE_STORE = true;
 
 // Directories
 
-std::string const OUTPUT_DIRECTORY = "./../../output/test2";
\ No newline at end of file
+std::string const OUTPUT_DIRECTORY = "./../../output/select2";
\ No newline at end of file
diff --git a/src/lns/solution/solution.cpp b/src/lns/solution/solution.cpp
index cb3f55b..fadddf8 100644
--- a/src/lns/solution/solution.cpp
+++ b/src/lns/solution/solution.cpp
@@ -124,18 +124,21 @@ Solution &Solution::operator=(Solution const &rhs)
     return *this;
 }
 
-Solution::Solution(Solution &&sol) noexcept : data(std::move(sol.data))
+Solution::Solution(Solution &&sol) noexcept : data(sol.data)
 {
     *this = std::move(sol);
 }
 
 Solution &Solution::operator=(Solution &&sol) noexcept
 {
-    if (this == &sol) return *this;
+    if (this == &sol)
+    {
+        return *this;
+    }
 
-    data = std::move(sol.data);
-    rawCost = std::move(sol.rawCost);
-    totalCost = std::move(sol.totalCost);
+    data = sol.data;
+    rawCost = sol.rawCost;
+    totalCost = sol.totalCost;
 
     pairBank = std::move(sol.pairBank);
     routes = std::move(sol.routes);
@@ -259,7 +262,7 @@ bool Solution::checkModification(AtomicRecreation const &modification) const
     return true;
 }
 
-void Solution::beforeApplyModification(AtomicModification &modification)
+void Solution::beforeApplyModification(AtomicModification &modification) const
 {
     // Pre-modification check
     check();
diff --git a/src/lns/solution/solution.h b/src/lns/solution/solution.h
index 364799b..62a2cf2 100644
--- a/src/lns/solution/solution.h
+++ b/src/lns/solution/solution.h
@@ -34,7 +34,7 @@ private:
 
 public:
     /*
-     * Creates an empty solution with all pairs in the pairBank and one empty route.
+     * Creates an empty solution with all pairs in the pairBank.
      */
     static Solution emptySolution(PDPTWData const &data);
 
@@ -137,7 +137,7 @@ public:
     /*
      * Pre-modification check. The modification must be valid.
      */
-    void beforeApplyModification(AtomicModification &modification);
+    void beforeApplyModification(AtomicModification &modification) const;
     /*
      * Updates constraints after modification is applied.
      */
diff --git a/src/mains/main.cpp b/src/mains/main.cpp
index 3a6d111..403ce58 100644
--- a/src/mains/main.cpp
+++ b/src/mains/main.cpp
@@ -116,16 +116,16 @@ int main(int argc, char **argv)
     ///////////////////////////////////////////////////////////////////////
 
     //std::string filepath = "/home/a24jacqb/Documents/Code/pdptw-main/data_in/n100/bar-n100-1.json";
-    std::string filepath = "/home/a24jacqb/Documents/Code/pdptw-main/data_in/pdp_100/lc103.json";
+    //std::string filepath = "/home/a24jacqb/Documents/Code/pdptw-main/data_in/pdp_100/lc106.json";
     //std::string filepath = "/home/a24jacqb/Documents/Code/pdptw-main/data_in/Nantes_1.json";
     //std::string filepath = "/home/a24jacqb/Documents/Code/pdptw-main/data_in/n5000/bar-n5000-1.json";
 
-    PDPTWData data = parsing::parseJson(filepath);
-    Solution startingSolution = Solution::emptySolution(data);
-    simpleLNS(data, startingSolution);
+    // PDPTWData data = parsing::parseJson(filepath);
+    // Solution startingSolution = Solution::emptySolution(data);
+    // simpleLNS(data, startingSolution);
 
-    // std::string path = "/home/a24jacqb/Documents/Code/pdptw-main/data_in/selection";
-    // runAllInDirectory(path, simpleLNS);
+    std::string path = "/home/a24jacqb/Documents/Code/pdptw-main/data_in/selection";
+    runAllInDirectory(path, simpleLNS);
 
 
 
-- 
GitLab