Skip to content

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
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
/// @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.
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
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
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?

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

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
}
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
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
@Grufoony
Copy link
Collaborator

Better to keep it as a map

@Grufoony Grufoony closed this Feb 14, 2025
@Grufoony Grufoony deleted the rework_itineraries branch February 14, 2025 10:11
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.

3 participants