Skip to content

Commit

Permalink
fix #14789
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Apr 29, 2024
1 parent a865199 commit 059e8d4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
14 changes: 2 additions & 12 deletions src/libsumo/Vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1435,20 +1435,10 @@ Vehicle::changeTarget(const std::string& vehID, const std::string& edgeID) {
if (destEdge == nullptr) {
throw TraCIException("Destination edge '" + edgeID + "' is not known.");
}
// build a new route between the vehicle's current edge and destination edge
ConstMSEdgeVector newRoute;
const MSEdge* currentEdge = *veh->getRerouteOrigin();
veh->getRouterTT().compute(
currentEdge, destEdge, veh, MSNet::getInstance()->getCurrentTimeStep(), newRoute);
// replace the vehicle's route by the new one (cost is updated by call to reroute())
std::string errorMsg;
if (!veh->replaceRouteEdges(newRoute, -1, 0, "traci:changeTarget", onInit, false, true, &errorMsg)) {
throw TraCIException("Route replacement failed for vehicle '" + veh->getID() + "' (" + errorMsg + ").");
}
// route again to ensure usage of via/stops
// change the final edge of the route and reroute
try {
veh->reroute(MSNet::getInstance()->getCurrentTimeStep(), "traci:changeTarget",
veh->getRouterTT(), onInit);
veh->getRouterTT(), onInit, false, false, destEdge);
} catch (ProcessError& e) {
throw TraCIException(e.what());
}
Expand Down
8 changes: 5 additions & 3 deletions src/microsim/MSBaseVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,17 @@ MSBaseVehicle::stopsAtEdge(const MSEdge* edge) const {


void
MSBaseVehicle::reroute(SUMOTime t, const std::string& info, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, const bool onInit, const bool withTaz, const bool silent) {
MSBaseVehicle::reroute(SUMOTime t, const std::string& info, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, const bool onInit, const bool withTaz, const bool silent, const MSEdge* sink) {
// check whether to reroute
const MSEdge* source = withTaz && onInit ? MSEdge::dictionary(myParameter->fromTaz + "-source") : *getRerouteOrigin();
if (source == nullptr) {
source = *getRerouteOrigin();
}
const MSEdge* sink = withTaz ? MSEdge::dictionary(myParameter->toTaz + "-sink") : myRoute->getLastEdge();
if (sink == nullptr) {
sink = myRoute->getLastEdge();
sink = withTaz ? MSEdge::dictionary(myParameter->toTaz + "-sink") : myRoute->getLastEdge();
if (sink == nullptr) {
sink = myRoute->getLastEdge();
}
}
ConstMSEdgeVector oldEdgesRemaining(source == *myCurrEdge ? myCurrEdge : myCurrEdge + 1, myRoute->end());
ConstMSEdgeVector edges;
Expand Down
3 changes: 2 additions & 1 deletion src/microsim/MSBaseVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,10 @@ class MSBaseVehicle : public SUMOVehicle {
*
* @param[in] t The time for which the route is computed
* @param[in] router The router to use
* @param[in] sink (optionally) a new destination edge
* @see replaceRoute
*/
void reroute(SUMOTime t, const std::string& info, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, const bool onInit = false, const bool withTaz = false, const bool silent = false);
void reroute(SUMOTime t, const std::string& info, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, const bool onInit = false, const bool withTaz = false, const bool silent = false, const MSEdge* sink = nullptr);


/** @brief Replaces the current route by the given edges
Expand Down
2 changes: 1 addition & 1 deletion src/utils/vehicle/SUMOVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class SUMOVehicle : public SUMOTrafficObject {
* @param[in] router The router to use
* @see replaceRoute
*/
virtual void reroute(SUMOTime t, const std::string& info, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, const bool onInit = false, const bool withTaz = false, const bool silent = false) = 0;
virtual void reroute(SUMOTime t, const std::string& info, SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, const bool onInit = false, const bool withTaz = false, const bool silent = false, const MSEdge* sink = nullptr) = 0;

/** @brief Validates the current or given route
* @param[out] msg Description why the route is not valid (if it is the case)
Expand Down

0 comments on commit 059e8d4

Please sign in to comment.