Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSDevice.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2013-2026 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// Abstract in-vehicle device
20/****************************************************************************/
21#include <config.h>
22
25#include <microsim/MSVehicle.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"
38#include "MSDevice_Battery.h"
39#include "MSDevice_SSM.h"
40#include "MSDevice_ToC.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"
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// ===========================================================================
59const std::string MSDevice::LOADSTATE_DEVICENAMES("LOADSTATE_DEVICENAMES");
60std::map<std::string, std::set<std::string> > MSDevice::myExplicitIDs;
61std::map<std::string, MSDevice::DefaultAssignment> MSDevice::myDefaultAssignments[2];
62SumoRNG MSDevice::myEquipmentRNG("deviceEquipment");
63
64
65// ===========================================================================
66// debug flags
67// ===========================================================================
68//#define DEBUG_DEVICE_PARAMS
69
70
71// ===========================================================================
72// method definitions
73// ===========================================================================
74// ---------------------------------------------------------------------------
75// static initialisation methods
76// ---------------------------------------------------------------------------
77void
104
105
106bool
108 bool ok = true;
110 return ok;
111}
112
113
114void
137
138
139void
147
148
149void
158
159
161MSDevice::getDefaultAssignment(const OptionsCont& oc, const std::string& deviceName, const bool isPerson) {
162 // the options do not change during a run, the cache is cleared in cleanupAll
163 std::map<std::string, DefaultAssignment>& cache = myDefaultAssignments[isPerson ? 1 : 0];
164 auto it = cache.find(deviceName);
165 if (it == cache.end()) {
167 d.prefix = (isPerson ? "person-device." : "device.") + deviceName;
168 d.parameterKey = "has." + deviceName + ".device";
169 d.probabilityKey = d.prefix + ".probability";
170 d.deterministic = oc.exists(d.prefix + ".deterministic") && oc.getBool(d.prefix + ".deterministic");
173 d.nameGiven = oc.exists(d.prefix + ".explicit") && oc.isSet(d.prefix + ".explicit");
174 it = cache.emplace(deviceName, d).first;
175 }
176 return it->second;
177}
178
179
180void
181MSDevice::insertDefaultAssignmentOptions(const std::string& deviceName, const std::string& optionsTopic, OptionsCont& oc, const bool isPerson) {
182 const std::string prefix = (isPerson ? "person-device." : "device.") + deviceName;
183 const std::string object = isPerson ? "person" : "vehicle";
184 oc.doRegister(prefix + ".probability", new Option_Float(-1.0));// (default: no need to call RNG)
185 oc.addDescription(prefix + ".probability", optionsTopic, "The probability for a " + object + " to have a '" + deviceName + "' device");
186
187 oc.doRegister(prefix + ".explicit", new Option_StringVector());
188 oc.addSynonyme(prefix + ".explicit", prefix + ".knownveh", true);
189 oc.addDescription(prefix + ".explicit", optionsTopic, "Assign a '" + deviceName + "' device to named " + object + "s");
190
191 oc.doRegister(prefix + ".deterministic", new Option_Bool(false));
192 oc.addDescription(prefix + ".deterministic", optionsTopic, "The '" + deviceName + "' devices are set deterministic using a fraction of 1000");
193}
194
195
196std::string
197MSDevice::getDeviceName(const std::string& id) {
198 if (StringUtils::startsWith(id, "routing_")) {
199 // special case: renamed in output
200 return "rerouting";
201 } else if (StringUtils::startsWith(id, "driverstate")) {
202 // special case: no underscore
203 return "driverstate";
204 } else {
205 return id.substr(0, id.find('_'));
206 }
207}
208
209
210void
212 WRITE_WARNINGF(TL("Device '%' cannot save state"), getID());
213}
214
215
216void
218}
219
220
221/****************************************************************************/
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:287
#define TL(string)
Definition MsgHandler.h:304
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_Example-options.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into, MSDevice_StationFinder *sf)
Build devices for the given vehicle, if needed.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_Bluelight-options.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_DriverState-options.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_ElecHybrid-options.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_Emissions-options.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_Example-options.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
static void cleanup()
resets the edge filter
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_FCD-options.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_FCDReplay-options.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_Friction-options.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_GLOSA-options.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_Routing-options.
static bool checkOptions(OptionsCont &oc)
checks MSDevice_Routing-options
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_SSM-options.
A device which triggers rerouting to nearby charging stations.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_StationFinder-options.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
static void cleanup()
resets counters
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_Taxi-options.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_ToC-options.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
static void cleanup()
resets counters
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_Tripinfo-options.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_FCD-options.
static MSDevice_Vehroutes * buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into, int maxRoutes=std::numeric_limits< int >::max())
Build devices for the given vehicle, if needed.
static const std::string LOADSTATE_DEVICENAMES
Definition MSDevice.h:102
static const DefaultAssignment & getDefaultAssignment(const OptionsCont &oc, const std::string &deviceName, const bool isPerson)
Definition MSDevice.cpp:161
virtual void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the device from the given description.
Definition MSDevice.cpp:217
static std::map< std::string, DefaultAssignment > myDefaultAssignments[2]
Definition MSDevice.h:196
virtual const std::string deviceName() const =0
return the name for this type of device
virtual void saveState(OutputDevice &out) const
Saves the state of the device.
Definition MSDevice.cpp:211
static std::string getDeviceName(const std::string &id)
extracts the deviceName from the id (which includes holder id) and is subject to special cases
Definition MSDevice.cpp:197
static void insertOptions(OptionsCont &oc)
Inserts options for building devices.
Definition MSDevice.cpp:78
static SumoRNG myEquipmentRNG
A random number generator used to choose from vtype/route distributions and computing the speed facto...
Definition MSDevice.h:199
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
Definition MSDevice.cpp:115
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc, const bool isPerson=false)
Adds common command options that allow to assign devices to vehicles.
Definition MSDevice.cpp:181
static std::map< std::string, std::set< std::string > > myExplicitIDs
vehicles which explicitly carry a device, sorted by device, first
Definition MSDevice.h:183
static bool checkOptions(OptionsCont &oc)
check device-specific options
Definition MSDevice.cpp:107
static void cleanupAll()
perform cleanup for all devices
Definition MSDevice.cpp:150
static void buildTransportableDevices(MSTransportable &p, std::vector< MSTransportableDevice * > &into)
Build devices for the given person, if needed.
Definition MSDevice.cpp:140
static void cleanup()
deletes the router instance
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_BTreceiver-options.
static void buildDevices(MSTransportable &t, std::vector< MSTransportableDevice * > &into)
Build devices for the given vehicle, if needed.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_BTsender-options.
static void buildDevices(MSTransportable &t, std::vector< MSTransportableDevice * > &into)
Build devices for the given vehicle, if needed.
static void insertOptions(OptionsCont &oc)
Inserts MSTransportableDevice_FCD-options.
static void buildDevices(MSTransportable &t, std::vector< MSTransportableDevice * > &into)
Build devices for the given vehicle, if needed.
static void buildDevices(MSTransportable &t, std::vector< MSTransportableDevice * > &into)
Build devices for the given vehicle, if needed.
static void buildDevices(MSTransportable &p, std::vector< MSTransportableDevice * > &into)
Build devices for the given person, if needed.
static void insertOptions(OptionsCont &oc)
Inserts MSTransportableDevice_Routing-options.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_BTreceiver-options.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_BTsender-options.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
const std::string & getID() const
Returns the id.
Definition Named.h:73
A storage for options typed value containers)
Definition OptionsCont.h:89
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
void doRegister(const std::string &name, Option *o)
Adds an option under the given name.
bool exists(const std::string &name) const
Returns the information whether the named option is known.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
Static storage of an output device and its base (abstract) implementation.
Encapsulated SAX-Attributes.
Representation of a vehicle.
Definition SUMOVehicle.h:63
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.
the option values of a device's default assignment (all callers pass the global options,...
Definition MSDevice.h:186