Skip to content

Commit

Permalink
special handling for looped lines. refs #14343
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Mar 16, 2024
1 parent 023309a commit 74773a7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/utils/router/IntermodalNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,9 @@ class IntermodalNetwork {
lastStop = currStop;
lastPos = stopPos;
}
if (pars.line != "taxi" && validStops.front().busstop == validStops.back().busstop) {
myLoopedLines.insert(pars.line);
}
} else {
if (validStops.size() != lineEdges.size() + 1) {
WRITE_WARNINGF("Number of stops for public transport line '%' does not match earlier definitions, ignoring schedule.", pars.line);
Expand Down Expand Up @@ -746,6 +749,10 @@ class IntermodalNetwork {
access->addSuccessor(to);
}

bool isLooped(const std::string lineID) const {
return myLoopedLines.count(lineID) != 0;
}

private:
/** @brief Returns where to insert or use the split edge
*
Expand Down Expand Up @@ -870,6 +877,9 @@ class IntermodalNetwork {
/// @brief retrieve the splitted edges for the given "original"
std::map<_IntermodalEdge*, std::vector<_IntermodalEdge*> > myAccessSplits;

/// @brief looped lines need extra checking when building itineraries
std::set<std::string > myLoopedLines;

int myNumericalID;
const int myCarWalkTransfer;

Expand Down
24 changes: 22 additions & 2 deletions src/utils/router/IntermodalRouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ class IntermodalRouter : public SUMOAbstractRouter<E, IntermodalTrip<E, N, V> >
const bool success = myInternalRouter->compute(iFrom, iTo, &trip, msTime, intoEdges, true);
if (success) {
std::string lastLine = "";
const _IntermodalEdge* lastLineEdge = nullptr;
double lastLineTime = STEPS2TIME(msTime);
double time = STEPS2TIME(msTime);
double effort = 0.;
double length = 0.;
Expand All @@ -147,8 +149,10 @@ class IntermodalRouter : public SUMOAbstractRouter<E, IntermodalTrip<E, N, V> >
into.back().destStop = iEdge->getID();
}
} else {
if (iEdge->getLine() != lastLine) {
if (iEdge->getLine() != lastLine || loopedLineTransfer(lastLineEdge, iEdge, lastLineTime, time)) {
lastLine = iEdge->getLine();
lastLineEdge = iEdge;
lastLineTime = time;
if (lastLine == "!car") {
into.push_back(TripItem(vehicle->getID()));
into.back().vType = vehicle->getParameter().vtypeid;
Expand All @@ -167,7 +171,9 @@ class IntermodalRouter : public SUMOAbstractRouter<E, IntermodalTrip<E, N, V> >
}
}
}
const double prevTime = time, prevEffort = effort, prevLength = length;
const double prevTime = time;
const double prevEffort = effort;
const double prevLength = length;
myInternalRouter->updateViaCost(prev, iEdge, &trip, time, effort, length);
// correct intermodal length:
length += iEdge->getPartialLength(&trip) - iEdge->getLength();
Expand Down Expand Up @@ -322,6 +328,20 @@ class IntermodalRouter : public SUMOAbstractRouter<E, IntermodalTrip<E, N, V> >
}
}


bool loopedLineTransfer(const _IntermodalEdge* prev, const _IntermodalEdge* cur, double prevTime, double time) {
assert(prev != nullptr);
if (myIntermodalNet->isLooped(cur->getLine())) {
// check if the last two edges are served by different vehicles
std::string intended1;
std::string intended2;
prev->getIntended(prevTime, intended1);
cur->getIntended(time, intended2);
return intended1 != intended2;
}
return false;
}

private:
const bool myAmClone;
_InternalRouter* myInternalRouter;
Expand Down

0 comments on commit 74773a7

Please sign in to comment.