Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions examples/slow_charge_tl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,11 @@ int main(int argc, char** argv) {
const auto& col = adj.getCol(nodeId, true);
std::set<Unit> 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);
Expand Down
2 changes: 1 addition & 1 deletion examples/stalingrado.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int main() {
graph.buildAdj();
graph.adjustNodeCapacities();
graph.makeSpireStreet(19);
auto& spire = dynamic_cast<SpireStreet&>(*graph.streetSet().at(19));
auto& spire = dynamic_cast<SpireStreet&>(*graph.street(19));

std::cout << "Intersections: " << graph.nNodes() << '\n';
std::cout << "Streets: " << graph.nEdges() << '\n';
Expand Down
2 changes: 1 addition & 1 deletion src/dsm/dsm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/dsm/headers/Dynamics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ namespace dsm {

template <typename agent_t>
double Dynamics<agent_t>::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.;
Expand Down
4 changes: 2 additions & 2 deletions src/dsm/headers/FirstOrderDynamics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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<Intersection&>(*node);
for (const auto& [angle, agentId] : intersection.agents()) {
Expand Down
6 changes: 6 additions & 0 deletions src/dsm/headers/Graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Id, std::unique_ptr<Node>>& nodeSet() { return m_nodes; }
/// @brief Get a node from the graph
/// @param id The node's id
const std::unique_ptr<Node>& 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(); }
Expand All @@ -241,6 +244,9 @@ namespace dsm {
/// @return A std::unordered_map containing the graph's streets
std::unordered_map<Id, std::unique_ptr<Street>>& streetSet() { return m_streets; }
/// @brief Get a street from the graph
/// @param id The street's id
const std::unique_ptr<Street>& 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
Expand Down
3 changes: 1 addition & 2 deletions src/dsm/headers/RoadDynamics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
18 changes: 8 additions & 10 deletions test/Test_dynamics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,21 @@ 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);
}
}
WHEN("We transform a node into a roundabout and create the 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()); }
}
}
}
Expand Down Expand Up @@ -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,
Expand All @@ -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") {
Expand All @@ -952,7 +950,7 @@ TEST_CASE("Dynamics") {
graph2.addEdge<Street>(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);
Expand Down
12 changes: 3 additions & 9 deletions test/Test_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()); }
}
}
}
Expand All @@ -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()); }
}
}
}
Expand Down
Loading