Skip to content

Commit cb5ab44

Browse files
committed
Bugfix: wrong nullopt return in m_nextStreetId
1 parent b69b859 commit cb5ab44

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

src/dsf/mobility/RoadDynamics.hpp

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -532,18 +532,21 @@ namespace dsf::mobility {
532532
double cumulativeProbability = 0.0;
533533
534534
for (const auto outEdgeId : outgoingEdges) {
535-
if (forbiddenTurns.contains(outEdgeId)) {
536-
continue;
537-
}
538-
539535
auto const& pStreetOut{this->graph().edge(outEdgeId)};
540536
541537
// Check if this is a valid path target for non-random agents
542-
bool bIsPathTarget = true;
538+
bool bIsPathTarget = false;
543539
if (!pathTargets.empty()) {
544540
bIsPathTarget =
545541
std::find(pathTargets.cbegin(), pathTargets.cend(), pStreetOut->target()) !=
546542
pathTargets.cend();
543+
}
544+
545+
if (forbiddenTurns.contains(outEdgeId) && !bIsPathTarget) {
546+
continue;
547+
}
548+
549+
if (!pathTargets.empty()) {
547550
if (!this->m_errorProbability.has_value() && !bIsPathTarget) {
548551
continue;
549552
}
@@ -566,7 +569,7 @@ namespace dsf::mobility {
566569
if (previousNodeId.has_value() && pStreetOut->target() == previousNodeId.value()) {
567570
if (pNode->isRoundabout()) {
568571
probability *= U_TURN_PENALTY_FACTOR;
569-
} else {
572+
} else if (!bIsPathTarget) {
570573
continue; // No U-turns allowed
571574
}
572575
}
@@ -577,11 +580,16 @@ namespace dsf::mobility {
577580
578581
// Select street based on weighted probabilities
579582
if (transitionProbabilities.empty()) {
580-
spdlog::trace("No valid transitions found for {} at {}", *pAgent, *pNode);
583+
spdlog::debug("No valid transitions found for {} at {}", *pAgent, *pNode);
581584
return std::nullopt;
582585
}
583586
if (transitionProbabilities.size() == 1) {
584-
return transitionProbabilities.cbegin()->first;
587+
auto const& onlyStreetId = transitionProbabilities.cbegin()->first;
588+
spdlog::debug("Only one valid transition for {} at {}: street {}",
589+
*pAgent,
590+
*pNode,
591+
onlyStreetId);
592+
return onlyStreetId;
585593
}
586594
587595
std::uniform_real_distribution<double> uniformDist{0., cumulativeProbability};
@@ -594,7 +602,10 @@ namespace dsf::mobility {
594602
}
595603
}
596604
// Return last one as fallback
597-
return std::prev(transitionProbabilities.cend())->first;
605+
auto const fallbackStreetId = std::prev(transitionProbabilities.cend())->first;
606+
spdlog::debug(
607+
"Fallback selection for {} at {}: street {}", *pAgent, *pNode, fallbackStreetId);
608+
return fallbackStreetId;
598609
}
599610
600611
template <typename delay_t>
@@ -685,15 +696,15 @@ namespace dsf::mobility {
685696
if (pStreet->isStochastic() &&
686697
uniformDist(this->m_generator) >
687698
dynamic_cast<StochasticStreet&>(*pStreet).flowRate()) {
688-
spdlog::debug("Skipping due to flow rate {:.2f} < random value",
699+
spdlog::trace("Skipping due to flow rate {:.2f} < random value",
689700
dynamic_cast<StochasticStreet&>(*pStreet).flowRate());
690701
continue;
691702
}
692703
if (i == std::ceil(transportCapacity) - 1) {
693704
double integral;
694705
double fractional = std::modf(transportCapacity, &integral);
695706
if (fractional != 0. && uniformDist(this->m_generator) > fractional) {
696-
spdlog::debug("Skipping due to fractional capacity {:.2f} < random value",
707+
spdlog::trace("Skipping due to fractional capacity {:.2f} < random value",
697708
fractional);
698709
continue;
699710
}
@@ -705,7 +716,7 @@ namespace dsf::mobility {
705716
// Logger::debug("Taking temp agent");
706717
auto const& pAgentTemp{pStreet->queue(queueIndex).front()};
707718
if (pAgentTemp->freeTime() > this->time_step()) {
708-
spdlog::debug("Skipping due to time {} < free time {}",
719+
spdlog::trace("Skipping due to time {} < free time {}",
709720
this->time_step(),
710721
pAgentTemp->freeTime());
711722
continue;
@@ -734,14 +745,14 @@ namespace dsf::mobility {
734745
pAgentTemp->setSpeed(0.);
735746
const auto& destinationNode{this->graph().node(pStreet->target())};
736747
if (destinationNode->isFull()) {
737-
spdlog::debug("Skipping due to full destination node {}", *destinationNode);
748+
spdlog::trace("Skipping due to full destination node {}", *destinationNode);
738749
continue;
739750
}
740751
if (destinationNode->isTrafficLight()) {
741752
auto& tl = dynamic_cast<TrafficLight&>(*destinationNode);
742753
auto const direction{pStreet->laneMapping().at(queueIndex)};
743754
if (!tl.isGreen(pStreet->id(), direction)) {
744-
spdlog::debug("Skipping due to red light on street {} and direction {}",
755+
spdlog::trace("Skipping due to red light on street {} and direction {}",
745756
pStreet->id(),
746757
directionToString.at(direction));
747758
continue;

0 commit comments

Comments
 (0)