-
Notifications
You must be signed in to change notification settings - Fork 5
Add stationary probability for random vehicles movement #376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -172,6 +172,11 @@ PYBIND11_MODULE(dsf_cpp, m) { | |||||
| .def("autoMapStreetLanes", | ||||||
| &dsf::mobility::RoadNetwork::autoMapStreetLanes, | ||||||
| dsf::g_docstrings.at("dsf::mobility::RoadNetwork::autoMapStreetLanes").c_str()) | ||||||
| .def("setStreetStationaryWeights", | ||||||
| &dsf::mobility::RoadNetwork::setStreetStationaryWeights, | ||||||
| pybind11::arg("weights"), | ||||||
| dsf::g_docstrings.at("dsf::mobility::RoadNetwork::setStreetStationaryWeights") | ||||||
| .c_str()) | ||||||
| .def( | ||||||
| "importEdges", | ||||||
| [](dsf::mobility::RoadNetwork& self, const std::string& fileName) { | ||||||
|
|
@@ -531,6 +536,10 @@ PYBIND11_MODULE(dsf_cpp, m) { | |||||
| pybind11::arg("ratio") = 1.3, | ||||||
| dsf::g_docstrings.at("dsf::mobility::RoadDynamics::optimizeTrafficLights") | ||||||
| .c_str()) | ||||||
| .def("graph", | ||||||
| &dsf::mobility::FirstOrderDynamics::graph, | ||||||
| pybind11::return_value_policy::reference_internal, | ||||||
| dsf::g_docstrings.at("dsf::Dynamics::graph").c_str()) | ||||||
|
||||||
| dsf::g_docstrings.at("dsf::Dynamics::graph").c_str()) | |
| dsf::g_docstrings.at("dsf::Dynamics::graph() const").c_str()) |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -497,11 +497,13 @@ namespace dsf::mobility { | |||||
| std::optional<Id> previousNodeId = std::nullopt; | ||||||
| std::set<Id> forbiddenTurns; | ||||||
| double speedCurrent = 1.0; | ||||||
| double stationaryWeightCurrent = 1.0; | ||||||
| if (pAgent->streetId().has_value()) { | ||||||
| auto const& pStreetCurrent{this->graph().edge(pAgent->streetId().value())}; | ||||||
| previousNodeId = pStreetCurrent->source(); | ||||||
| forbiddenTurns = pStreetCurrent->forbiddenTurns(); | ||||||
| speedCurrent = pStreetCurrent->maxSpeed(); | ||||||
| stationaryWeightCurrent = pStreetCurrent->stationaryWeight(); | ||||||
| } | ||||||
|
|
||||||
| // Get path targets for non-random agents | ||||||
|
|
@@ -550,7 +552,10 @@ namespace dsf::mobility { | |||||
|
|
||||||
| // Calculate base probability | ||||||
| auto const speedNext{pStreetOut->maxSpeed()}; | ||||||
| double probability = speedCurrent * speedNext; | ||||||
| double const stationaryWeightNext = pStreetOut->stationaryWeight(); | ||||||
| auto const weightRatio{stationaryWeightNext / | ||||||
| stationaryWeightCurrent}; // SQRT (p_i / p_j) | ||||||
|
||||||
| stationaryWeightCurrent}; // SQRT (p_i / p_j) | |
| stationaryWeightCurrent}; // sqrt(p_next / p_current) |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |||||||||
| #include "dsf/mobility/RoadNetwork.hpp" | ||||||||||
| #include "dsf/mobility/Itinerary.hpp" | ||||||||||
| #include "dsf/mobility/Street.hpp" | ||||||||||
| #include "dsf/mobility/Intersection.hpp" | ||||||||||
|
|
||||||||||
| #include <chrono> | ||||||||||
| #include <cstdint> | ||||||||||
|
|
@@ -1282,3 +1283,101 @@ | |||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| TEST_CASE("Stationary Weights Impact on Random Navigation") { | ||||||||||
| RoadNetwork network; | ||||||||||
|
|
||||||||||
| network.addNode<Intersection>(0); | ||||||||||
| network.addNode<Intersection>(1); | ||||||||||
| network.addNode<Intersection>(2); | ||||||||||
| network.addNode<Intersection>(3); | ||||||||||
|
|
||||||||||
| const int numAgents = 3000; | ||||||||||
| const int highCapacity = numAgents + 100; | ||||||||||
|
|
||||||||||
| // Street 0: 0 -> 1 | ||||||||||
| // High length to hold all agents, high transport capacity to move them all at once | ||||||||||
| network.addStreet(Street(0, | ||||||||||
| {0, 1}, | ||||||||||
Check noticeCode scanning / Cppcheck (reported by Codacy) MISRA 12.3 rule Note test
MISRA 12.3 rule
|
||||||||||
| 100.0, | ||||||||||
| 10.0, | ||||||||||
| 1, | ||||||||||
| "Street 0", | ||||||||||
| {}, | ||||||||||
| highCapacity, | ||||||||||
| static_cast<double>(highCapacity))); | ||||||||||
| // Street 1: 1 -> 2 | ||||||||||
| network.addStreet(Street(1, | ||||||||||
| {1, 2}, | ||||||||||
Check noticeCode scanning / Cppcheck (reported by Codacy) MISRA 12.3 rule Note test
MISRA 12.3 rule
|
||||||||||
| 100.0, | ||||||||||
| 10.0, | ||||||||||
| 1, | ||||||||||
| "Street 1", | ||||||||||
| {}, | ||||||||||
| highCapacity, | ||||||||||
| static_cast<double>(highCapacity))); | ||||||||||
| // Street 2: 1 -> 3 | ||||||||||
| network.addStreet(Street(2, | ||||||||||
| {1, 3}, | ||||||||||
Check noticeCode scanning / Cppcheck (reported by Codacy) MISRA 12.3 rule Note test
MISRA 12.3 rule
|
||||||||||
| 100.0, | ||||||||||
| 10.0, | ||||||||||
| 1, | ||||||||||
| "Street 2", | ||||||||||
| {}, | ||||||||||
| highCapacity, | ||||||||||
| static_cast<double>(highCapacity))); | ||||||||||
|
|
||||||||||
| // Set stationary weights | ||||||||||
| // Street 0: weight 1.0 | ||||||||||
| network.edge(0)->setStationaryWeight(1.0); | ||||||||||
|
|
||||||||||
| // Street 1: weight 1.0 | ||||||||||
| network.edge(1)->setStationaryWeight(1.0); | ||||||||||
|
|
||||||||||
| // Street 2: weight 4.0 | ||||||||||
| network.edge(2)->setStationaryWeight(4.0); | ||||||||||
|
|
||||||||||
| // Adjust node capacities to match street capacities | ||||||||||
| network.adjustNodeCapacities(); | ||||||||||
|
|
||||||||||
| // Initialize dynamics | ||||||||||
| FirstOrderDynamics dynamics(network, false, 42, 0.0); | ||||||||||
|
|
||||||||||
| // Add many random agents to Street 0 | ||||||||||
| for (int i = 0; i < numAgents; ++i) { | ||||||||||
| auto agent = std::make_unique<Agent>(0, std::nullopt, 0); | ||||||||||
| agent->setStreetId(0); | ||||||||||
| agent->setSpeed(10.0); | ||||||||||
| agent->setFreeTime(0); | ||||||||||
| dynamics.graph().edge(0)->addAgent(std::move(agent)); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Evolve simulation | ||||||||||
| // Step 1: Agents move from Street 0 to Node 1 | ||||||||||
| dynamics.evolve(); | ||||||||||
|
|
||||||||||
| // Step 2: Agents move from Node 1 to Street 1 or 2 | ||||||||||
| dynamics.evolve(); | ||||||||||
|
|
||||||||||
| // Count agents on Street 1 and Street 2 | ||||||||||
| size_t countStreet1 = dynamics.graph().edge(1)->nAgents(); | ||||||||||
| size_t countStreet2 = dynamics.graph().edge(2)->nAgents(); | ||||||||||
|
|
||||||||||
| // Expected probabilities: | ||||||||||
| // P(1) ~ speed * speed * sqrt(1/1) = 100 | ||||||||||
| // P(2) ~ speed * speed * sqrt(4/1) = 200 | ||||||||||
|
Comment on lines
+1367
to
+1368
|
||||||||||
| // P(1) ~ speed * speed * sqrt(1/1) = 100 | |
| // P(2) ~ speed * speed * sqrt(4/1) = 200 | |
| // P(1) ~ speedCurrent * speedNext * sqrt(1/1) = 10.0 * 10.0 * 1 = 100 | |
| // P(2) ~ speedCurrent * speedNext * sqrt(4/1) = 10.0 * 10.0 * 2 = 200 |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 10.4 rule Note test
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug output statements (std::cout) should be removed from test code or replaced with proper logging. These print statements were likely used during development and should not remain in production test code as they clutter test output.
| std::cout << "Agents on Street 1: " << countStreet1 << std::endl; | |
| std::cout << "Agents on Street 2: " << countStreet2 << std::endl; | |
| std::cout << "Ratio (Street 2 / Street 1): " << ratio << std::endl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Python bindings reference
dsf::mobility::RoadNetwork::setStreetStationaryWeightsin the docstrings map (line 178), but this method has no documentation in RoadNetwork.hpp (line 194). This will cause a runtime error when loading the Python module, as the docstrings are generated from Doxygen comments and this key won't exist in the g_docstrings map. Add proper Doxygen documentation for this public API method.