diff --git a/src/dsf/binding.cpp b/src/dsf/binding.cpp index a888d3db..5797cba5 100644 --- a/src/dsf/binding.cpp +++ b/src/dsf/binding.cpp @@ -298,6 +298,10 @@ PYBIND11_MODULE(dsf_cpp, m) { &dsf::FirstOrderDynamics::setWeightFunction, pybind11::arg("weightFunction"), pybind11::arg("weightThreshold") = std::nullopt) + .def("killStagnantAgents", + &dsf::FirstOrderDynamics::killStagnantAgents, + pybind11::arg("timeToleranceFactor") = 3., + dsf::g_docstrings.at("dsf::RoadDynamics::killStagnantAgents").c_str()) .def( "setDestinationNodes", [](dsf::FirstOrderDynamics& self, diff --git a/src/dsf/headers/RoadDynamics.hpp b/src/dsf/headers/RoadDynamics.hpp index 7861dd68..c4fe2235 100644 --- a/src/dsf/headers/RoadDynamics.hpp +++ b/src/dsf/headers/RoadDynamics.hpp @@ -65,6 +65,7 @@ namespace dsf { double m_maxTravelDistance; Time m_maxTravelTime; double m_weightTreshold; + std::optional m_timeToleranceFactor; std::optional m_dataUpdatePeriod; bool m_bCacheEnabled; bool m_forcePriorities; @@ -125,9 +126,16 @@ namespace dsf { /// @details The passage probability is the probability of passing through a node /// It is useful in the case of random agents void setPassageProbability(double passageProbability); - + /// @brief Set the time tolerance factor for killing stagnant agents. + /// An agent will be considered stagnant if it has not moved for timeToleranceFactor * std::ceil(street_length / street_maxSpeed) time units. + /// @param timeToleranceFactor The time tolerance factor + /// @throw std::invalid_argument If the time tolerance factor is not positive + void killStagnantAgents(double timeToleranceFactor = 3.); + /// @brief Set the weight function + /// @param pathWeight The dsf::PathWeight function to use for the pathfinding + /// @param weightThreshold The weight threshold for updating the paths (default is std::nullopt) void setWeightFunction(PathWeight const pathWeight, - std::optional weigthThreshold = std::nullopt); + std::optional weightThreshold = std::nullopt); /// @brief Set the force priorities flag /// @param forcePriorities The flag /// @details If true, if an agent cannot move to the next street, the whole node is skipped @@ -393,6 +401,7 @@ namespace dsf { m_errorProbability{std::nullopt}, m_passageProbability{std::nullopt}, m_maxTravelDistance{std::numeric_limits::max()}, + m_timeToleranceFactor{std::nullopt}, m_maxTravelTime{std::numeric_limits