-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: main
Are you sure you want to change the base?
Conversation
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
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
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
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
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
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
@@ -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
@@ -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
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
a92fa72
to
8b07c33
Compare
@@ -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) { |
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.
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)); |
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.
emplace_back?
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.
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
[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
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
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
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
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
@@ -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
@@ -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
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
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
No description provided.