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-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/****************************************************************************/
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;
61SumoRNG 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// ---------------------------------------------------------------------------
76void
103
104
105bool
107 bool ok = true;
109 return ok;
110}
111
112
113void
136
137
138void
146
147
148void
155
156void
157MSDevice::insertDefaultAssignmentOptions(const std::string& deviceName, const std::string& optionsTopic, OptionsCont& oc, const bool isPerson) {
158 const std::string prefix = (isPerson ? "person-device." : "device.") + deviceName;
159 const std::string object = isPerson ? "person" : "vehicle";
160 oc.doRegister(prefix + ".probability", new Option_Float(-1.0));// (default: no need to call RNG)
161 oc.addDescription(prefix + ".probability", optionsTopic, "The probability for a " + object + " to have a '" + deviceName + "' device");
162
163 oc.doRegister(prefix + ".explicit", new Option_StringVector());
164 oc.addSynonyme(prefix + ".explicit", prefix + ".knownveh", true);
165 oc.addDescription(prefix + ".explicit", optionsTopic, "Assign a '" + deviceName + "' device to named " + object + "s");
166
167 oc.doRegister(prefix + ".deterministic", new Option_Bool(false));
168 oc.addDescription(prefix + ".deterministic", optionsTopic, "The '" + deviceName + "' devices are set deterministic using a fraction of 1000");
169}
170
171
172std::string
173MSDevice::getDeviceName(const std::string& id) {
174 if (StringUtils::startsWith(id, "routing_")) {
175 // special case: renamed in output
176 return "rerouting";
177 } else if (StringUtils::startsWith(id, "driverstate")) {
178 // special case: no underscore
179 return "driverstate";
180 } else {
181 return id.substr(0, id.find('_'));
182 }
183}
184
185
186void
188 WRITE_WARNINGF(TL("Device '%' cannot save state"), getID());
189}
190
191
192void
194}
195
196
197/****************************************************************************/
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:288
#define TL(string)
Definition MsgHandler.h:305
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
virtual void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the device from the given description.
Definition MSDevice.cpp:193
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:187
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:173
static void insertOptions(OptionsCont &oc)
Inserts options for building devices.
Definition MSDevice.cpp:77
static SumoRNG myEquipmentRNG
A random number generator used to choose from vtype/route distributions and computing the speed facto...
Definition MSDevice.h:186
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
Definition MSDevice.cpp:114
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:157
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:106
static void cleanupAll()
perform cleanup for all devices
Definition MSDevice.cpp:149
static void buildTransportableDevices(MSTransportable &p, std::vector< MSTransportableDevice * > &into)
Build devices for the given person, if needed.
Definition MSDevice.cpp:139
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:74
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.
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.
Static storage of an output device and its base (abstract) implementation.
Encapsulated SAX-Attributes.
Representation of a vehicle.
Definition SUMOVehicle.h:62
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.