void MSBaseVehicle::reroute(SUMOTime t, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, const bool onInit, const bool withTaz) { // check whether to reroute const MSEdge* source = withTaz && onInit ? MSEdge::dictionary(myParameter->fromTaz + "-source") : getRerouteOrigin(); if (source == 0) { source = getRerouteOrigin(); } const MSEdge* sink = withTaz ? MSEdge::dictionary(myParameter->toTaz + "-sink") : myRoute->getLastEdge(); if (sink == 0) { sink = myRoute->getLastEdge(); } ConstMSEdgeVector edges; const ConstMSEdgeVector stops = getStopEdges(); for (MSRouteIterator s = stops.begin(); s != stops.end(); ++s) { if (*s != source) { // !!! need to adapt t here router.compute(source, *s, this, t, edges); source = *s; edges.pop_back(); } } router.compute(source, sink, this, t, edges); if (!edges.empty() && edges.front()->getPurpose() == MSEdge::EDGEFUNCTION_DISTRICT) { edges.erase(edges.begin()); } if (!edges.empty() && edges.back()->getPurpose() == MSEdge::EDGEFUNCTION_DISTRICT) { edges.pop_back(); } replaceRouteEdges(edges, onInit); }
void GUIVehicle::rerouteDRTStop(MSStoppingPlace* busStop) { SUMOTime intermediateDuration = TIME2STEPS(20); SUMOTime finalDuration = SUMOTime_MAX; if (myParameter->stops.size() >= 2) { // copy durations from the original stops intermediateDuration = myParameter->stops.front().duration; finalDuration = myParameter->stops.back().duration; } // if the stop is already in the list of stops, cancel all stops that come // after it and set the stop duration std::string line = ""; int destinations = 0; bool add = true; for (auto it = myStops.begin(); it != myStops.end(); it++) { if (!it->reached && destinations < 2 && it->busstop != nullptr) { line += it->busstop->getID(); destinations++; } if (it->busstop == busStop) { it->duration = finalDuration; myStops.erase(++it, myStops.end()); add = false; break; } else { it->duration = MIN2(it->duration, intermediateDuration); } } if (destinations < 2) { line += busStop->getID(); } if (add) { // create new stop SUMOVehicleParameter::Stop stopPar; stopPar.busstop = busStop->getID(); stopPar.lane = busStop->getLane().getID(); stopPar.startPos = busStop->getBeginLanePosition(); stopPar.endPos = busStop->getEndLanePosition(); stopPar.duration = finalDuration; stopPar.until = -1; stopPar.triggered = false; stopPar.containerTriggered = false; stopPar.parking = false; stopPar.index = STOP_INDEX_FIT; stopPar.parametersSet = STOP_START_SET | STOP_END_SET; // clean up prior route to improve visualisation, ensure that the stop can be added immediately ConstMSEdgeVector edges = myRoute->getEdges(); edges.erase(edges.begin(), edges.begin() + getRoutePosition()); edges.push_back(&busStop->getLane().getEdge()); replaceRouteEdges(edges, -1, 0, "DRT.tmp", false, false, false); std::string errorMsg; // add stop addStop(stopPar, errorMsg); } const bool hasReroutingDevice = getDevice(typeid(MSDevice_Routing)) != nullptr; SUMOAbstractRouter<MSEdge, SUMOVehicle>& router = hasReroutingDevice ? MSRoutingEngine::getRouterTT() : MSNet::getInstance()->getRouterTT(); // reroute to ensure the new stop is reached reroute(MSNet::getInstance()->getCurrentTimeStep(), "DRT", router); myParameter->line = line; assert(haveValidStopEdges()); }