Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/microsim/Command_RouteReplacement.cpp
185785 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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
/****************************************************************************/
14
/// @file Command_RouteReplacement.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Michael Behrisch
17
/// @date 15 Feb 2004
18
///
19
// Writes the state of the tls to a file (in each second)
20
/****************************************************************************/
21
#include <config.h>
22
23
#include <utils/vehicle/SUMOVehicle.h>
24
#include <microsim/MSNet.h>
25
#include <microsim/MSVehicleControl.h>
26
#include <microsim/MSRoute.h>
27
#include <microsim/MSGlobals.h>
28
#include "Command_RouteReplacement.h"
29
30
31
// ===========================================================================
32
// method definitions
33
// ===========================================================================
34
Command_RouteReplacement::Command_RouteReplacement(const std::string& vehID, ConstMSRoutePtr route) :
35
myVehID(vehID),
36
myRoute(route) {
37
}
38
39
40
Command_RouteReplacement::~Command_RouteReplacement() { }
41
42
43
SUMOTime
44
Command_RouteReplacement::execute(SUMOTime /*currentTime*/) {
45
SUMOVehicle* veh = MSNet::getInstance()->getVehicleControl().getVehicle(myVehID);
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);
53
if (MSGlobals::gCheckRoutes) {
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
/****************************************************************************/
68
69