From aaf8e73badbe4b03afb1148d3cbdad1b7fb240f3 Mon Sep 17 00:00:00 2001
From: Romain BERNARD <romain.bernard@uca.fr>
Date: Wed, 10 Jul 2024 14:42:57 +0200
Subject: [PATCH] use size_t/uint where appropriate

---
 src/instance/graph/Graph.h          | 28 ++++++++++-----------
 src/instance/requests/Request.cpp   | 32 ++++++++++++------------
 src/instance/requests/Request.h     | 38 ++++++++++++++---------------
 src/routes/vehicle/SAEVKeyPoint.cpp |  8 +++---
 src/routes/vehicle/SAEVKeyPoint.h   | 12 ++++-----
 5 files changed, 58 insertions(+), 60 deletions(-)

diff --git a/src/instance/graph/Graph.h b/src/instance/graph/Graph.h
index 389b8e5..2843207 100644
--- a/src/instance/graph/Graph.h
+++ b/src/instance/graph/Graph.h
@@ -40,20 +40,20 @@ public:
         return nodesVector;
     }
 
-    [[nodiscard]] const Node &getNode(int nodeIndex) const {
-        return nodesVector.at(nodeIndex);
+    [[nodiscard]] const Node &getNode(size_t nodeIndex) const {
+        return nodesVector[nodeIndex];
     }
 
     [[nodiscard]] size_t getNbNodes() const {
         return nodesVector.size();
     }
 
-    [[nodiscard]] std::vector<LineStop> getPTLinesSet(int nodeIndex) const {
-        return nodesVector.at(nodeIndex).getPTLinesSet();
+    [[nodiscard]] std::vector<LineStop> getPTLinesSet(size_t nodeIndex) const {
+        return nodesVector[nodeIndex].getPTLinesSet();
     }
 
-    [[nodiscard]] size_t getNbPTLines(int nodeIndex) const {
-        return nodesVector.at(nodeIndex).getPTLinesSet().size();
+    [[nodiscard]] size_t getNbPTLines(size_t nodeIndex) const {
+        return nodesVector[nodeIndex].getPTLinesSet().size();
     }
 
     [[nodiscard]] int getDepotNodeIdx() const;
@@ -66,17 +66,17 @@ public:
         return edgesVector;
     }
 
-    [[nodiscard]] size_t getNbIncomingEdges(int nodeIndex) const {
-        return nodesVector.at(nodeIndex).getIncomingEdges().size();
+    [[nodiscard]] size_t getNbIncomingEdges(size_t nodeIndex) const {
+        return nodesVector[nodeIndex].getIncomingEdges().size();
     }
 
-    [[nodiscard]] size_t getNbOutgoingEdges(int nodeIndex) const {
-        return nodesVector.at(nodeIndex).getOutgoingEdges().size();
+    [[nodiscard]] size_t getNbOutgoingEdges(size_t nodeIndex) const {
+        return nodesVector[nodeIndex].getOutgoingEdges().size();
     }
 
 
-    [[nodiscard]] size_t getNbEdges(int nodeIndex) const {
-        return nodesVector.at(nodeIndex).getIncomingEdges().size() + nodesVector.at(nodeIndex).getOutgoingEdges().size();
+    [[nodiscard]] size_t getNbEdges(size_t nodeIndex) const {
+        return nodesVector[nodeIndex].getIncomingEdges().size() + nodesVector[nodeIndex].getOutgoingEdges().size();
     }
 
     /**
@@ -148,9 +148,9 @@ public:
      * @param edgeEndNodeIndex Index of the node serving as an exit point for this edge
      * @param length The length of this edge (in minutes)
      */
-    void createAndAddEdge(int edgeStartNodeIndex, int edgeEndNodeIndex, double length);
+    void createAndAddEdge(size_t edgeStartNodeIndex, size_t edgeEndNodeIndex, double length);
 
-    [[nodiscard]] int getShortestSAEVPath(int x, int y) const { return shortestSAEVPaths.at(x).at(y); }
+    [[nodiscard]] int getShortestSAEVPath(size_t x, size_t y) const { return shortestSAEVPaths[x][y]; }
 
     void parseDistanceMatrix(std::ifstream &infile, DATRow currentRow);
 };
diff --git a/src/instance/requests/Request.cpp b/src/instance/requests/Request.cpp
index 6de343d..02aaa80 100644
--- a/src/instance/requests/Request.cpp
+++ b/src/instance/requests/Request.cpp
@@ -6,19 +6,17 @@
 #include "Request.h"
 #include "../../services/DatFile/DATRow.h"
 
-Request::Request(const int departureNodeIndex, const int arrivalNodeIndex, const TimeWindow &arrivalTw,
-                 const int deltaTime, const int weight) : _originNodeIndex(departureNodeIndex),
-                                                          _destinationNodeIndex(arrivalNodeIndex), _arrivalTW(arrivalTw),
-                                                          _deltaTime(deltaTime), _weight(weight) {
-    _currentDeltaTime = deltaTime;
+Request::Request(const size_t departureNodeIndex, const size_t arrivalNodeIndex, const TimeWindow &arrivalTw,
+                 const uint deltaTime, const uint weight) : _originNodeIndex(departureNodeIndex),
+                                                            _destinationNodeIndex(arrivalNodeIndex), _arrivalTW(arrivalTw),
+                                                            _deltaTime(deltaTime), _currentDeltaTime(deltaTime), _weight(weight) {
     _departureTW = _arrivalTW - deltaTime;
 }
 
-Request::Request(const int departureNodeIndex, const int arrivalNodeIndex, const TimeWindow &arrivalTw,
-                 const int deltaTime, const int weight, const Graph& graph) :
+Request::Request(const size_t departureNodeIndex, const size_t arrivalNodeIndex, const TimeWindow &arrivalTw,
+                 const uint deltaTime, const uint weight, const Graph& graph) :
         _originNodeIndex(departureNodeIndex), _destinationNodeIndex(arrivalNodeIndex),
-        _arrivalTW(arrivalTw), _deltaTime(deltaTime), _weight(weight) {
-    _currentDeltaTime = deltaTime;
+        _arrivalTW(arrivalTw), _deltaTime(deltaTime), _currentDeltaTime(deltaTime), _weight(weight) {
     _departureTW.min = _arrivalTW.min - deltaTime;
     _departureTW.max = _arrivalTW.max - graph.getShortestSAEVPath(departureNodeIndex, arrivalNodeIndex);
 }
@@ -85,11 +83,11 @@ std::vector<Request> Request::getRequestsFromFile(const std::string& datFilePath
     return requests;
 }
 
-const int Request::getOriginNodeIndex() const {
+size_t Request::getOriginNodeIndex() const {
     return _originNodeIndex;
 }
 
-const int Request::getDestinationNodeIndex() const {
+size_t Request::getDestinationNodeIndex() const {
     return _destinationNodeIndex;
 }
 
@@ -97,11 +95,11 @@ const TimeWindow &Request::getArrivalTw() const {
     return _arrivalTW;
 }
 
-const int Request::getDeltaTime() const {
+int Request::getDeltaTime() const {
     return _deltaTime;
 }
 
-const int Request::getWeight() const {
+int Request::getWeight() const {
     return _weight;
 }
 
@@ -125,21 +123,21 @@ const TimeWindow &Request::getDepartureTw() const {
     return _departureTW;
 }
 
-const int &Request::getMinDepartureTw() const {
+uint Request::getMinDepartureTw() const {
     return _departureTW.min;
 }
 
 
-const int &Request::getMaxDepartureTw() const {
+uint Request::getMaxDepartureTw() const {
     return _departureTW.max;
 }
 
-const int &Request::getMinArrivalTw() const {
+uint Request::getMinArrivalTw() const {
     return _arrivalTW.min;
 }
 
 
-const int &Request::getMaxArrivalTw() const {
+uint Request::getMaxArrivalTw() const {
     return _arrivalTW.max;
 }
 
diff --git a/src/instance/requests/Request.h b/src/instance/requests/Request.h
index df95f2f..d24cf79 100644
--- a/src/instance/requests/Request.h
+++ b/src/instance/requests/Request.h
@@ -13,43 +13,43 @@
 class Request {
 private:
     //Request base members (const and initialized on _request creation)
-    int _originNodeIndex; //Starting point of the user _request //TODO (?) change this to a Node pointer eventually
-    int _destinationNodeIndex; //
+    size_t _originNodeIndex; //Starting point of the user _request //TODO (?) change this to a Node pointer eventually
+    size_t _destinationNodeIndex; //
     TimeWindow _arrivalTW; //[min,max] time window for arrival to the destination node
-    int _deltaTime; //Base delta time, aka the maximum total duration of the path to serve this _request
-    int _weight; //How much space the requests takes in the vehicle (defaults to 1)
+    uint _deltaTime; //Base delta time, aka the maximum total duration of the path to serve this _request
+    uint _weight; //How much space the requests takes in the vehicle (defaults to 1)
 
     //Request helpful members (used for constraint propagation and remember the current state of the _request)
-    int _currentDeltaTime; //deltaTime - currentRouteDuration
-    int _requestServiceStart;
-    int _requestServiceEnd;
+    uint _currentDeltaTime; //deltaTime - currentRouteDuration
+    uint _requestServiceStart;
+    uint _requestServiceEnd;
     RequestRoute _currentRoute{this};
     TimeWindow _departureTW; //For now, a virtual TW on departures, used for constraint propagation
 public:
-    Request(const int departureNodeIndex, const int arrivalNodeIndex,
-            const TimeWindow &arrivalTw, const int deltaTime, const int weight);
-    Request(const int departureNodeIndex, const int arrivalNodeIndex, const TimeWindow &arrivalTw,
-            const int deltaTime, const int weight, const Graph& graph);
+    Request(const size_t departureNodeIndex, const size_t arrivalNodeIndex,
+            const TimeWindow &arrivalTw, const uint deltaTime, const uint weight);
+    Request(const size_t departureNodeIndex, const size_t arrivalNodeIndex, const TimeWindow &arrivalTw,
+            const uint deltaTime, const uint weight, const Graph& graph);
     Request(const DATRow& currentRow, const Graph& graph);
     Request(const DATRow& currentRow, double deltaRatio, const Graph& graph);
 
     static std::vector<Request> getRequestsFromFile(const std::string& datFilePath, const Graph& graph);
 
     //Getters
-    [[nodiscard]] const int getOriginNodeIndex() const;
-    [[nodiscard]] const int getDestinationNodeIndex() const;
+    [[nodiscard]] size_t getOriginNodeIndex() const;
+    [[nodiscard]] size_t getDestinationNodeIndex() const;
     [[nodiscard]] const TimeWindow &getArrivalTw() const;
-    [[nodiscard]] const int getDeltaTime() const;
-    [[nodiscard]] const int getWeight() const;
+    [[nodiscard]] int getDeltaTime() const;
+    [[nodiscard]] int getWeight() const;
     [[nodiscard]] int getCurrentDeltaTime() const;
     [[nodiscard]] int getRequestServiceStart() const;
     [[nodiscard]] int getRequestServiceEnd() const;
     [[nodiscard]] const RequestRoute &getCurrentRoute() const;
     [[nodiscard]] const TimeWindow &getDepartureTw() const;
-    [[nodiscard]] const int &getMinDepartureTw() const;
-    [[nodiscard]] const int &getMaxDepartureTw() const;
-    [[nodiscard]] const int &getMinArrivalTw() const;
-    [[nodiscard]] const int &getMaxArrivalTw() const;
+    [[nodiscard]] uint getMinDepartureTw() const;
+    [[nodiscard]] uint getMaxDepartureTw() const;
+    [[nodiscard]] uint getMinArrivalTw() const;
+    [[nodiscard]] uint getMaxArrivalTw() const;
 
     //Setters
     void setCurrentDeltaTime(int currentDeltaTime);
diff --git a/src/routes/vehicle/SAEVKeyPoint.cpp b/src/routes/vehicle/SAEVKeyPoint.cpp
index 15511b8..9f7527f 100644
--- a/src/routes/vehicle/SAEVKeyPoint.cpp
+++ b/src/routes/vehicle/SAEVKeyPoint.cpp
@@ -32,19 +32,19 @@ void SAEVKeyPoint::setCurrentOccupation(int currentCapacity) {
     _currentOccupation = currentCapacity;
 }
 
-int SAEVKeyPoint::getMinTw() const {
+uint SAEVKeyPoint::getMinTw() const {
     return _minTW;
 }
 
-void SAEVKeyPoint::setMinTw(int minTw) {
+void SAEVKeyPoint::setMinTw(uint minTw) {
     _minTW = minTw;
 }
 
-int SAEVKeyPoint::getMaxTw() const {
+uint SAEVKeyPoint::getMaxTw() const {
     return _maxTW;
 }
 
-void SAEVKeyPoint::setMaxTw(int maxTw) {
+void SAEVKeyPoint::setMaxTw(uint maxTw) {
     _maxTW = maxTw;
 }
 
diff --git a/src/routes/vehicle/SAEVKeyPoint.h b/src/routes/vehicle/SAEVKeyPoint.h
index bacdbaa..8725687 100644
--- a/src/routes/vehicle/SAEVKeyPoint.h
+++ b/src/routes/vehicle/SAEVKeyPoint.h
@@ -18,8 +18,8 @@ private:
     SAEVKeyPoint* _successor{nullptr};
     SAEVKeyPoint* _counterpart{nullptr};
     int _currentOccupation{0};
-    int _minTW{0};
-    int _maxTW{INT16_MAX};
+    uint _minTW{0};
+    uint _maxTW{INT16_MAX};
     SAEVehicle const * _vehiclePointer{};
     Request const * _requestPointer{};
 public:
@@ -48,11 +48,11 @@ public:
     [[nodiscard]] int getCurrentOccupation() const;
     void setCurrentOccupation(int currentCapacity);
 
-    [[nodiscard]] int getMinTw() const;
-    void setMinTw(int minTw);
+    [[nodiscard]] uint getMinTw() const;
+    void setMinTw(uint minTw);
 
-    [[nodiscard]] int getMaxTw() const;
-    void setMaxTw(int maxTw);
+    [[nodiscard]] uint getMaxTw() const;
+    void setMaxTw(uint maxTw);
 
     [[nodiscard]] bool isOrigin() const;
     [[nodiscard]] bool isDestination() const;
-- 
GitLab