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
4 changes: 2 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ find_package(TBB REQUIRED CONFIG)

# Set the C++ flags
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
string(APPEND CMAKE_CXX_FLAGS "-Wall -Wextra -O0 -g")
string(APPEND CMAKE_CXX_FLAGS "-Wall -Wextra -O0 -g -fsanitize=address")
elseif (CMAKE_BUILD_TYPE STREQUAL "Release")
string(APPEND CMAKE_CXX_FLAGS "-O3")
string(APPEND CMAKE_CXX_FLAGS "-O3 -fsanitize=address")
endif()

# Set the folder for the executable
Expand Down
2 changes: 1 addition & 1 deletion examples/slow_charge_rb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ int main(int argc, char** argv) {

std::cout << "Creating dynamics...\n";

Dynamics dynamics{graph, true, SEED, 0.95};
Dynamics dynamics{graph, true, SEED, 0.6};
Unit n{0};
{
std::vector<Unit> destinationNodes;
Expand Down
2 changes: 1 addition & 1 deletion examples/slow_charge_tl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ int main(int argc, char** argv) {

std::cout << "Creating dynamics...\n";

Dynamics dynamics{graph, true, SEED, 0.95};
Dynamics dynamics{graph, true, SEED, 0.6};
Unit n{0};
{
std::vector<Unit> destinationNodes;
Expand Down
14 changes: 5 additions & 9 deletions examples/stalingrado.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,22 @@

// Street(StreetId, Capacity, Length, vMax, (from, to))
dsm::Road::setMeanVehicleLength(8.);
Street s01{1, std::make_pair(0, 1), 2281.};
Street s12{7, std::make_pair(1, 2), 118.};
Street s23{13, std::make_pair(2, 3), 222.};
Street s01{1, std::make_pair(0, 1), 2281., 13.9, 2};

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
Street s12{7, std::make_pair(1, 2), 118., 13.9, 2};

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
Street s23{13, std::make_pair(2, 3), 222., 13.9, 2};

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
Street s34{19, std::make_pair(3, 4), 651., 13.9, 2};
// Viale Aldo Moro
auto& tl1 = graph.addNode<TrafficLight>(1, 132);
tl1.setCycle(s01.id(), dsm::Direction::ANY, {62, 0});
tl1.setCapacity(1);
// Via Donato Creti
auto& tl2 = graph.addNode<TrafficLight>(2, 141);
tl2.setCycle(s12.id(), dsm::Direction::ANY, {72, 0});
tl2.setCapacity(1);
// Via del Lavoro
auto& tl3 = graph.addNode<TrafficLight>(3, 138);
tl3.setCycle(s23.id(), dsm::Direction::ANY, {88, 0});
tl3.setCapacity(1);
// Viali
auto& tl4 = graph.addNode<TrafficLight>(4, 131);
tl4.setCycle(s34.id(), dsm::Direction::ANY, {81, 0});
tl4.setCapacity(1);

graph.addStreets(s01, s12, s23, s34);
graph.buildAdj();
Expand All @@ -86,7 +82,7 @@
dsm::Logger::info(std::format("Streets: {}", graph.nEdges()));

// Create the dynamics
Dynamics dynamics{graph, false, 69, 0.95};
Dynamics dynamics{graph, false, 69, 0.6};
dynamics.setSpeedFluctuationSTD(0.2);
Itinerary itinerary{4, 4};
dynamics.addItinerary(itinerary);
Expand All @@ -112,7 +108,7 @@
if (progress % 300 == 0) {
ofs << progress << ';' << spire.outputCounts(true) << std::endl;
}
dynamics.addAgents(*it / 2, 4, 0);
dynamics.addAgents(*it, 4, 0);
}
dynamics.evolve(false);
++progress;
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 = 25;
static constexpr uint8_t DSM_VERSION_PATCH = 26;

static auto const DSM_VERSION =
std::format("{}.{}.{}", DSM_VERSION_MAJOR, DSM_VERSION_MINOR, DSM_VERSION_PATCH);
Expand Down
27 changes: 20 additions & 7 deletions src/dsm/headers/RoadDynamics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
continue;
}
pAgent->setSpeed(0.);
const auto& destinationNode{this->m_graph.nodeSet()[pStreet->nodePair().second]};
const auto& destinationNode{this->m_graph.node(pStreet->target())};
if (destinationNode->isFull()) {
continue;
}
Expand Down Expand Up @@ -687,14 +687,27 @@
// move the first agent of each street queue, if possible, putting it in the next node
bool const bUpdateData =
m_dataUpdatePeriod.has_value() && this->m_time % m_dataUpdatePeriod.value() == 0;
for (const auto& [streetId, pStreet] : this->m_graph.streetSet()) {
if (bUpdateData) {
m_streetTails[streetId] += pStreet->nExitingAgents();
}
for (auto i = 0; i < pStreet->transportCapacity(); ++i) {
this->m_evolveStreet(pStreet, reinsert_agents);
for (auto const& [nodeId, _] : this->m_graph.nodeSet()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
for (auto const& [streetId, _] : this->m_graph.adjMatrix().getCol(nodeId, true)) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 14.4 rule Note

MISRA 14.4 rule

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
auto const& pStreet{this->m_graph.street(streetId)};
// Logger::info(std::format("Evolving street {}", streetId));
if (bUpdateData) {
m_streetTails[streetId] += pStreet->nExitingAgents();
}
for (auto i = 0; i < pStreet->transportCapacity(); ++i) {
this->m_evolveStreet(pStreet, reinsert_agents);
}
}
}
// for (const auto& [streetId, pStreet] : this->m_graph.streetSet()) {
// if (bUpdateData) {
// m_streetTails[streetId] += pStreet->nExitingAgents();
// }
// Logger::info(std::format("Evolving street {}", streetId));
// for (auto i = 0; i < pStreet->transportCapacity(); ++i) {
// this->m_evolveStreet(pStreet, reinsert_agents);
// }
// }
// Move transport capacity agents from each node
for (const auto& [nodeId, pNode] : this->m_graph.nodeSet()) {
for (auto i = 0; i < pNode->transportCapacity(); ++i) {
Expand Down
23 changes: 11 additions & 12 deletions test/Test_dynamics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,41 +784,40 @@
"itineraries "
"and a roundabout") {
Road::setMeanVehicleLength(10.);
Street s1{0, std::make_pair(0, 1), 10., 10.};
Street s2{1, std::make_pair(2, 1), 10., 10.};
Street s3{2, std::make_pair(1, 0), 10., 10.};
Street s4{3, std::make_pair(1, 2), 10., 10.};
Street s1{1, std::make_pair(0, 1), 10., 10.};

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note test

MISRA 12.3 rule
Street s2{7, std::make_pair(2, 1), 10., 10.};

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note test

MISRA 12.3 rule
Street s3{3, std::make_pair(1, 0), 10., 10.};

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note test

MISRA 12.3 rule
Street s4{5, std::make_pair(1, 2), 10., 10.};

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note test

MISRA 12.3 rule
Graph graph2;
graph2.addStreets(s1, s2, s3, s4);
graph2.buildAdj();
auto& rb = graph2.makeRoundabout(1);
graph2.adjustNodeCapacities();
Dynamics dynamics{graph2, false, 69};
Itinerary itinerary{0, 2};
Itinerary itinerary2{1, 0};
Itinerary itinerary{2, 2};
Itinerary itinerary2{0, 0};
dynamics.addItinerary(itinerary);
dynamics.addItinerary(itinerary2);
dynamics.updatePaths();
dynamics.addAgent(0, 0, 0);
dynamics.addAgent(1, 1, 2);
dynamics.addAgent(0, 2, 0);
dynamics.addAgent(1, 0, 2);
WHEN(
"We evolve the dynamics adding an agent on the path of the agent "
"with "
"priority") {
dynamics.evolve(false);
dynamics.addAgent(2, 0, 1);
dynamics.addAgent(2, 2, 1);
dynamics.evolve(false);
dynamics.evolve(false);
THEN("The agents are trapped into the roundabout") {
CHECK_EQ(dynamics.agents().at(0)->streetId().value(), 1);
CHECK_EQ(dynamics.agents().at(1)->streetId().value(), 7);
CHECK_EQ(dynamics.agents().at(1)->streetId().value(), 3);
CHECK_EQ(dynamics.agents().at(2)->streetId().value(), 5);
CHECK_EQ(rb.agents().size(), 1);
CHECK(rb.agents().empty());
}
dynamics.evolve(false);
THEN("The agent with priority leaves the roundabout") {
CHECK_EQ(dynamics.agents().at(0)->streetId().value(), 5);
CHECK_EQ(dynamics.agents().at(1)->streetId().value(), 3);
CHECK(rb.agents().empty());
}
}
Expand Down
Loading