From 4b30bfec5b360379c5549632464e0568b42986b6 Mon Sep 17 00:00:00 2001
From: awenjb <126257927+awenjb@users.noreply.github.com>
Date: Thu, 27 Mar 2025 14:49:00 +0100
Subject: [PATCH] Add Route Penalty

---
 julia/txt_to_json.jl          |  2 +-
 src/config.h                  |  4 +++-
 src/lns/solution/solution.cpp | 16 +++++++++++++++-
 src/lns/solution/solution.h   |  1 +
 src/mains/main.cpp            |  4 ++--
 5 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/julia/txt_to_json.jl b/julia/txt_to_json.jl
index 30cc9ba..f50b001 100644
--- a/julia/txt_to_json.jl
+++ b/julia/txt_to_json.jl
@@ -188,7 +188,7 @@ end
 
 
 function euclidean_distance(x1, y1, x2, y2)
-    return round(sqrt((x2 - x1)^2 + (y2 - y1)^2), digits=2)
+    return sqrt((x2 - x1)^2 + (y2 - y1)^2)
 end
 
 
diff --git a/src/config.h b/src/config.h
index 967603c..444c3d0 100644
--- a/src/config.h
+++ b/src/config.h
@@ -1,4 +1,6 @@
-const int EXCLUSION_PENALTY = 100;
+const int EXCLUSION_PENALTY = 1000000;
+
+const int ROUTE_PENALTY = 1000;
 
 const int RANDOM_SEED = 100;
 
diff --git a/src/lns/solution/solution.cpp b/src/lns/solution/solution.cpp
index 0a975ed..2c540f1 100644
--- a/src/lns/solution/solution.cpp
+++ b/src/lns/solution/solution.cpp
@@ -61,9 +61,23 @@ double Solution::computeSolutionCost() const
 
 double Solution::computePenalisation() const
 {
-    return getBank().size() * EXCLUSION_PENALTY;
+    return getBank().size() * EXCLUSION_PENALTY + getNumberOfRoutes() * ROUTE_PENALTY;
 }
 
+int Solution::getNumberOfRoutes() const 
+{
+    int cpt = 0;
+    for (Route const &route : getRoutes())
+    {
+        if (!(route.getRoute().empty()))
+        {
+            cpt++;
+        }
+    }
+    return cpt;
+}
+
+
 void Solution::init()
 {
     initPairBank();
diff --git a/src/lns/solution/solution.h b/src/lns/solution/solution.h
index 4ad16c4..3de416b 100644
--- a/src/lns/solution/solution.h
+++ b/src/lns/solution/solution.h
@@ -76,6 +76,7 @@ public:
     PDPTWData const &getData() const;
     double getRawCost() const;
     double getCost() const;
+    int getNumberOfRoutes() const;
     unsigned int missingPairCount() const;
     std::vector<std::unique_ptr<Constraint>> const &getConstraints() const;
 
diff --git a/src/mains/main.cpp b/src/mains/main.cpp
index 1b4227b..4a7e564 100644
--- a/src/mains/main.cpp
+++ b/src/mains/main.cpp
@@ -86,8 +86,8 @@ 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/lc102.json";
+    //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/lc101.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";
 
-- 
GitLab