Eclipse SUMO - Simulation of Urban MObility
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-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 // 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"
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"
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 std::map<std::string, std::set<std::string> > MSDevice::myExplicitIDs;
60 SumoRNG MSDevice::myEquipmentRNG("deviceEquipment");
61 
62 // ===========================================================================
63 // debug flags
64 // ===========================================================================
65 //#define DEBUG_DEVICE_PARAMS
66 
67 
68 // ===========================================================================
69 // method definitions
70 // ===========================================================================
71 // ---------------------------------------------------------------------------
72 // static initialisation methods
73 // ---------------------------------------------------------------------------
74 void
95 
100 }
101 
102 
103 bool
105  bool ok = true;
107  return ok;
108 }
109 
110 
111 void
112 MSDevice::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) {
120  const size_t numBefore = into.size();
122  MSDevice_Battery::buildVehicleDevices(v, into, into.size() == numBefore ? nullptr : static_cast<MSDevice_StationFinder*>(into.back()));
133 }
134 
135 
136 void
137 MSDevice::buildTransportableDevices(MSTransportable& p, std::vector<MSTransportableDevice*>& into) {
143 }
144 
145 
146 void
152 }
153 
154 void
155 MSDevice::insertDefaultAssignmentOptions(const std::string& deviceName, const std::string& optionsTopic, OptionsCont& oc, const bool isPerson) {
156  const std::string prefix = (isPerson ? "person-device." : "device.") + deviceName;
157  const std::string object = isPerson ? "person" : "vehicle";
158  oc.doRegister(prefix + ".probability", new Option_Float(-1.0));// (default: no need to call RNG)
159  oc.addDescription(prefix + ".probability", optionsTopic, "The probability for a " + object + " to have a '" + deviceName + "' device");
160 
161  oc.doRegister(prefix + ".explicit", new Option_StringVector());
162  oc.addSynonyme(prefix + ".explicit", prefix + ".knownveh", true);
163  oc.addDescription(prefix + ".explicit", optionsTopic, "Assign a '" + deviceName + "' device to named " + object + "s");
164 
165  oc.doRegister(prefix + ".deterministic", new Option_Bool(false));
166  oc.addDescription(prefix + ".deterministic", optionsTopic, "The '" + deviceName + "' devices are set deterministic using a fraction of 1000");
167 }
168 
169 
170 void
172  WRITE_WARNINGF(TL("Device '%' cannot save state"), getID());
173 }
174 
175 
176 void
178 }
179 
180 
181 /****************************************************************************/
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:296
#define TL(string)
Definition: MsgHandler.h:315
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.
virtual void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the device from the given description.
Definition: MSDevice.cpp:177
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:171
static void insertOptions(OptionsCont &oc)
Inserts options for building devices.
Definition: MSDevice.cpp:75
static SumoRNG myEquipmentRNG
A random number generator used to choose from vtype/route distributions and computing the speed facto...
Definition: MSDevice.h:181
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
Definition: MSDevice.cpp:112
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:155
static std::map< std::string, std::set< std::string > > myExplicitIDs
vehicles which explicitly carry a device, sorted by device, first
Definition: MSDevice.h:178
static bool checkOptions(OptionsCont &oc)
check device-specific options
Definition: MSDevice.cpp:104
static void cleanupAll()
perform cleanup for all devices
Definition: MSDevice.cpp:147
static void buildTransportableDevices(MSTransportable &p, std::vector< MSTransportableDevice * > &into)
Build devices for the given person, if needed.
Definition: MSDevice.cpp:137
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.
Definition: OptionsCont.cpp:76
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
Encapsulated SAX-Attributes.
Representation of a vehicle.
Definition: SUMOVehicle.h:62