Skip to content
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

Replace itineraries map with a vector #217

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Conversation

sbaldu
Copy link
Collaborator

@sbaldu sbaldu commented Nov 18, 2024

No description provided.

std::transform(itineraries.cbegin(),
itineraries.cend(),
m_itineraries.begin(),
[this](const auto& pItinerary) { return clone(pItinerary); });

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 15.5 rule Note

MISRA 15.5 rule
src/dsm/headers/Dynamics.hpp Fixed Show fixed Hide fixed
buildLog(std::format("Itinerary with id {} not found", itineraryId)));
}
assert((void("Nodes indexes out of range."),
srcNodeId < this->m_graph.nodeSet().size() &&

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.1 rule Note

MISRA 12.1 rule
std::find_if(m_itineraries.begin(),
m_itineraries.end(),
[dstNodeId](const std::unique_ptr<Itinerary>& itinerary) {
return itinerary->destination() == dstNodeId;

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 15.5 rule Note

MISRA 15.5 rule
std::find_if(m_itineraries.begin(),
m_itineraries.end(),
[dstNodeId](const std::unique_ptr<Itinerary>& itinerary) {
return itinerary->destination() == dstNodeId;

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 15.5 rule Note

MISRA 15.5 rule
this->m_path.clear();
}
Itinerary::Itinerary(Id destination, SparseMatrix<bool> path)
: m_path{std::move(path)}, m_destination{destination} {}

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
SparseMatrix<bool> m_path;
Id m_destination;

public:
/// @brief Construct a new Itinerary object
/// @param destination The itinerary's destination
Itinerary(Id id, Id destination);
Itinerary(Id destination);

Check warning

Code scanning / Cppcheck (reported by Codacy)

Class 'Itinerary' has a constructor with 1 argument that is not explicit. Warning

Class 'Itinerary' has a constructor with 1 argument that is not explicit.
@@ -176,7 +160,7 @@
graph.importMatrix("./data/matrix.dsm");
Dynamics dynamics(graph);
dynamics.setSeed(69);
Itinerary Itinerary1{0, 2}, Itinerary2{1, 1};
Itinerary Itinerary1{2}, Itinerary2{1};

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note test

MISRA 12.3 rule
@@ -351,10 +313,10 @@
CHECK(dynamics.itineraries().at(0)->path()(0, 1));
CHECK(dynamics.itineraries().at(0)->path()(1, 2));
CHECK_FALSE(dynamics.itineraries().at(0)->path()(0, 2));
for (auto const& it : dynamics.itineraries()) {
auto const& path = it.second->path();
for (auto const& itinerary : dynamics.itineraries()) {

Check warning

Code scanning / Cppcheck (reported by Codacy)

Local variable 'itinerary' shadows outer variable Warning test

Local variable 'itinerary' shadows outer variable
dynamics.addItinerary(it_2);
dynamics.addItinerary(it_3);
dynamics.updatePaths();
std::array<uint32_t, 4> destinationNodes{0, 2, 3, 4};

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note test

MISRA 12.3 rule
@sbaldu sbaldu force-pushed the rework_itineraries branch from a92fa72 to 8b07c33 Compare November 18, 2024 08:40
@@ -35,6 +35,11 @@ namespace dsm {

using TimePoint = long long unsigned int;

template <typename T>
std::unique_ptr<T> clone(const std::unique_ptr<T>& ptr) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to have a one-line function?

@@ -1142,13 +1161,13 @@ namespace dsm {
template <typename Delay>
requires(is_numeric_v<Delay>)
void Dynamics<Delay>::addItinerary(const Itinerary& itinerary) {
m_itineraries.emplace(itinerary.id(), std::make_unique<Itinerary>(itinerary));
m_itineraries.push_back(std::make_unique<Itinerary>(itinerary));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emplace_back?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

push_back should be better in this case

@@ -700,27 +707,42 @@

template <typename Delay>
requires(is_numeric_v<Delay>)
void Dynamics<Delay>::setDestinationNodes(const std::span<Id>& destinationNodes,
void Dynamics<Delay>::setDestinationNodes(std::span<Id> destinationNodes,

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
[destination](const auto& pItinerary) {
pItinerary->destination() == destination;
});
return (foundIt == m_itineraries.end()) ? nullptr : (*foundIt).get();

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 15.5 rule Note

MISRA 15.5 rule
throw std::invalid_argument(
buildLog(std::format("Node with id {} not found", nodeId)));
}
return std::make_unique<Itinerary>(nodeId);

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 15.5 rule Note

MISRA 15.5 rule
auto foundIt = std::find_if(m_itineraries.begin(),
m_itineraries.end(),
[destination](const auto& pItinerary) {
return pItinerary->destination() == destination;

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 15.5 rule Note

MISRA 15.5 rule
this->m_uniformDist(this->m_generator) > this->m_errorProbability) {
const auto& it = this->m_itineraries[this->m_agents[agentId]->itineraryId()];
const auto& it =
*std::ranges::find_if(m_itineraries, [this, agentId](const auto& ptr) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
const auto& it = this->m_itineraries[this->m_agents[agentId]->itineraryId()];
const auto& it =
*std::ranges::find_if(m_itineraries, [this, agentId](const auto& ptr) {
return ptr->destination() == m_agents[agentId]->itineraryId();

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 15.5 rule Note

MISRA 15.5 rule
@@ -492,7 +500,9 @@
}
}
if (destinationNode->id() ==
m_itineraries[m_agents[agentId]->itineraryId()]->destination()) {
(*std::ranges::find_if(m_itineraries, [this, agentId](const auto& ptr) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
@@ -492,7 +500,9 @@
}
}
if (destinationNode->id() ==
m_itineraries[m_agents[agentId]->itineraryId()]->destination()) {
(*std::ranges::find_if(m_itineraries, [this, agentId](const auto& ptr) {
return m_agents[agentId]->itineraryId() == ptr->destination();

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 15.5 rule Note

MISRA 15.5 rule
if (this->m_itineraries[agent->itineraryId()]->destination() ==
street->nodePair().second) {

if ((*std::ranges::find_if(m_itineraries, [&agent](const auto& ptr) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
street->nodePair().second) {

if ((*std::ranges::find_if(m_itineraries, [&agent](const auto& ptr) {
return ptr->destination() == agent->itineraryId();

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 15.5 rule Note

MISRA 15.5 rule
src/dsm/headers/Dynamics.hpp Fixed Show fixed Hide fixed
src/dsm/headers/Dynamics.hpp Fixed Show fixed Hide fixed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants