Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2013-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 MSDevice.cpp
15 : /// @author Daniel Krajzewicz
16 : /// @author Michael Behrisch
17 : /// @date 14.08.2013
18 : ///
19 : // Abstract in-vehicle device
20 : /****************************************************************************/
21 : #include <config.h>
22 :
23 : #include <utils/options/OptionsCont.h>
24 : #include <utils/common/StringUtils.h>
25 : #include <microsim/MSVehicle.h>
26 : #include <microsim/transportables/MSTransportable.h>
27 : #include <microsim/MSVehicleControl.h>
28 : #include <microsim/MSEdge.h>
29 :
30 : #include "MSDevice_Vehroutes.h"
31 : #include "MSDevice_Tripinfo.h"
32 : #include "MSDevice_Routing.h"
33 : #include "MSDevice_Emissions.h"
34 : #include "MSDevice_BTreceiver.h"
35 : #include "MSDevice_BTsender.h"
36 : #include "MSDevice_Example.h"
37 : #include "MSDevice_StationFinder.h"
38 : #include "MSDevice_Battery.h"
39 : #include "MSDevice_SSM.h"
40 : #include "MSDevice_ToC.h"
41 : #include "MSDevice_DriverState.h"
42 : #include "MSDevice_Bluelight.h"
43 : #include "MSDevice_FCD.h"
44 : #include "MSDevice_Taxi.h"
45 : #include "MSDevice_GLOSA.h"
46 : #include "MSDevice_ElecHybrid.h"
47 : #include "MSTransportableDevice_Routing.h"
48 : #include "MSTransportableDevice_FCD.h"
49 : #include "MSTransportableDevice_FCDReplay.h"
50 : #include "MSRoutingEngine.h"
51 : #include "MSDevice_Friction.h"
52 : #include "MSDevice_FCDReplay.h"
53 : #include "MSDevice.h"
54 :
55 :
56 : // ===========================================================================
57 : // static member variables
58 : // ===========================================================================
59 : const std::string MSDevice::LOADSTATE_DEVICENAMES("LOADSTATE_DEVICENAMES");
60 : std::map<std::string, std::set<std::string> > MSDevice::myExplicitIDs;
61 : SumoRNG MSDevice::myEquipmentRNG("deviceEquipment");
62 :
63 :
64 : // ===========================================================================
65 : // debug flags
66 : // ===========================================================================
67 : //#define DEBUG_DEVICE_PARAMS
68 :
69 :
70 : // ===========================================================================
71 : // method definitions
72 : // ===========================================================================
73 : // ---------------------------------------------------------------------------
74 : // static initialisation methods
75 : // ---------------------------------------------------------------------------
76 : void
77 39900 : MSDevice::insertOptions(OptionsCont& oc) {
78 39900 : MSDevice_Routing::insertOptions(oc);
79 39900 : MSDevice_Emissions::insertOptions(oc);
80 39900 : MSVehicleDevice_BTreceiver::insertOptions(oc);
81 39900 : MSVehicleDevice_BTsender::insertOptions(oc);
82 39900 : MSDevice_Example::insertOptions(oc);
83 39900 : MSDevice_StationFinder::insertOptions(oc);
84 39900 : MSDevice_Battery::insertOptions(oc);
85 39900 : MSDevice_SSM::insertOptions(oc);
86 39900 : MSDevice_ToC::insertOptions(oc);
87 39900 : MSDevice_DriverState::insertOptions(oc);
88 39900 : MSDevice_Bluelight::insertOptions(oc);
89 39900 : MSDevice_FCD::insertOptions(oc);
90 39900 : MSDevice_ElecHybrid::insertOptions(oc);
91 39900 : MSDevice_Taxi::insertOptions(oc);
92 39900 : MSDevice_GLOSA::insertOptions(oc);
93 39900 : MSDevice_Tripinfo::insertOptions(oc);
94 39900 : MSDevice_Vehroutes::insertOptions(oc);
95 39900 : MSDevice_Friction::insertOptions(oc);
96 39900 : MSDevice_FCDReplay::insertOptions(oc);
97 :
98 39900 : MSTransportableDevice_Routing::insertOptions(oc);
99 39900 : MSTransportableDevice_FCD::insertOptions(oc);
100 39900 : MSTransportableDevice_BTsender::insertOptions(oc);
101 39900 : MSTransportableDevice_BTreceiver::insertOptions(oc);
102 39900 : }
103 :
104 :
105 : bool
106 39440 : MSDevice::checkOptions(OptionsCont& oc) {
107 : bool ok = true;
108 39440 : ok &= MSDevice_Routing::checkOptions(oc);
109 39440 : return ok;
110 : }
111 :
112 :
113 : void
114 5382016 : MSDevice::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) {
115 5382016 : MSDevice_Vehroutes::buildVehicleDevices(v, into);
116 5382016 : MSDevice_Tripinfo::buildVehicleDevices(v, into);
117 5382016 : MSDevice_Routing::buildVehicleDevices(v, into);
118 5382010 : MSDevice_Emissions::buildVehicleDevices(v, into);
119 5382010 : MSVehicleDevice_BTreceiver::buildVehicleDevices(v, into);
120 5382010 : MSVehicleDevice_BTsender::buildVehicleDevices(v, into);
121 5382010 : MSDevice_Example::buildVehicleDevices(v, into);
122 : const size_t numBefore = into.size();
123 5382010 : MSDevice_StationFinder::buildVehicleDevices(v, into);
124 5382009 : MSDevice_Battery::buildVehicleDevices(v, into, into.size() == numBefore ? nullptr : static_cast<MSDevice_StationFinder*>(into.back()));
125 5382009 : MSDevice_SSM::buildVehicleDevices(v, into);
126 5382009 : MSDevice_ToC::buildVehicleDevices(v, into);
127 5382005 : MSDevice_DriverState::buildVehicleDevices(v, into);
128 5382005 : MSDevice_Bluelight::buildVehicleDevices(v, into);
129 5382005 : MSDevice_FCD::buildVehicleDevices(v, into);
130 5382005 : MSDevice_ElecHybrid::buildVehicleDevices(v, into);
131 5382005 : MSDevice_Taxi::buildVehicleDevices(v, into);
132 5381999 : MSDevice_GLOSA::buildVehicleDevices(v, into);
133 5381999 : MSDevice_Friction::buildVehicleDevices(v, into);
134 5381999 : MSDevice_FCDReplay::buildVehicleDevices(v, into);
135 5381999 : }
136 :
137 :
138 : void
139 513493 : MSDevice::buildTransportableDevices(MSTransportable& p, std::vector<MSTransportableDevice*>& into) {
140 513493 : MSTransportableDevice_Routing::buildDevices(p, into);
141 513493 : MSTransportableDevice_FCD::buildDevices(p, into);
142 513493 : MSTransportableDevice_BTsender::buildDevices(p, into);
143 513493 : MSTransportableDevice_BTreceiver::buildDevices(p, into);
144 513493 : MSTransportableDevice_FCDReplay::buildDevices(p, into);
145 513493 : }
146 :
147 :
148 : void
149 38777 : MSDevice::cleanupAll() {
150 38777 : MSRoutingEngine::cleanup();
151 38777 : MSDevice_Tripinfo::cleanup();
152 38777 : MSDevice_FCD::cleanup();
153 38777 : MSDevice_Taxi::cleanup();
154 38777 : }
155 :
156 : void
157 917700 : MSDevice::insertDefaultAssignmentOptions(const std::string& deviceName, const std::string& optionsTopic, OptionsCont& oc, const bool isPerson) {
158 1675800 : const std::string prefix = (isPerson ? "person-device." : "device.") + deviceName;
159 1675800 : const std::string object = isPerson ? "person" : "vehicle";
160 917700 : oc.doRegister(prefix + ".probability", new Option_Float(-1.0));// (default: no need to call RNG)
161 2753100 : oc.addDescription(prefix + ".probability", optionsTopic, "The probability for a " + object + " to have a '" + deviceName + "' device");
162 :
163 917700 : oc.doRegister(prefix + ".explicit", new Option_StringVector());
164 1835400 : oc.addSynonyme(prefix + ".explicit", prefix + ".knownveh", true);
165 2753100 : oc.addDescription(prefix + ".explicit", optionsTopic, "Assign a '" + deviceName + "' device to named " + object + "s");
166 :
167 917700 : oc.doRegister(prefix + ".deterministic", new Option_Bool(false));
168 3670800 : oc.addDescription(prefix + ".deterministic", optionsTopic, "The '" + deviceName + "' devices are set deterministic using a fraction of 1000");
169 917700 : }
170 :
171 :
172 : std::string
173 7194 : MSDevice::getDeviceName(const std::string& id) {
174 14388 : if (StringUtils::startsWith(id, "routing_")) {
175 : // special case: renamed in output
176 4814 : return "rerouting";
177 4760 : } else if (StringUtils::startsWith(id, "driverstate")) {
178 : // special case: no underscore
179 0 : return "driverstate";
180 : } else {
181 2380 : return id.substr(0, id.find('_'));
182 : }
183 : }
184 :
185 :
186 : void
187 0 : MSDevice::saveState(OutputDevice& /* out */) const {
188 0 : WRITE_WARNINGF(TL("Device '%' cannot save state"), getID());
189 0 : }
190 :
191 :
192 : void
193 0 : MSDevice::loadState(const SUMOSAXAttributes& /* attrs */) {
194 0 : }
195 :
196 :
197 : /****************************************************************************/
|