Skip to content

Commit 99cdedb

Browse files
committed
Init refactoring
1 parent 5d36cb9 commit 99cdedb

File tree

4 files changed

+12
-30
lines changed

4 files changed

+12
-30
lines changed

src/dsf/mobility/Road.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ namespace dsf::mobility {
2222
m_length{length},
2323
m_maxSpeed{maxSpeed},
2424
m_nLanes{nLanes},
25-
m_name{std::move(name)},
26-
m_priority{nLanes * 100} {
25+
m_name{std::move(name)} {
2726
if (!(length > 0.)) {
2827
throw std::invalid_argument(
2928
std::format("The length of a road ({}) must be greater than 0.", length));
@@ -84,10 +83,6 @@ namespace dsf::mobility {
8483
}
8584
m_transportCapacity = transportCapacity;
8685
}
87-
void Road::setPriority(int priority) {
88-
assert(priority >= 0);
89-
m_priority = priority;
90-
}
9186
Direction Road::turnDirection(double const& previousStreetAngle) const {
9287
auto const deltaAngle{this->deltaAngle(previousStreetAngle)};
9388
if (std::abs(deltaAngle) >= std::numbers::pi) {

src/dsf/mobility/Road.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace dsf::mobility {
1717
int m_capacity;
1818
double m_transportCapacity;
1919
std::string m_name;
20-
int m_priority;
20+
bool m_hasPriority = false;
2121
std::set<Id> m_forbiddenTurns; // Stores the forbidden turns (road ids)
2222

2323
public:
@@ -60,9 +60,8 @@ namespace dsf::mobility {
6060
/// @param transportCapacity The transport capacity
6161
/// @throws std::invalid_argument If the transport capacity is less or equal to 0
6262
void setTransportCapacity(double transportCapacity);
63-
/// @brief Set the road's priority
64-
/// @param priority The road's priority
65-
void setPriority(int priority);
63+
/// @brief Set the road's priority to true
64+
inline void setPriority() { m_hasPriority = true; }
6665
/// @brief Add a road id to the forbidden turns
6766
/// @param roadId The road id to add
6867
void addForbiddenTurn(Id roadId);
@@ -90,7 +89,7 @@ namespace dsf::mobility {
9089
inline auto const& name() const noexcept { return m_name; }
9190
/// @brief Get the priority
9291
/// @return int The priority
93-
inline auto priority() const noexcept { return m_priority; }
92+
inline auto hasPriority() const noexcept { return m_hasPriority; }
9493
/// @brief Get the road's forbidden turns
9594
/// @return std::set<Id> The road's forbidden turns
9695
/// @details The forbidden turns are the road ids that are not allowed to be used by the agents

src/dsf/mobility/RoadNetwork.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -507,23 +507,10 @@ namespace dsf::mobility {
507507
auto const& pNode{pair.second};
508508
auto const& inNeighbours{pNode->ingoingEdges()};
509509
auto const& outNeighbours{pNode->outgoingEdges()};
510-
int maxPriority{0};
511-
std::for_each(inNeighbours.cbegin(),
512-
inNeighbours.cend(),
513-
[this, &maxPriority](auto const& edgeId) {
514-
auto const& pStreet{this->edge(edgeId)};
515-
maxPriority = std::max(maxPriority, pStreet->priority());
516-
});
517-
std::for_each(outNeighbours.cbegin(),
518-
outNeighbours.cend(),
519-
[this, &maxPriority](auto const& edgeId) {
520-
auto const& pStreet{this->edge(edgeId)};
521-
maxPriority = std::max(maxPriority, pStreet->priority());
522-
});
523510
std::for_each(
524511
inNeighbours.cbegin(),
525512
inNeighbours.cend(),
526-
[this, &pNode, &outNeighbours, &maxPriority](auto const& edgeId) {
513+
[this, &pNode, &outNeighbours](auto const& edgeId) {
527514
auto const& pInStreet{this->edge(edgeId)};
528515
auto const nLanes{pInStreet->nLanes()};
529516
if (nLanes == 1) {
@@ -533,7 +520,7 @@ namespace dsf::mobility {
533520
std::for_each(
534521
outNeighbours.cbegin(),
535522
outNeighbours.cend(),
536-
[this, &pInStreet, &allowedTurns, &maxPriority](auto const& edgeId) {
523+
[this, &pInStreet, &allowedTurns](auto const& edgeId) {
537524
auto const& pOutStreet{this->edge(edgeId)};
538525
if (pOutStreet->target() == pInStreet->source() ||
539526
pInStreet->forbiddenTurns().contains(pOutStreet->id())) {
@@ -546,8 +533,7 @@ namespace dsf::mobility {
546533
return;
547534
}
548535
// Actually going straight means remain on the same road, thus...
549-
if (((pInStreet->priority() == maxPriority) ==
550-
(outOppositeStreet->get()->priority() == maxPriority)) &&
536+
if ((pInStreet->priority() == outOppositeStreet->get()->priority()) &&
551537
!allowedTurns.contains(Direction::STRAIGHT)) {
552538
spdlog::debug("Street {} prioritized STRAIGHT", pInStreet->id());
553539
if (allowedTurns.contains(Direction::STRAIGHT) &&

test/mobility/Test_street.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ TEST_CASE("Road") {
216216
CHECK_EQ(road.capacity(),
217217
static_cast<int>(std::ceil((100.0 * 2) / Road::meanVehicleLength())));
218218
CHECK_EQ(road.transportCapacity(), 1.0);
219-
CHECK_EQ(road.priority(), 200); // 2 * 100
219+
CHECK_FALSE(road.hasPriority());
220+
road.setPriority();
221+
CHECK(road.hasPriority());
220222
}
221223
}
222224

@@ -403,7 +405,7 @@ TEST_CASE("Road") {
403405
static_cast<int>(std::ceil((100.0 * 2) / Road::meanVehicleLength())));
404406
CHECK_EQ(road.transportCapacity(), 1.0);
405407
CHECK_EQ(road.name(), "Test Road");
406-
CHECK_EQ(road.priority(), 200); // 2 * 100
408+
CHECK_FALSE(road.hasPriority());
407409
CHECK(road.forbiddenTurns().empty());
408410
}
409411

0 commit comments

Comments
 (0)