Skip to content

Commit c0fcdde

Browse files
committed
Move capacity-related attributes to Road class
1 parent a5c25a5 commit c0fcdde

File tree

4 files changed

+48
-42
lines changed

4 files changed

+48
-42
lines changed

src/dsf/headers/Edge.hpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ namespace dsf {
1212
std::vector<std::pair<double, double>> m_geometry;
1313
Id m_id;
1414
std::pair<Id, Id> m_nodePair;
15-
int m_capacity;
16-
double m_transportCapacity;
1715
std::optional<double> m_weight;
1816
double m_angle;
1917

@@ -24,24 +22,16 @@ namespace dsf {
2422
/// @brief Construct a new Edge object
2523
/// @param id The edge's id
2624
/// @param nodePair The edge's node pair (u, v) with the edge u -> v
27-
/// @param capacity The edge's capacity, in number of agents, i.e. the maximum number of agents that can be on the
28-
/// edge at the same time. Default is 1.
29-
/// @param transportCapacity The edge's transport capacity, in number of agents, i.e. the maximum number of agents
30-
/// that can be emitted by the same time. Default is 1.
3125
/// @param geometry The edge's geometry, a vector of pairs of doubles representing the coordinates of the edge's
3226
/// geometry. Default is an empty vector.
3327
Edge(Id id,
3428
std::pair<Id, Id> nodePair,
35-
int capacity = 1,
36-
double transportCapacity = 1.,
3729
std::vector<std::pair<double, double>> geometry = {});
3830
Edge(Edge&&) = default;
3931
Edge(const Edge&) = delete;
4032
virtual ~Edge() = default;
4133

4234
void resetId(Id newId);
43-
void setCapacity(int capacity);
44-
void setTransportCapacity(double capacity);
4535
void setGeometry(std::vector<std::pair<double, double>> geometry);
4636
void setWeight(double const weight);
4737

@@ -58,14 +48,10 @@ namespace dsf {
5848
/// @return std::pair<Id, Id> The edge's node pair, where the first element is the source node id and the second
5949
/// element is the target node id. The pair is (u, v) with the edge u -> v.
6050
std::pair<Id, Id> const& nodePair() const;
61-
51+
/// @brief Get the edge's geometry
52+
/// @return std::vector<std::pair<double, double>> The edge's geometry, a vector of pairs of doubles representing the coordinates of the edge's geometry
6253
std::vector<std::pair<double, double>> const& geometry() const;
63-
/// @brief Get the edge's capacity, in number of agents
64-
/// @return int The edge's capacity, in number of agents
65-
int capacity() const;
66-
/// @brief Get the edge's transport capacity, in number of agents
67-
/// @return int The edge's transport capacity, in number of agents
68-
double transportCapacity() const;
54+
6955
/// @brief Get the edge's angle, in radians, between the source and target nodes
7056
/// @return double The edge's angle, in radians
7157
double angle() const;

src/dsf/headers/Road.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace dsf {
1414
double m_length;
1515
double m_maxSpeed;
1616
int m_nLanes;
17+
int m_capacity;
18+
double m_transportCapacity;
1719
std::string m_name;
1820
int m_priority;
1921
std::set<Id> m_forbiddenTurns; // Stores the forbidden turns (road ids)
@@ -49,6 +51,14 @@ namespace dsf {
4951
/// @param speed The maximum speed
5052
/// @throws std::invalid_argument If the speed is less or equal to 0
5153
void setMaxSpeed(double speed);
54+
/// @brief Set the capacity, in number of agents
55+
/// @param capacity The capacity
56+
/// @throws std::invalid_argument If the capacity is less or equal to 0
57+
void setCapacity(int capacity);
58+
/// @brief Set the transport capacity, in number of agents
59+
/// @param transportCapacity The transport capacity
60+
/// @throws std::invalid_argument If the transport capacity is less or equal to 0
61+
void setTransportCapacity(double transportCapacity);
5262
/// @brief Set the road's priority
5363
/// @param priority The road's priority
5464
void setPriority(int priority);
@@ -68,6 +78,12 @@ namespace dsf {
6878
/// @brief Get the number of lanes
6979
/// @return int The number of lanes
7080
int nLanes() const;
81+
/// @brief Get the road's capacity, in number of agents
82+
/// @return int The road's capacity, in number of agents
83+
int capacity() const;
84+
/// @brief Get the road's transport capacity, in number of agents
85+
/// @return double The road's transport capacity, in number of agents
86+
double transportCapacity() const;
7187
/// @brief Get the name
7288
/// @return std::string The name
7389
std::string name() const;

src/dsf/sources/Edge.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@
99
namespace dsf {
1010
Edge::Edge(Id id,
1111
std::pair<Id, Id> nodePair,
12-
int capacity,
13-
double transportCapacity,
1412
std::vector<std::pair<double, double>> geometry)
1513
: m_geometry{std::move(geometry)}, m_id(id), m_nodePair(nodePair) {
16-
setCapacity(capacity);
17-
setTransportCapacity(transportCapacity);
1814
if (m_geometry.size() > 1) {
1915
m_setAngle(m_geometry[m_geometry.size() - 2], m_geometry.back());
2016
} else {
@@ -35,20 +31,6 @@ namespace dsf {
3531
}
3632

3733
void Edge::resetId(Id newId) { m_id = newId; }
38-
void Edge::setCapacity(int capacity) {
39-
if (capacity < 1) {
40-
throw std::invalid_argument(
41-
std::format("{} capacity ({}) must be greater than 0.", *this, capacity));
42-
}
43-
m_capacity = capacity;
44-
}
45-
void Edge::setTransportCapacity(double capacity) {
46-
if (capacity <= 0.) {
47-
throw std::invalid_argument(std::format(
48-
"{} edge transport capacity ({}) must be greater than 0.", *this, capacity));
49-
}
50-
m_transportCapacity = capacity;
51-
}
5234

5335
void Edge::setGeometry(std::vector<std::pair<double, double>> geometry) {
5436
m_geometry = std::move(geometry);
@@ -70,8 +52,6 @@ namespace dsf {
7052
Id Edge::source() const { return m_nodePair.first; }
7153
Id Edge::target() const { return m_nodePair.second; }
7254
std::pair<Id, Id> const& Edge::nodePair() const { return m_nodePair; }
73-
int Edge::capacity() const { return m_capacity; }
74-
double Edge::transportCapacity() const { return m_transportCapacity; }
7555
double Edge::angle() const { return m_angle; }
7656
double Edge::weight() const {
7757
return m_weight.has_value() ? *m_weight

src/dsf/sources/Road.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ namespace dsf {
1818
std::vector<std::pair<double, double>> geometry,
1919
std::optional<int> capacity,
2020
double transportCapacity)
21-
: Edge(id,
22-
std::move(nodePair),
23-
capacity.value_or(std::ceil((length * nLanes) / m_meanVehicleLength)),
24-
transportCapacity,
25-
std::move(geometry)),
21+
: Edge(id, std::move(nodePair), std::move(geometry)),
2622
m_length{length},
2723
m_maxSpeed{maxSpeed},
2824
m_nLanes{nLanes},
@@ -40,6 +36,17 @@ namespace dsf {
4036
throw std::invalid_argument(std::format(
4137
"The number of lanes of a road ({}) must be greater than 0.", nLanes));
4238
}
39+
m_capacity = capacity.value_or(std::ceil((length * nLanes) / m_meanVehicleLength));
40+
if (m_capacity < 1) {
41+
throw std::invalid_argument(
42+
std::format("The capacity of a road ({}) must be greater than 0.", m_capacity));
43+
}
44+
if (transportCapacity <= 0.) {
45+
throw std::invalid_argument(
46+
std::format("The transport capacity of a road ({}) must be greater than 0.",
47+
transportCapacity));
48+
}
49+
m_transportCapacity = transportCapacity;
4350
}
4451
void Road::setMeanVehicleLength(double meanVehicleLength) {
4552
if (!(meanVehicleLength > 0.)) {
@@ -62,6 +69,21 @@ namespace dsf {
6269
}
6370
m_maxSpeed = speed;
6471
}
72+
void Road::setCapacity(int capacity) {
73+
if (capacity < 1) {
74+
throw std::invalid_argument(
75+
std::format("The capacity of a road ({}) must be greater than 0.", capacity));
76+
}
77+
m_capacity = capacity;
78+
}
79+
void Road::setTransportCapacity(double transportCapacity) {
80+
if (transportCapacity <= 0.) {
81+
throw std::invalid_argument(
82+
std::format("The transport capacity of a road ({}) must be greater than 0.",
83+
transportCapacity));
84+
}
85+
m_transportCapacity = transportCapacity;
86+
}
6587
void Road::setPriority(int priority) {
6688
assert(priority >= 0);
6789
m_priority = priority;
@@ -83,6 +105,8 @@ namespace dsf {
83105
double Road::length() const { return m_length; }
84106
double Road::maxSpeed() const { return m_maxSpeed; }
85107
int Road::nLanes() const { return m_nLanes; }
108+
int Road::capacity() const { return m_capacity; }
109+
double Road::transportCapacity() const { return m_transportCapacity; }
86110
std::string Road::name() const { return m_name; }
87111
int Road::priority() const { return m_priority; }
88112
std::set<Id> const& Road::forbiddenTurns() const { return m_forbiddenTurns; }

0 commit comments

Comments
 (0)