Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
Command_RouteReplacement.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
19// Writes the state of the tls to a file (in each second)
20/****************************************************************************/
21#include <config.h>
22
24#include <microsim/MSNet.h>
26#include <microsim/MSRoute.h>
27#include <microsim/MSGlobals.h>
29
30
31// ===========================================================================
32// method definitions
33// ===========================================================================
35 myVehID(vehID),
36 myRoute(route) {
37}
38
39
41
42
46 // if the vehicle is not available anymore, silently ignore replacement
47 if (veh != nullptr) {
48 std::string errorPrefix = ("Replayed route replacement failed for vehicle '"
49 + veh->getID() + "' route=" + myRoute->getID() + " time=" + time2string(SIMSTEP));
50 std::string msg;
51 if (!veh->hasValidRoute(msg, myRoute)) {
52 WRITE_WARNING("Invalid route replacement for vehicle '" + veh->getID() + "'. " + msg);
54 throw ProcessError(errorPrefix + ".");
55 }
56 }
57 std::string errorMsg;
58 if (!veh->replaceRoute(myRoute, "replayRerouting", veh->getLane() == nullptr,
59 veh->getRoute().getReplacedIndex(), true, true, &errorMsg)) {
60 throw ProcessError(errorPrefix + " (" + errorMsg + ").");
61 }
62 }
63 return 0;
64}
65
66
67/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define WRITE_WARNING(msg)
Definition MsgHandler.h:295
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition Route.h:32
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:69
#define SIMSTEP
Definition SUMOTime.h:61
Command_RouteReplacement(const std::string &vehID, ConstMSRoutePtr route)
Constructor.
SUMOTime execute(SUMOTime currentTime)
toggles override
ConstMSRoutePtr myRoute
The replacement route.
std::string myVehID
The id of the vehicle to be rerouted.
static bool gCheckRoutes
Definition MSGlobals.h:91
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:186
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:378
int getReplacedIndex() const
Returns the index at which this route was replaced.
Definition MSRoute.h:193
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
const std::string & getID() const
Returns the id.
Definition Named.h:74
virtual const MSLane * getLane() const =0
Returns the lane the object is currently at.
virtual bool replaceRoute(ConstMSRoutePtr route, const std::string &info, bool onInit=false, int offset=0, bool addStops=true, bool removeStops=true, std::string *msgReturn=nullptr)=0
Replaces the current route by the given one.
Representation of a vehicle.
Definition SUMOVehicle.h:62
virtual bool hasValidRoute(std::string &msg, ConstMSRoutePtr route=0) const =0
Validates the current or given route.
virtual const MSRoute & getRoute() const =0
Returns the current route.