From 0377af8278206021772c1b17530848cce41dcf1e Mon Sep 17 00:00:00 2001
From: Romain BERNARD <romain.bernard@uca.fr>
Date: Wed, 19 Jun 2024 15:07:11 +0200
Subject: [PATCH] REFACTOR directly refer to insertion key points wherever
 possible to prevent any divergence in the kind of index expected by the
 function's implementation

---
 src/routes/vehicle/BestRequestInsertion.h     | 28 +++----
 src/routes/vehicle/SAEVRoute.cpp              | 81 +++++++++----------
 src/routes/vehicle/SAEVRoute.h                | 24 +++---
 .../propagation/SAEVRouteChangelist.cpp       | 10 +--
 .../vehicle/propagation/SAEVRouteChangelist.h | 25 +++---
 test/src/BestInsertionHeuristicDebug.cpp      | 16 ++--
 test/src/ConstraintPropagationDebug.cpp       | 18 ++---
 7 files changed, 95 insertions(+), 107 deletions(-)

diff --git a/src/routes/vehicle/BestRequestInsertion.h b/src/routes/vehicle/BestRequestInsertion.h
index 798b9cc..0a19ab7 100644
--- a/src/routes/vehicle/BestRequestInsertion.h
+++ b/src/routes/vehicle/BestRequestInsertion.h
@@ -13,8 +13,8 @@
 
 class BestRequestInsertion {
 private:
-    size_t _originInsertionIndex{std::numeric_limits<size_t>::max()};
-    size_t _destinationInsertionIndex{std::numeric_limits<size_t>::max()};
+    const SAEVKeyPoint* _originInsertionKP;
+    const SAEVKeyPoint* _destinationInsertionKP;
     double _score{ std::numeric_limits<double>::max() };
 
 public:
@@ -24,28 +24,28 @@ public:
     BestRequestInsertion() {};
     /**
      * Constructs a BestRequestInsertion object, containing Origin/Destination insertion indexes and the score associated
-     * @param originInsertionIndex Index of insertion for the origin of the request in the route
-     * @param destinationInsertionIndex Index of insertion for the destination of the request in the route
+     * @param originInsertionKP Index of insertion for the origin of the request in the route
+     * @param destinationInsertionKP Index of insertion for the destination of the request in the route
      * @param score
      */
-    BestRequestInsertion(size_t originInsertionIndex, size_t destinationInsertionIndex, double score)
-            : _originInsertionIndex(originInsertionIndex), _destinationInsertionIndex(destinationInsertionIndex),
+    BestRequestInsertion(const SAEVKeyPoint *originInsertionKP, const SAEVKeyPoint *destinationInsertionKP, double score)
+            : _originInsertionKP(originInsertionKP), _destinationInsertionKP(destinationInsertionKP),
               _score(score) {};
 
-    [[nodiscard]] size_t getOriginInsertionIndex() const {
-        return _originInsertionIndex;
+    [[nodiscard]] const SAEVKeyPoint *getOriginInsertionKp() const {
+        return _originInsertionKP;
     }
 
-    void setOriginInsertionIndex(size_t originInsertionIndex) {
-        BestRequestInsertion::_originInsertionIndex = originInsertionIndex;
+    void setOriginInsertionKp(SAEVKeyPoint *originInsertionKp) {
+        _originInsertionKP = originInsertionKp;
     }
 
-    [[nodiscard]] size_t getDestinationInsertionIndex() const {
-        return _destinationInsertionIndex;
+    [[nodiscard]] const SAEVKeyPoint *getDestinationInsertionKp() const {
+        return _destinationInsertionKP;
     }
 
-    void setDestinationInsertionIndex(size_t destinationInsertionIndex) {
-        BestRequestInsertion::_destinationInsertionIndex = destinationInsertionIndex;
+    void setDestinationInsertionKp(SAEVKeyPoint *destinationInsertionKp) {
+        _destinationInsertionKP = destinationInsertionKp;
     }
 
     [[nodiscard]] double getScore() const {
diff --git a/src/routes/vehicle/SAEVRoute.cpp b/src/routes/vehicle/SAEVRoute.cpp
index 6e815a0..dccb0a4 100644
--- a/src/routes/vehicle/SAEVRoute.cpp
+++ b/src/routes/vehicle/SAEVRoute.cpp
@@ -37,36 +37,34 @@ SAEVRoute::SAEVRoute(const Graph& graph, const std::vector<Request>& requestList
     }
 }
 
-void SAEVRoute::insertRequest(size_t requestId, size_t originRequestPredecessorIdx, size_t destinationRequestPredecessorIdx) {
+void SAEVRoute::insertRequest(size_t requestId, SAEVKeyPoint &originRequestPredecessorKP, SAEVKeyPoint &destinationRequestPredecessorKP) {
     SAEVKeyPoint& originKp = getOrigin(requestId);
     SAEVKeyPoint& destinationKp = getDestination(requestId);
 
-    SAEVKeyPoint& originPredKp = _route.at(originRequestPredecessorIdx);
-    SAEVKeyPoint *originSuccKp = originPredKp.getSuccessor();
-    SAEVKeyPoint& destinationPredKp = _route.at(destinationRequestPredecessorIdx);
-    SAEVKeyPoint *destinationSuccKp = destinationPredKp.getSuccessor();
+    SAEVKeyPoint *originSuccKp = originRequestPredecessorKP.getSuccessor();
+    SAEVKeyPoint *destinationSuccKp = destinationRequestPredecessorKP.getSuccessor();
 
-    if(originRequestPredecessorIdx != destinationRequestPredecessorIdx) {
+    if(originRequestPredecessorKP != destinationRequestPredecessorKP) {
         //Set values for O/D KPs
-        originKp.setPredecessor(&originPredKp);
+        originKp.setPredecessor(&originRequestPredecessorKP);
         originKp.setSuccessor(originSuccKp);
-        destinationKp.setPredecessor(&destinationPredKp);
+        destinationKp.setPredecessor(&destinationRequestPredecessorKP);
         destinationKp.setSuccessor(destinationSuccKp);
 
         //Set values for predecessors/successors
-        originPredKp.setSuccessor(&originKp);
+        originRequestPredecessorKP.setSuccessor(&originKp);
         originSuccKp->setPredecessor(&originKp);
-        destinationPredKp.setSuccessor(&destinationKp);
+        destinationRequestPredecessorKP.setSuccessor(&destinationKp);
         destinationSuccKp->setPredecessor(&destinationKp);
     } else {
         //Set values for O/D KPs
-        originKp.setPredecessor(&originPredKp);
+        originKp.setPredecessor(&originRequestPredecessorKP);
         originKp.setSuccessor(&destinationKp);
         destinationKp.setPredecessor(&originKp);
         destinationKp.setSuccessor(destinationSuccKp);
 
         //Set values for predecessors/successors
-        originPredKp.setSuccessor(&originKp);
+        originRequestPredecessorKP.setSuccessor(&originKp);
         originSuccKp->setPredecessor(&destinationKp);
     }
 }
@@ -99,30 +97,28 @@ void SAEVRoute::removeRequest(int requestId) {
 }
 
 SAEVRouteChangelist
-SAEVRoute::tryAddRequest(const size_t requestId, const size_t originRequestPredecessorIdx, const size_t destinationRequestPredecessorIdx) {
+SAEVRoute::tryAddRequest(const size_t requestId, SAEVKeyPoint &originRequestPredecessorKP, SAEVKeyPoint &destinationRequestPredecessorKP) {
     const Request* request = &_requestList->at(requestId);
-    SAEVKeyPoint const* originPredecessor = &_route.at(originRequestPredecessorIdx);
-    SAEVKeyPoint const* destinationPredecessor = &_route.at(destinationRequestPredecessorIdx);
-    SAEVKeyPoint const* destinationSuccessor = destinationPredecessor->getSuccessor();
+    SAEVKeyPoint const* destinationSuccessor = destinationRequestPredecessorKP.getSuccessor();
 
     //Check vehicle capacity
-    SAEVKeyPoint const* currentKP = originPredecessor;
+    SAEVKeyPoint const* currentKP = &originRequestPredecessorKP;
     do {
         if(currentKP->getCurrentOccupation() + request->getWeight() > SAEVehicle::getCapacity()) {
             DEBUG_MSG("WEIGHT VIOLATION : request weight = " + std::to_string(request->getWeight()) + " incompatible KP = " + currentKP->to_string());
-            return SAEVRouteChangelist(this, requestId, originRequestPredecessorIdx, destinationRequestPredecessorIdx);
+            return SAEVRouteChangelist(this, requestId, originRequestPredecessorKP, destinationRequestPredecessorKP);
         }
         currentKP = currentKP->getSuccessor();
     } while (currentKP != destinationSuccessor && currentKP != nullptr);
 
     //Do basic checks on neighbouring nodes from our Origin/Destination insertion points
-    bool isValid = doNeighbouringTWChecks(requestId, request->getOriginNodeIndex(), request->getDestinationNodeIndex(), originPredecessor, destinationPredecessor);
+    bool isValid = doNeighbouringTWChecks(requestId, request->getOriginNodeIndex(), request->getDestinationNodeIndex(), &originRequestPredecessorKP, &destinationRequestPredecessorKP);
 
     if(isValid) {
-        return insertRequestWithPropagation(requestId, originRequestPredecessorIdx, destinationRequestPredecessorIdx);
+        return insertRequestWithPropagation(requestId, originRequestPredecessorKP, destinationRequestPredecessorKP);
     } else {
         DEBUG_MSG("TW VIOLATION on neighbour KPs");
-        return SAEVRouteChangelist(this, requestId, originRequestPredecessorIdx, destinationRequestPredecessorIdx);
+        return SAEVRouteChangelist(this, requestId, originRequestPredecessorKP, destinationRequestPredecessorKP);
     }
 }
 
@@ -173,12 +169,12 @@ SAEVRoute::doNeighbouringTWChecks(const size_t requestId, const size_t originNod
     return true;
 }
 
-SAEVRouteChangelist SAEVRoute::insertRequestWithPropagation(const size_t requestId, const size_t originRequestPredecessorIdx,
-                                                            const size_t destinationRequestPredecessorIdx) {
+SAEVRouteChangelist SAEVRoute::insertRequestWithPropagation(const size_t requestId, SAEVKeyPoint &originRequestPredecessorKP,
+                                                            SAEVKeyPoint &destinationRequestPredecessorKP) {
     //Init changelist
-    SAEVRouteChangelist changelist{this, requestId, originRequestPredecessorIdx, destinationRequestPredecessorIdx};
+    SAEVRouteChangelist changelist{this, requestId, originRequestPredecessorKP, destinationRequestPredecessorKP};
     //Properly insert the request to facilitate constraint propagation
-    insertRequest(requestId, originRequestPredecessorIdx, destinationRequestPredecessorIdx);
+    insertRequest(requestId, originRequestPredecessorKP, destinationRequestPredecessorKP);
 
     //Initialize bound propagation signal queue (each item signals a modification done on one of a KeyPoint
     std::queue<std::pair<Bound, SAEVKeyPoint *>> boundPropagationQueue{};
@@ -277,36 +273,35 @@ SAEVRouteChangelist SAEVRoute::insertRequestWithPropagation(const size_t request
         }
     }
 
-    changelist.setScore(getDetourScore(requestId, originRequestPredecessorIdx, destinationRequestPredecessorIdx));
+    changelist.setScore(getDetourScore(requestId, originRequestPredecessorKP, destinationRequestPredecessorKP));
     return changelist;
 }
 
-double SAEVRoute::getDetourScore(const size_t requestId, const size_t originRequestPredecessorIdx,
-                                 const size_t destinationRequestPredecessorIdx) {
+double SAEVRoute::getDetourScore(const size_t requestId, const SAEVKeyPoint &originRequestPredecessorKP,
+                                 const SAEVKeyPoint &destinationRequestPredecessorKP) {
     double score;
     const SAEVKeyPoint& originKP = getOrigin(requestId);
     const SAEVKeyPoint& destinationKP = getDestination(requestId);
-    const SAEVKeyPoint& originPredKP = _route.at(originRequestPredecessorIdx);
-    const SAEVKeyPoint* originSuccKP = originPredKP.getSuccessor();
+    const SAEVKeyPoint* originSuccKP = originRequestPredecessorKP.getSuccessor();
+    const SAEVKeyPoint* destinationSuccKP = destinationRequestPredecessorKP.getSuccessor();
 
-    if(originRequestPredecessorIdx != destinationRequestPredecessorIdx) {
-        const SAEVKeyPoint* destinationPredKP = destinationKP.getPredecessor();
-        const SAEVKeyPoint* destinationSuccKP = destinationKP.getSuccessor();
+    if(originRequestPredecessorKP != destinationRequestPredecessorKP) {
+        const SAEVKeyPoint* destinationPredKP = &destinationRequestPredecessorKP;
 
         //Origin Detour
-        score = _graph->getShortestSAEVPath(originPredKP.getNodeIndex(), originKP.getNodeIndex()) //T(Pred(O), D)
+        score = _graph->getShortestSAEVPath(originRequestPredecessorKP.getNodeIndex(), originKP.getNodeIndex()) //T(Pred(O), D)
                 + _graph->getShortestSAEVPath(originKP.getNodeIndex(), originSuccKP->getNodeIndex()) //T(O, Succ(D))
-                - _graph->getShortestSAEVPath(originPredKP.getNodeIndex(), originSuccKP->getNodeIndex()); //T(Pred(O), Succ(O))
+                - _graph->getShortestSAEVPath(originRequestPredecessorKP.getNodeIndex(), originSuccKP->getNodeIndex()); //T(Pred(O), Succ(O))
 
         //Destination Detour
         score += _graph->getShortestSAEVPath(destinationPredKP->getNodeIndex(), destinationKP.getNodeIndex()) //T(Pred(D), D))
                 + _graph->getShortestSAEVPath(destinationKP.getNodeIndex(), destinationSuccKP->getNodeIndex()) //T(D, Succ(D)))
                 - _graph->getShortestSAEVPath(destinationPredKP->getNodeIndex(), destinationSuccKP->getNodeIndex()); //T(Pred(D), Succ(D)))
     } else {
-        score = _graph->getShortestSAEVPath(originPredKP.getNodeIndex(), originKP.getNodeIndex()) //T(Pred(O), O)
+        score = _graph->getShortestSAEVPath(originRequestPredecessorKP.getNodeIndex(), originKP.getNodeIndex()) //T(Pred(O), O)
                 + _graph->getShortestSAEVPath(originKP.getNodeIndex(), destinationKP.getNodeIndex()) //T(O, D)
-                + _graph->getShortestSAEVPath(destinationKP.getNodeIndex(), originSuccKP->getNodeIndex()) //T(D, Succ(D))
-                - _graph->getShortestSAEVPath(originPredKP.getNodeIndex(), originSuccKP->getNodeIndex()); //T(Pred(O), Succ(D))
+                + _graph->getShortestSAEVPath(destinationKP.getNodeIndex(), destinationSuccKP->getNodeIndex()) //T(D, Succ(D))
+                - _graph->getShortestSAEVPath(originRequestPredecessorKP.getNodeIndex(), destinationSuccKP->getNodeIndex()); //T(Pred(O), Succ(D))
     }
     return score;
 }
@@ -359,7 +354,7 @@ bool SAEVRoute::checkRouteTimeWindows(size_t vehicleId) {
 }
 
 void SAEVRoute::finalizeRequestInsertion(const size_t requestId) {
-    SAEVKeyPoint * currentKeyPoint = &_route.at(getRequestOriginIdx(requestId));
+    SAEVKeyPoint * currentKeyPoint = &getOrigin(requestId);
     SAEVKeyPoint const * counterpartKP = currentKeyPoint->getCounterpart();
     int requestWeight = counterpartKP->getRequest()->getWeight();
     //Init weight value for Origin KP
@@ -383,18 +378,14 @@ BestInsertionQueue SAEVRoute::getBestInsertionsQueue(size_t requestId, size_t ve
 
     //Init variables used during iteration
     double score;
-    size_t originNodeIndex;
-    size_t destinationNodeIndex;
     SAEVKeyPoint const* originKeyPoint = &getOriginDepot(vehicleId);
     SAEVKeyPoint const* destinationKeyPoint = originKeyPoint;
 
     //iterate over possible origin/destination pairs for the given vehicle
     while(originKeyPoint->getSuccessor() != nullptr) {
-        originNodeIndex = originKeyPoint->getNodeIndex();
         while(destinationKeyPoint->getSuccessor() != nullptr) {
-            destinationNodeIndex = destinationKeyPoint->getNodeIndex();
-            score = getDetourScore(requestId, originNodeIndex, destinationNodeIndex);
-            bestInsertionQueue.emplace(originNodeIndex, destinationNodeIndex,score);
+            score = getDetourScore(requestId, *originKeyPoint, *destinationKeyPoint);
+            bestInsertionQueue.emplace(originKeyPoint, destinationKeyPoint, score);
             destinationKeyPoint = destinationKeyPoint->getSuccessor();
         }
 
diff --git a/src/routes/vehicle/SAEVRoute.h b/src/routes/vehicle/SAEVRoute.h
index 89714e9..d9ebee9 100644
--- a/src/routes/vehicle/SAEVRoute.h
+++ b/src/routes/vehicle/SAEVRoute.h
@@ -35,10 +35,10 @@ public:
     /**
      * Raw request route insertion method. Public for debug purposes, but should effectively never be called by an outside member
      * @param requestId index of the request we want to insert in the route
-     * @param originRequestPredecessorIdx Identifier/index in the route key point vector for the request origin or destination that will precede the origin of the request we want to insert
-     * @param destinationRequestPredecessorIdx Identifier/index in the route key point vector for the request origin or destination that will precede the destination of the request we want to insert
+     * @param originRequestPredecessorKP Identifier/index in the route key point vector for the request origin or destination that will precede the origin of the request we want to insert
+     * @param destinationRequestPredecessorKP Identifier/index in the route key point vector for the request origin or destination that will precede the destination of the request we want to insert
      */
-    void insertRequest(size_t requestId, size_t originRequestPredecessorIdx, size_t destinationRequestPredecessorIdx);
+    void insertRequest(size_t requestId, SAEVKeyPoint &originRequestPredecessorKP, SAEVKeyPoint &destinationRequestPredecessorKP);
 
     /**
      * Raw request removal method. Public for debug purposes, but should effectively never be called by an outside member
@@ -52,11 +52,11 @@ public:
      * Then we propagate our min/max bounds, iteratively rippling through every modification induced by min/max neighbour constraints or delta constraints. \n
      * ⚠️ In case of infeasibility, tryAdd automatically reverts changes and the change list will be effectively empty, but otherwise it's the caller's responsibility to revert changes if necessary
      * @param requestId Identifier/index in the instance's request vector for the request we wish to insert
-     * @param originRequestPredecessorIdx Identifier/index in the route key point vector for the request origin or destination that will precede our request's origin in the route
-     * @param destinationRequestPredecessorIdx Identifier/index in the route key point vector for the request origin or destination that will precede our request's destination in the route
+     * @param originRequestPredecessorKP Identifier/index in the route key point vector for the request origin or destination that will precede our request's origin in the route
+     * @param destinationRequestPredecessorKP Identifier/index in the route key point vector for the request origin or destination that will precede our request's destination in the route
      * @return A change list with every min/max bound change made during the tryAdd procedure and a score estimating insertion quality (lower is better)
      */
-    SAEVRouteChangelist tryAddRequest(const size_t requestId, const size_t originRequestPredecessorIdx, const size_t destinationRequestPredecessorIdx);
+    SAEVRouteChangelist tryAddRequest(const size_t requestId, SAEVKeyPoint &originRequestPredecessorKP, SAEVKeyPoint &destinationRequestPredecessorKP);
 
     /**
      * Call this function whenever a request insertion is considered final (Insertion success + satisfied with result)
@@ -88,21 +88,21 @@ public:
      * If the bounds become infeasible (min > max), then the propagation stops with a changelist with score= +Infinity and changes will be immediately reverted.
      * Otherwise, it's the responsibility of this method's callers to revert changes if wanted (or to defer this responsibility to its caller)
      * @param requestId Identifier/index in the instance's request vector for the request we wish to insert
-     * @param originRequestPredecessorIdx Identifier/index in the route key point vector for the request origin or destination that will precede our request's origin in the route
-     * @param destinationRequestPredecessorIdx Identifier/index in the route key point vector for the request origin or destination that will precede our request's destination in the route
+     * @param originRequestPredecessorKP Identifier/index in the route key point vector for the request origin or destination that will precede our request's origin in the route
+     * @param destinationRequestPredecessorKP Identifier/index in the route key point vector for the request origin or destination that will precede our request's destination in the route
      * @return A change list with every min/max bound change made during the insert procedure and a score estimating insertion quality (lower is better)
      */
-    SAEVRouteChangelist insertRequestWithPropagation(const size_t requestId, const size_t originRequestPredecessorIdx, const size_t destinationRequestPredecessorIdx);
+    SAEVRouteChangelist insertRequestWithPropagation(const size_t requestId, SAEVKeyPoint &originRequestPredecessorKP, SAEVKeyPoint &destinationRequestPredecessorKP);
 
     /**
      * Returns a score value equivalent to the detour implied by insertion of a request after the two given key point indexes.
      * The specific case of origin/destination being inserted one after another is taken into account
      * @param requestId Identifier/index in the instance's request vector for the request we wish to insert
-     * @param originRequestPredecessorIdx Identifier/index in the route key point vector for the request origin or destination that will precede our request's origin in the route
-     * @param destinationRequestPredecessorIdx Identifier/index in the route key point vector for the request origin or destination that will precede our request's destination in the route
+     * @param originRequestPredecessorKP Identifier/index in the route key point vector for the request origin or destination that will precede our request's origin in the route
+     * @param destinationRequestPredecessorKP Identifier/index in the route key point vector for the request origin or destination that will precede our request's destination in the route
      * @return
      */
-    double getDetourScore(const size_t requestId, const size_t originRequestPredecessorIdx, const size_t destinationRequestPredecessorIdx);
+    double getDetourScore(const size_t requestId, const SAEVKeyPoint &originRequestPredecessorKP, const SAEVKeyPoint &destinationRequestPredecessorKP);
 
     BestInsertionQueue getBestInsertionsQueue(size_t requestId, size_t vehicleId);
 
diff --git a/src/routes/vehicle/propagation/SAEVRouteChangelist.cpp b/src/routes/vehicle/propagation/SAEVRouteChangelist.cpp
index a2535b6..07ee842 100644
--- a/src/routes/vehicle/propagation/SAEVRouteChangelist.cpp
+++ b/src/routes/vehicle/propagation/SAEVRouteChangelist.cpp
@@ -21,7 +21,7 @@ void SAEVRouteChangelist::emplace_back(SAEVKeyPoint &kp, Bound bound, int value)
 }
 
 void SAEVRouteChangelist::applyChanges() const {
-    _routePtr->insertRequest(_requestId, _originPredecessorIdx, _destinationPredecessorIdx);
+    _routePtr->insertRequest(_requestId, _originPredecessorKP, _destinationPredecessorKP);
     for(SAEVRouteChange change : _changelist) {
         change.applyChange();
     }
@@ -40,12 +40,12 @@ size_t SAEVRouteChangelist::getRequestId() const {
     return _requestId;
 }
 
-int SAEVRouteChangelist::getOriginPredecessorIdx() const {
-    return _originPredecessorIdx;
+const SAEVKeyPoint &SAEVRouteChangelist::getOriginPredecessorKP() const {
+    return _originPredecessorKP;
 }
 
-int SAEVRouteChangelist::getDestinationPredecessorIdx() const {
-    return _destinationPredecessorIdx;
+const SAEVKeyPoint &SAEVRouteChangelist::getDestinationPredecessorKP() const {
+    return _destinationPredecessorKP;
 }
 
 double SAEVRouteChangelist::getScore() const {
diff --git a/src/routes/vehicle/propagation/SAEVRouteChangelist.h b/src/routes/vehicle/propagation/SAEVRouteChangelist.h
index 6db14fb..f15912a 100644
--- a/src/routes/vehicle/propagation/SAEVRouteChangelist.h
+++ b/src/routes/vehicle/propagation/SAEVRouteChangelist.h
@@ -28,8 +28,8 @@ public:
 private:
     SAEVRoute * const _routePtr;
     const size_t _requestId;
-    const size_t _originPredecessorIdx;
-    const size_t _destinationPredecessorIdx;
+    SAEVKeyPoint& _originPredecessorKP;
+    SAEVKeyPoint& _destinationPredecessorKP;
     std::vector<SAEVRouteChange> _changelist{};
     double _score{std::numeric_limits<double>::infinity()}; //Init score to infinity
 
@@ -38,11 +38,11 @@ public:
      * Initializes a change list to memorize every iterative modification made during constraint propagation
      * @param routePtr a pointer to the route the constraint propagation was applied on. revert/apply operations will be done on this route
      * @param requestId The index of the request in the global request list
-     * @param originPredecessorIdx The index of the request our origin will be inserted after
-     * @param destinationPredecessorIdx The index of the request our destination will be inserted after
+     * @param originPredecessorKP The index of the request our origin will be inserted after
+     * @param destinationPredecessorKP The index of the request our destination will be inserted after
      */
-    explicit SAEVRouteChangelist(SAEVRoute * const routePtr, const size_t requestId, const size_t originPredecessorIdx, const size_t destinationPredecessorIdx)
-    : _routePtr(routePtr), _requestId(requestId), _originPredecessorIdx(originPredecessorIdx), _destinationPredecessorIdx(destinationPredecessorIdx) {};
+    explicit SAEVRouteChangelist(SAEVRoute * const routePtr, const size_t requestId, SAEVKeyPoint &originPredecessorKP, SAEVKeyPoint &destinationPredecessorKP)
+    : _routePtr(routePtr), _requestId(requestId), _originPredecessorKP(originPredecessorKP), _destinationPredecessorKP(destinationPredecessorKP) {};
 
     /**
      * @return A pointer to the route this change list applies/reverts changes to
@@ -54,14 +54,11 @@ public:
      * @return The index of the request that we want to insert to a route
      */
     [[nodiscard]] size_t getRequestId() const;
-    /**
-     * @return The index of the request our origin will be inserted after
-     */
-    [[nodiscard]] size_t getOriginPredecessorIdx() const;
-    /**
-     * @return The index of the request our destination will be inserted after
-     */
-    [[nodiscard]] size_t getDestinationPredecessorIdx() const;
+
+    [[nodiscard]] const SAEVKeyPoint &getOriginPredecessorKP() const;
+
+    [[nodiscard]] const SAEVKeyPoint &getDestinationPredecessorKP() const;
+
     /**
      * @return A score value associated with this changelist. A lower score is better
      */
diff --git a/test/src/BestInsertionHeuristicDebug.cpp b/test/src/BestInsertionHeuristicDebug.cpp
index 9d000e2..4e20b2d 100644
--- a/test/src/BestInsertionHeuristicDebug.cpp
+++ b/test/src/BestInsertionHeuristicDebug.cpp
@@ -26,11 +26,11 @@ TEST(BestInsertionHeuristicDebug, DebugBaseInstance) {
     std::cout << "------------------Fin parsing instance et route-------------------" << std::endl << std::endl;
     int vehicleId = 1;
     assert(routesContainer.checkRouteTimeWindows(vehicleId));
-    SAEVRouteChangelist req0Changelist = routesContainer.tryAddRequest(0, routesContainer.getOriginDepotIdx(vehicleId), routesContainer.getOriginDepotIdx(1));
+    SAEVRouteChangelist req0Changelist = routesContainer.tryAddRequest(0, routesContainer.getOriginDepot(vehicleId), routesContainer.getOriginDepot(1));
     std::cout << routesContainer.to_string(vehicleId) << std::endl;
     assert(routesContainer.checkRouteTimeWindows(vehicleId));
     std::cout << "------------------------------------------------------------------" << std::endl;
-    SAEVRouteChangelist req1Changelist = routesContainer.tryAddRequest(1, routesContainer.getOriginDepotIdx(vehicleId), routesContainer.getRequestDestinationIdx(0));
+    SAEVRouteChangelist req1Changelist = routesContainer.tryAddRequest(1, routesContainer.getOriginDepot(vehicleId), routesContainer.getDestination(0));
     std::cout << routesContainer.to_string(vehicleId) << std::endl << std::endl;
     assert(!routesContainer.checkRouteTimeWindows(vehicleId));
     std::cout << "------------------------------------------------------------------" << std::endl;
@@ -58,20 +58,20 @@ TEST(BestInsertionHeuristicDebug, DebugInstanceAlain) {
 
     //Vehicle 1 insertions
     BestInsertionQueue biQueue = routesContainer.getBestInsertionsQueue(0,0);
-    routesContainer.tryAddRequest(0,routesContainer.getOriginDepotIdx(0),routesContainer.getOriginDepotIdx(0));
+    routesContainer.tryAddRequest(0,routesContainer.getOriginDepot(0),routesContainer.getOriginDepot(0));
     biQueue = routesContainer.getBestInsertionsQueue(1,0);
-    routesContainer.tryAddRequest(1,routesContainer.getRequestOriginIdx(0),routesContainer.getRequestOriginIdx(0));
+    routesContainer.tryAddRequest(1,routesContainer.getOrigin(0),routesContainer.getOrigin(0));
     biQueue = routesContainer.getBestInsertionsQueue(2,0);
-    SAEVRouteChangelist cl = routesContainer.tryAddRequest(2,routesContainer.getRequestOriginIdx(1),routesContainer.getRequestDestinationIdx(1));
+    SAEVRouteChangelist cl = routesContainer.tryAddRequest(2,routesContainer.getOrigin(1),routesContainer.getDestination(1));
     biQueue = routesContainer.getBestInsertionsQueue(3,0);
 
     //Vehicle 2 insertions
     biQueue = routesContainer.getBestInsertionsQueue(5,1);
-    routesContainer.tryAddRequest(5,routesContainer.getOriginDepotIdx(1),routesContainer.getOriginDepotIdx(1));
+    routesContainer.tryAddRequest(5,routesContainer.getOriginDepot(1),routesContainer.getOriginDepot(1));
     biQueue = routesContainer.getBestInsertionsQueue(4,1);
-    routesContainer.tryAddRequest(4,routesContainer.getOriginDepotIdx(1),routesContainer.getRequestDestinationIdx(5));
+    routesContainer.tryAddRequest(4,routesContainer.getOriginDepot(1),routesContainer.getDestination(5));
     biQueue = routesContainer.getBestInsertionsQueue(3,1);
-    routesContainer.tryAddRequest(3,routesContainer.getOriginDepotIdx(1),routesContainer.getRequestOriginIdx(4));
+    routesContainer.tryAddRequest(3,routesContainer.getOriginDepot(1),routesContainer.getOrigin(4));
     biQueue = routesContainer.getBestInsertionsQueue(0,1);
     biQueue = routesContainer.getBestInsertionsQueue(1,1);
     biQueue = routesContainer.getBestInsertionsQueue(2,1);
diff --git a/test/src/ConstraintPropagationDebug.cpp b/test/src/ConstraintPropagationDebug.cpp
index 1c159f5..dd68aad 100644
--- a/test/src/ConstraintPropagationDebug.cpp
+++ b/test/src/ConstraintPropagationDebug.cpp
@@ -27,11 +27,11 @@ TEST(ConstraintPropagationDebug, DebugBaseInstance) {
     std::cout << "------------------Fin parsing instance et route-------------------" << std::endl << std::endl;
     int vehicleId = 1;
     assert(routesContainer.checkRouteTimeWindows(vehicleId));
-    SAEVRouteChangelist req0Changelist = routesContainer.tryAddRequest(0, routesContainer.getOriginDepotIdx(vehicleId), routesContainer.getOriginDepotIdx(1));
+    SAEVRouteChangelist req0Changelist = routesContainer.tryAddRequest(0, routesContainer.getOriginDepot(vehicleId), routesContainer.getOriginDepot(1));
     std::cout << routesContainer.to_string(vehicleId) << std::endl;
     assert(routesContainer.checkRouteTimeWindows(vehicleId));
     std::cout << "------------------------------------------------------------------" << std::endl;
-    SAEVRouteChangelist req1Changelist = routesContainer.tryAddRequest(1, routesContainer.getOriginDepotIdx(vehicleId), routesContainer.getRequestDestinationIdx(0));
+    SAEVRouteChangelist req1Changelist = routesContainer.tryAddRequest(1, routesContainer.getOriginDepot(vehicleId), routesContainer.getDestination(0));
     std::cout << routesContainer.to_string(vehicleId) << std::endl << std::endl;
     assert(!routesContainer.checkRouteTimeWindows(vehicleId));
     std::cout << "------------------------------------------------------------------" << std::endl;
@@ -67,7 +67,7 @@ TEST(ConstraintPropagationDebug, DebugRequestGeneration) {
 TEST(ConstraintPropagationDebug, DebugInstanceAlain) {
     std::string instancesPath = "../../resources/test/instances/Constraint Propagation/";
     std::string instanceFolder = "Instance_Alain_140624/";
-    std::string graphDatFile = "graph.dat";
+    std::string graphDatFile = "graph2.dat";
     std::string requestsDatFile = "requests.dat";
 
     //Parse graph
@@ -79,14 +79,14 @@ TEST(ConstraintPropagationDebug, DebugInstanceAlain) {
     SAEVRoute routesContainer(graphFromSingleFile, requests);
 
     //Vehicle 1 insertions
-    routesContainer.tryAddRequest(0,routesContainer.getOriginDepotIdx(0),routesContainer.getOriginDepotIdx(0));
-    routesContainer.tryAddRequest(1,routesContainer.getRequestOriginIdx(0),routesContainer.getRequestOriginIdx(0));
-    routesContainer.tryAddRequest(2,routesContainer.getRequestOriginIdx(1),routesContainer.getRequestDestinationIdx(0));
+    routesContainer.tryAddRequest(0,routesContainer.getOriginDepot(0),routesContainer.getOriginDepot(0));
+    routesContainer.tryAddRequest(1,routesContainer.getOrigin(0),routesContainer.getOrigin(0));
+    SAEVRouteChangelist cl = routesContainer.tryAddRequest(2,routesContainer.getOrigin(1),routesContainer.getDestination(1));
 
     //Vehicle 2 insertions
-    routesContainer.tryAddRequest(5,routesContainer.getOriginDepotIdx(1),routesContainer.getOriginDepotIdx(1));
-    routesContainer.tryAddRequest(4,routesContainer.getOriginDepotIdx(1),routesContainer.getRequestDestinationIdx(5));
-    routesContainer.tryAddRequest(3,routesContainer.getOriginDepotIdx(1),routesContainer.getRequestOriginIdx(4));
+    routesContainer.tryAddRequest(5,routesContainer.getOriginDepot(1),routesContainer.getOriginDepot(1));
+    routesContainer.tryAddRequest(4,routesContainer.getOriginDepot(1),routesContainer.getDestination(5));
+    routesContainer.tryAddRequest(3,routesContainer.getOriginDepot(1),routesContainer.getOrigin(4));
 }
 
 }
-- 
GitLab