diff --git a/examples/slow_charge_tl.cpp b/examples/slow_charge_tl.cpp index 24ce34645..5a7d91860 100644 --- a/examples/slow_charge_tl.cpp +++ b/examples/slow_charge_tl.cpp @@ -178,17 +178,11 @@ int main(int argc, char** argv) { const auto& col = adj.getCol(nodeId, true); std::set streets; const auto id = col.begin(); - const auto& refLat = graph.nodeSet() - .at(graph.streetSet().at(id->first)->nodePair().second) - ->coords() - .value() - .first; + const auto& refLat = + graph.node(graph.street(id->first)->nodePair().second)->coords().value().first; for (const auto& [c, value] : col) { - const auto& lat = graph.nodeSet() - .at(graph.streetSet().at(c)->nodePair().first) - ->coords() - .value() - .first; + const auto& lat = + graph.node(graph.street(c)->nodePair().first)->coords().value().first; // std::cout << "Lat: " << lat << " RefLat: " << refLat << '\n'; if (lat == refLat) { streets.emplace(c); diff --git a/examples/stalingrado.cpp b/examples/stalingrado.cpp index c0324dc75..62f7ccc8b 100644 --- a/examples/stalingrado.cpp +++ b/examples/stalingrado.cpp @@ -75,7 +75,7 @@ int main() { graph.buildAdj(); graph.adjustNodeCapacities(); graph.makeSpireStreet(19); - auto& spire = dynamic_cast(*graph.streetSet().at(19)); + auto& spire = dynamic_cast(*graph.street(19)); std::cout << "Intersections: " << graph.nNodes() << '\n'; std::cout << "Streets: " << graph.nEdges() << '\n'; diff --git a/src/dsm/dsm.hpp b/src/dsm/dsm.hpp index 0a721f88a..2aad4e0e2 100644 --- a/src/dsm/dsm.hpp +++ b/src/dsm/dsm.hpp @@ -6,7 +6,7 @@ static constexpr uint8_t DSM_VERSION_MAJOR = 2; static constexpr uint8_t DSM_VERSION_MINOR = 3; -static constexpr uint8_t DSM_VERSION_PATCH = 3; +static constexpr uint8_t DSM_VERSION_PATCH = 4; static auto const DSM_VERSION = std::format("{}.{}.{}", DSM_VERSION_MAJOR, DSM_VERSION_MINOR, DSM_VERSION_PATCH); diff --git a/src/dsm/headers/Dynamics.hpp b/src/dsm/headers/Dynamics.hpp index 7ef6f03e7..eb5beca3e 100644 --- a/src/dsm/headers/Dynamics.hpp +++ b/src/dsm/headers/Dynamics.hpp @@ -426,7 +426,7 @@ namespace dsm { template double Dynamics::streetMeanSpeed(Id streetId) const { - auto const& pStreet{m_graph.streetSet().at(streetId)}; + auto const& pStreet{m_graph.street(streetId)}; auto const nAgents{pStreet->nAgents()}; if (nAgents == 0) { return 0.; diff --git a/src/dsm/headers/FirstOrderDynamics.cpp b/src/dsm/headers/FirstOrderDynamics.cpp index 8219ff076..183d188e6 100644 --- a/src/dsm/headers/FirstOrderDynamics.cpp +++ b/src/dsm/headers/FirstOrderDynamics.cpp @@ -47,7 +47,7 @@ namespace dsm { } double FirstOrderDynamics::streetMeanSpeed(Id streetId) const { - const auto& street{this->m_graph.streetSet().at(streetId)}; + const auto& street{this->m_graph.street(streetId)}; if (street->nAgents() == 0) { return street->maxSpeed(); } @@ -69,7 +69,7 @@ namespace dsm { } } } - const auto& node = this->m_graph.nodeSet().at(street->nodePair().second); + const auto& node = this->m_graph.node(street->nodePair().second); if (node->isIntersection()) { auto& intersection = dynamic_cast(*node); for (const auto& [angle, agentId] : intersection.agents()) { diff --git a/src/dsm/headers/Graph.hpp b/src/dsm/headers/Graph.hpp index c588f3f9d..fc8ff2303 100644 --- a/src/dsm/headers/Graph.hpp +++ b/src/dsm/headers/Graph.hpp @@ -229,6 +229,9 @@ namespace dsm { /// @brief Get the graph's node map /// @return A std::unordered_map containing the graph's nodes std::unordered_map>& nodeSet() { return m_nodes; } + /// @brief Get a node from the graph + /// @param id The node's id + const std::unique_ptr& node(Id id) const { return m_nodes.at(id); } /// @brief Get the Graph's number of streets /// @return size_t The number of streets in the graph size_t nEdges() const { return m_streets.size(); } @@ -241,6 +244,9 @@ namespace dsm { /// @return A std::unordered_map containing the graph's streets std::unordered_map>& streetSet() { return m_streets; } /// @brief Get a street from the graph + /// @param id The street's id + const std::unique_ptr& street(Id id) const { return m_streets.at(id); } + /// @brief Get a street from the graph /// @param source The source node /// @param destination The destination node /// @return A std::unique_ptr to the street if it exists, nullptr otherwise diff --git a/src/dsm/headers/RoadDynamics.hpp b/src/dsm/headers/RoadDynamics.hpp index b4ad4a563..797b263d6 100644 --- a/src/dsm/headers/RoadDynamics.hpp +++ b/src/dsm/headers/RoadDynamics.hpp @@ -225,8 +225,7 @@ namespace dsm { p = moveDist(this->m_generator); iterator = possibleMoves.begin(); std::advance(iterator, p); - } while (!this->m_graph.nodeSet().at(nodeId)->isRoundabout() and - streetId.has_value() and + } while (!this->m_graph.node(nodeId)->isRoundabout() and streetId.has_value() and (this->m_graph.streetSet()[iterator->first]->nodePair().second == this->m_graph.streetSet()[streetId.value()]->nodePair().first) and (possibleMoves.size() > 1)); diff --git a/test/Test_dynamics.cpp b/test/Test_dynamics.cpp index d7533a302..e9e7727eb 100644 --- a/test/Test_dynamics.cpp +++ b/test/Test_dynamics.cpp @@ -75,7 +75,7 @@ TEST_CASE("Dynamics") { auto& tl = graph.makeTrafficLight(0, 2); Dynamics dynamics{graph, 69}; THEN("The node is a traffic light") { - CHECK(dynamics.graph().nodeSet().at(0)->isTrafficLight()); + CHECK(dynamics.graph().node(0)->isTrafficLight()); CHECK_EQ(tl.cycleTime(), 2); } } @@ -83,15 +83,13 @@ TEST_CASE("Dynamics") { graph.makeRoundabout(0); Dynamics dynamics{graph, 69}; THEN("The node is a roundabout") { - CHECK(dynamics.graph().nodeSet().at(0)->isRoundabout()); + CHECK(dynamics.graph().node(0)->isRoundabout()); } } WHEN("We transorm a street into a spire and create the dynamcis") { graph.makeSpireStreet(8); Dynamics dynamics{graph, 69}; - THEN("The street is a spire") { - CHECK(dynamics.graph().streetSet().at(8)->isSpire()); - } + THEN("The street is a spire") { CHECK(dynamics.graph().street(8)->isSpire()); } } } } @@ -910,8 +908,8 @@ TEST_CASE("Dynamics") { for (const auto& [agentId, agent] : dynamics.agents()) { meanSpeed += agent->speed(); } - meanSpeed /= (dynamics.graph().streetSet().at(1)->nExitingAgents() + - dynamics.graph().streetSet().at(1)->movingAgents().size()); + auto const& pStreet{dynamics.graph().street(1)}; + meanSpeed /= (pStreet->nExitingAgents() + pStreet->movingAgents().size()); CHECK_EQ(dynamics.streetMeanSpeed(1), meanSpeed); // I don't think the mean speed of agents should be equal to the street's // one... CHECK_EQ(dynamics.streetMeanSpeed().mean, @@ -930,8 +928,8 @@ TEST_CASE("Dynamics") { meanSpeed += agent->speed(); } } - meanSpeed /= dynamics.graph().streetSet().at(1)->queue(0).size(); - CHECK_EQ(dynamics.graph().streetSet().at(1)->queue(0).size(), 3); + meanSpeed /= pStreet->queue(0).size(); + CHECK_EQ(pStreet->queue(0).size(), 3); CHECK_EQ(dynamics.streetMeanSpeed(1), meanSpeed); } SUBCASE("Intersection priorities") { @@ -952,7 +950,7 @@ TEST_CASE("Dynamics") { graph2.addEdge(7, std::make_pair(4, 0), 10., 10.); graph2.buildAdj(); Dynamics dynamics{graph2, 69}; - dynamics.graph().nodeSet().at(0)->setCapacity(3); + dynamics.graph().node(0)->setCapacity(3); Itinerary itinerary{0, 2}; Itinerary itinerary2{1, 1}; dynamics.addItinerary(itinerary); diff --git a/test/Test_graph.cpp b/test/Test_graph.cpp index 74ecd003f..1b4f9d991 100644 --- a/test/Test_graph.cpp +++ b/test/Test_graph.cpp @@ -271,9 +271,7 @@ TEST_CASE("Graph") { graph.buildAdj(); WHEN("We make node 0 a traffic light") { auto& tl = graph.makeTrafficLight(0, 60); - THEN("The node 0 is a traffic light") { - CHECK(graph.nodeSet().at(0)->isTrafficLight()); - } + THEN("The node 0 is a traffic light") { CHECK(graph.node(0)->isTrafficLight()); } THEN("The traffic light has the correct parameters") { CHECK_EQ(tl.id(), 0); CHECK_EQ(tl.cycleTime(), 60); @@ -288,9 +286,7 @@ TEST_CASE("Graph") { graph.buildAdj(); WHEN("We make node 0 a roundabout") { graph.makeRoundabout(0); - THEN("The node 0 is a roundabout") { - CHECK(graph.nodeSet().at(0)->isRoundabout()); - } + THEN("The node 0 is a roundabout") { CHECK(graph.node(0)->isRoundabout()); } } } } @@ -301,9 +297,7 @@ TEST_CASE("Graph") { graph.buildAdj(); WHEN("We make the street a spire street") { graph.makeSpireStreet(1); - THEN("The street is a spire street") { - CHECK(graph.streetSet().at(1)->isSpire()); - } + THEN("The street is a spire street") { CHECK(graph.street(1)->isSpire()); } } } }