Use edge dijkstra#499
Draft
Grufoony wants to merge 3 commits into
Draft
Conversation
Grufoony
force-pushed
the
useEdgeDijkstra
branch
2 times, most recently
from
July 22, 2026 09:50
e21927e to
4c681d9
Compare
Grufoony
force-pushed
the
useEdgeDijkstra
branch
from
July 22, 2026 13:31
4c681d9 to
75d6b64
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR appears to migrate mobility routing and agent decision-making from node-based shortest paths to edge-based shortest paths (“edge dijkstra”), updating itinerary path generation, next-street selection, and OD-import/spawn logic accordingly.
Changes:
- Switch itinerary path computation from
allPathsTo(...)toallEdgePathsTo(...). - Update several agent spawning and transition-selection call sites to treat itinerary paths and destinations as edge-based.
- Refactor a number of
std::optionalusages to dereference via*optand add additional runtime checks/throws in evolve logic.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 10 comments.
| File | Description |
|---|---|
| src/dsf/mobility/Street.cpp | Minor std::optional dereference change when applying speedFactor. |
| src/dsf/mobility/FirstOrderDynamics.cpp | Main routing migration: edge-path computation, spawning/origin handling, next-street selection, OD import updates, and additional runtime checks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
37
to
41
| auto const oldSize{pItinerary->path().size()}; | ||
|
|
||
| auto const path{this->graph().allPathsTo(pItinerary->destination())}; | ||
| auto const path{this->graph().allEdgePathsTo(pItinerary->destination())}; | ||
| pItinerary->setPath(path); | ||
| auto const newSize{pItinerary->path().size()}; |
Comment on lines
60
to
64
| if (m_originNodes.size() == 1) { | ||
| auto [originId, weight] = m_originNodes.at(0); | ||
| this->addAgents(nAgents, nullptr, originId); | ||
| auto const [originId, weight] = m_originNodes.at(0); | ||
| auto const originNodeId{this->graph().edge(originId).target()}; | ||
| this->addAgents(nAgents, nullptr, originNodeId); | ||
| return; |
Comment on lines
69
to
75
| } else { | ||
| auto randValue{uniformDist(this->m_generator)}; | ||
| for (auto const& [origin, weight] : m_originNodes) { | ||
| for (auto const [origin, weight] : m_originNodes) { | ||
| if (randValue < weight) { | ||
| this->addAgent(nullptr, origin); | ||
| auto const originNodeId{this->graph().edge(origin).target()}; | ||
| this->addAgent(nullptr, originNodeId); | ||
| break; |
Comment on lines
303
to
312
| auto const& itinerary = itineraryIt->second; | ||
| if (!itinerary->path().contains(originId)) { | ||
| spdlog::debug("Destination {} not reachable from origin {}. Skipping agent.", | ||
| destinationId, | ||
| originId); | ||
| continue; | ||
| } | ||
| this->addAgent(itineraryIt->second, originId); | ||
| auto const originNodeId{this->graph().edge(originId).source()}; | ||
| this->addAgent(itineraryIt->second, originNodeId); | ||
| } |
Comment on lines
+401
to
405
| if (currentStreetIdOpt.has_value()) { | ||
| auto const* pStreetCurrent{&this->graph().edge(*currentStreetIdOpt)}; | ||
| previousNodeId = pStreetCurrent->source(); | ||
| forbiddenTurns = pStreetCurrent->forbiddenTurns(); | ||
| } | ||
|
|
Comment on lines
432
to
436
| // Check if this is a valid path target for non-random agents | ||
| bool bIsPathTarget = false; | ||
| bIsPathTarget = | ||
| std::find(pathTargets.cbegin(), pathTargets.cend(), streetOut.target()) != | ||
| std::find(pathTargets.cbegin(), pathTargets.cend(), streetOut.id()) != | ||
| pathTargets.cend(); |
Comment on lines
479
to
487
| bool bArrived{false}; | ||
| if (!pAgent->isRandom()) { | ||
| if (pAgent->itinerary()->destination() == pStreet->target()) { | ||
| auto const& dstStreet{this->graph().edge(pAgent->itinerary()->destination())}; | ||
| if (dstStreet.source() == pStreet->target()) { | ||
| pAgent->updateItinerary(); | ||
| } | ||
| if (pAgent->itinerary()->destination() == pStreet->target()) { | ||
| if (dstStreet.source() == pStreet->target()) { | ||
| bArrived = true; | ||
| } |
Comment on lines
755
to
759
| if (!pAgentTemp->isRandom()) { | ||
| if (destinationNode->id() == pAgentTemp->itinerary()->destination()) { | ||
| auto const& dstStreet{this->graph().edge(pAgentTemp->itinerary()->destination())}; | ||
| if (destinationNode->id() == dstStreet.source()) { | ||
| bArrived = true; | ||
| spdlog::debug("Agent {} has arrived at destination node {}", |
Comment on lines
+1173
to
+1177
| this->graph().edges().end(), | ||
| [&](auto const& edgePair) { | ||
| auto const pathCollection = this->graph().allEdgePathsTo(edgePair.first); | ||
| allPaths.emplace(edgePair.first, std::move(pathCollection)); | ||
| }); |
Comment on lines
+1214
to
+1223
| try { | ||
| auto const path = allPaths.at(targetEdgeId) | ||
| .explode(sourceEdgeId, targetEdgeId) | ||
| .front(); | ||
| if (bestPath.empty() || path.size() < bestPath.size()) { | ||
| bestPath = std::move(path); | ||
| } | ||
| } catch (...) { | ||
| continue; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.