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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ cmake --build build -j$(nproc)

To run the tests use the command:
```shell
ctest --test-dir build -j$(nproc)
ctest --test-dir build -j$(nproc) --output-on-failure
```

## Benchmarking
Expand Down
17 changes: 17 additions & 0 deletions src/dsf/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@
dsf::g_docstrings.at("dsf::mobility::RoadDynamics::setDestinationNodes").c_str())
.def(
"setDestinationNodes",
[](dsf::mobility::FirstOrderDynamics& self,

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
const std::unordered_map<dsf::Id, double>& destinationNodes) {
self.setDestinationNodes(destinationNodes);
},
Expand All @@ -482,6 +482,23 @@
pybind11::arg("nAgents"),
pybind11::arg("itineraryId") = std::nullopt,
dsf::g_docstrings.at("dsf::mobility::RoadDynamics::addAgentsUniformly").c_str())
.def(
"addRandomAgents",
[](dsf::mobility::FirstOrderDynamics& self, std::size_t nAgents) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
self.addRandomAgents(nAgents);
},
pybind11::arg("nAgents"),
dsf::g_docstrings.at("dsf::mobility::RoadDynamics::addRandomAgents").c_str())
.def(
"addRandomAgents",
[](dsf::mobility::FirstOrderDynamics& self,
std::size_t nAgents,

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
const std::unordered_map<dsf::Id, double>& src_weights) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
self.addRandomAgents(nAgents, src_weights);
},
pybind11::arg("nAgents"),
pybind11::arg("src_weights"),
dsf::g_docstrings.at("dsf::mobility::RoadDynamics::addRandomAgents").c_str())
.def(
"addAgentsRandomly",
[](dsf::mobility::FirstOrderDynamics& self, dsf::Size nAgents) {
Expand Down
2 changes: 1 addition & 1 deletion src/dsf/dsf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

static constexpr uint8_t DSF_VERSION_MAJOR = 4;
static constexpr uint8_t DSF_VERSION_MINOR = 4;
static constexpr uint8_t DSF_VERSION_PATCH = 2;
static constexpr uint8_t DSF_VERSION_PATCH = 3;

static auto const DSF_VERSION =
std::format("{}.{}.{}", DSF_VERSION_MAJOR, DSF_VERSION_MINOR, DSF_VERSION_PATCH);
Expand Down
12 changes: 9 additions & 3 deletions src/dsf/mobility/Agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,21 @@
void Agent::setSrcNodeId(Id srcNodeId) { m_srcNodeId = srcNodeId; }
void Agent::setStreetId(std::optional<Id> streetId) {
if (!streetId.has_value()) {
assert(m_nextStreetId.has_value());
if (!m_nextStreetId.has_value()) {
throw std::logic_error(std::format(
"Agent {} has no next street id to set the current street id to", m_id));
}
m_streetId = std::exchange(m_nextStreetId, std::nullopt);
return;
}
assert(m_nextStreetId.has_value() ? streetId == m_nextStreetId.value() : true);
if (m_nextStreetId.has_value()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 14.4 rule Note

MISRA 14.4 rule
throw std::logic_error(std::format(
"Agent {} has a next street id already set, cannot set street id directly",
m_id));
}
m_streetId = streetId;
m_nextStreetId = std::nullopt;
}
void Agent::setNextStreetId(Id nextStreetId) { m_nextStreetId = nextStreetId; }
void Agent::setSpeed(double speed) {
if (speed < 0.) {
throw std::invalid_argument(
Expand Down
6 changes: 2 additions & 4 deletions src/dsf/mobility/Agent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace dsf::mobility {
void setStreetId(std::optional<Id> streetId = std::nullopt);
/// @brief Set the id of the next street
/// @param nextStreetId The id of the next street
void setNextStreetId(Id nextStreetId);
inline auto setNextStreetId(Id nextStreetId) { m_nextStreetId = nextStreetId; }
/// @brief Set the agent's speed
/// @param speed, The agent's speed
/// @throw std::invalid_argument, if speed is negative
Expand Down Expand Up @@ -127,8 +127,6 @@ struct std::formatter<dsf::mobility::Agent> {
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const dsf::mobility::Agent& agent, FormatContext&& ctx) const {
auto const strItinerary = agent.trip().empty() ? std::string("RANDOM")
: std::to_string(agent.itineraryId());
return std::format_to(
ctx.out(),
"Agent(id: {}, streetId: {}, srcNodeId: {}, nextStreetId: {}, "
Expand All @@ -139,7 +137,7 @@ struct std::formatter<dsf::mobility::Agent> {
agent.srcNodeId().has_value() ? std::to_string(agent.srcNodeId().value()) : "N/A",
agent.nextStreetId().has_value() ? std::to_string(agent.nextStreetId().value())
: "N/A",
strItinerary,
agent.isRandom() ? std::string("RANDOM") : std::to_string(agent.itineraryId()),
agent.speed(),
agent.distance(),
agent.spawnTime(),
Expand Down
5 changes: 2 additions & 3 deletions src/dsf/mobility/FirstOrderDynamics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ namespace dsf::mobility {
double m_alpha;
double m_speedFluctuationSTD;

double m_speedFactor(double const& density) const;
double m_speedFactor(double const& density) const final;

double m_streetEstimatedTravelTime(
std::unique_ptr<Street> const& pStreet) const override;
double m_streetEstimatedTravelTime(std::unique_ptr<Street> const& pStreet) const final;

public:
/// @brief Construct a new First Order Dynamics object
Expand Down
Loading
Loading