Path: blob/main/src/microsim/Command_RouteReplacement.cpp
185785 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file Command_RouteReplacement.cpp14/// @author Daniel Krajzewicz15/// @author Michael Behrisch16/// @date 15 Feb 200417///18// Writes the state of the tls to a file (in each second)19/****************************************************************************/20#include <config.h>2122#include <utils/vehicle/SUMOVehicle.h>23#include <microsim/MSNet.h>24#include <microsim/MSVehicleControl.h>25#include <microsim/MSRoute.h>26#include <microsim/MSGlobals.h>27#include "Command_RouteReplacement.h"282930// ===========================================================================31// method definitions32// ===========================================================================33Command_RouteReplacement::Command_RouteReplacement(const std::string& vehID, ConstMSRoutePtr route) :34myVehID(vehID),35myRoute(route) {36}373839Command_RouteReplacement::~Command_RouteReplacement() { }404142SUMOTime43Command_RouteReplacement::execute(SUMOTime /*currentTime*/) {44SUMOVehicle* veh = MSNet::getInstance()->getVehicleControl().getVehicle(myVehID);45// if the vehicle is not available anymore, silently ignore replacement46if (veh != nullptr) {47std::string errorPrefix = ("Replayed route replacement failed for vehicle '"48+ veh->getID() + "' route=" + myRoute->getID() + " time=" + time2string(SIMSTEP));49std::string msg;50if (!veh->hasValidRoute(msg, myRoute)) {51WRITE_WARNING("Invalid route replacement for vehicle '" + veh->getID() + "'. " + msg);52if (MSGlobals::gCheckRoutes) {53throw ProcessError(errorPrefix + ".");54}55}56std::string errorMsg;57if (!veh->replaceRoute(myRoute, "replayRerouting", veh->getLane() == nullptr,58veh->getRoute().getReplacedIndex(), true, true, &errorMsg)) {59throw ProcessError(errorPrefix + " (" + errorMsg + ").");60}61}62return 0;63}646566/****************************************************************************/676869