Skip to content

Commit

Permalink
fix #14468
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Mar 14, 2024
1 parent da269ff commit 6724c56
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/libsumo/Vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1126,12 +1126,10 @@ Vehicle::replaceStop(const std::string& vehID,
if (edgeID == "") {
// only remove stop
const bool ok = vehicle->abortNextStop(nextStopIndex);
if ((teleport & 2) != 0) {
if (teleport != 0) {
if (!vehicle->rerouteBetweenStops(nextStopIndex, "traci:replaceStop", (teleport & 1), error)) {
throw TraCIException("Stop replacement failed for vehicle '" + vehID + "' (" + error + ").");
}
} else if (teleport != 0) {
WRITE_WARNINGF(TL("Stop replacement parameter 'teleport=%' ignored for vehicle '%' when only removing stop."), toString(teleport), vehID);
}
if (!ok) {
throw TraCIException("Stop replacement failed for vehicle '" + vehID + "' (invalid nextStopIndex).");
Expand Down
46 changes: 46 additions & 0 deletions src/microsim/MSBaseVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,8 @@ MSBaseVehicle::rerouteBetweenStops(int nextStopIndex, const std::string& info, b
}
const SUMOTime t = MSNet::getInstance()->getCurrentTimeStep();

auto itStop = myStops.begin();
std::advance(itStop, nextStopIndex);
const ConstMSEdgeVector& oldEdges = getRoute().getEdges();
std::vector<MSStop> stops(myStops.begin(), myStops.end());
const int junctionOffset = getLane() != nullptr && getLane()->isInternal() ? 1 : 0;
Expand Down Expand Up @@ -1789,6 +1791,50 @@ MSBaseVehicle::rerouteBetweenStops(int nextStopIndex, const std::string& info, b
const double routeCost = router.recomputeCosts(newEdges, this, t);
const double previousCost = router.recomputeCosts(oldRemainingEdges, this, t);
const double savings = previousCost - routeCost;

if (teleport) {
// let the vehicle jump rather than teleport
// we add a jump-stop at the end of the edge (unless the vehicle is
// already configure to jump before the replaced stop)
bool needJump = true;
if (nextStopIndex > 0) {
auto itPriorStop = myStops.begin();
std::advance(itPriorStop, nextStopIndex - 1);
const MSStop& priorStop = *itPriorStop;
if (priorStop.pars.jump >= 0) {
needJump = false;
}
}
if (needJump) {
SUMOVehicleParameter::Stop jumpStopPars;
jumpStopPars.endPos = (*itStart)->getLength();
jumpStopPars.speed = 1000;
jumpStopPars.jump = 0;
jumpStopPars.edge = (*itStart)->getID();
jumpStopPars.parametersSet = STOP_SPEED_SET | STOP_JUMP_SET;
MSLane* jumpStopLane = nullptr;
for (MSLane* cand : (*itStart)->getLanes()) {
if (cand->allowsVehicleClass(getVClass())) {
jumpStopLane = cand;
break;
}
}
if (jumpStopLane == nullptr) {
errorMsg = "Unable to replace stop with teleporting\n";
return false;
}
MSStop jumpStop(jumpStopPars);
jumpStop.initPars(jumpStopPars);
jumpStop.lane = jumpStopLane;
jumpStop.edge = myRoute->end(); // will be patched in replaceRoute
myStops.insert(itStop, jumpStop);
if (!hasDeparted() && (int)myParameter->stops.size() > nextStopIndex) {
// stops will be rebuilt from scratch so we must patch the stops in myParameter
auto it = myParameter->stops.begin() + nextStopIndex;
const_cast<SUMOVehicleParameter*>(myParameter)->stops.insert(it, jumpStopPars);
}
}
}
return replaceRouteEdges(newEdges, routeCost, savings, info, !hasDeparted(), false, false, &errorMsg);
}

Expand Down

0 comments on commit 6724c56

Please sign in to comment.