Skip to content

Use edge dijkstra#499

Draft
Grufoony wants to merge 3 commits into
mainfrom
useEdgeDijkstra
Draft

Use edge dijkstra#499
Grufoony wants to merge 3 commits into
mainfrom
useEdgeDijkstra

Conversation

@Grufoony

Copy link
Copy Markdown
Owner

No description provided.

@Grufoony
Grufoony force-pushed the useEdgeDijkstra branch 2 times, most recently from e21927e to 4c681d9 Compare July 22, 2026 09:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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(...) to allEdgePathsTo(...).
  • Update several agent spawning and transition-selection call sites to treat itinerary paths and destinations as edge-based.
  • Refactor a number of std::optional usages to dereference via *opt and 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;
}
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