SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSDevice.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // Abstract in-vehicle device
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
10 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
31 #include <microsim/MSVehicle.h>
32 #include "MSDevice.h"
39 
40 #ifdef CHECK_MEMORY_LEAKS
41 #include <foreign/nvwa/debug_new.h>
42 #endif // CHECK_MEMORY_LEAKS
43 
44 
45 // ===========================================================================
46 // static member variables
47 // ===========================================================================
48 std::map<std::string, std::set<std::string> > MSDevice::myExplicitIDs;
49 
50 
51 // ===========================================================================
52 // method definitions
53 // ===========================================================================
54 // ---------------------------------------------------------------------------
55 // static initialisation methods
56 // ---------------------------------------------------------------------------
57 void
62 }
63 
64 
65 void
66 MSDevice::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into) {
72 }
73 
74 
75 void
76 MSDevice::insertDefaultAssignmentOptions(const std::string& deviceName, const std::string& optionsTopic, OptionsCont& oc) {
77  oc.doRegister("device." + deviceName + ".probability", new Option_Float(0.));
78  oc.addDescription("device." + deviceName + ".probability", optionsTopic, "The probability for a vehicle to have a '" + deviceName + "' device");
79 
80  oc.doRegister("device." + deviceName + ".explicit", new Option_String());
81  oc.addSynonyme("device." + deviceName + ".explicit", "device." + deviceName + ".knownveh", true);
82  oc.addDescription("device." + deviceName + ".explicit", optionsTopic, "Assign a '" + deviceName + "' device to named vehicles");
83 
84  oc.doRegister("device." + deviceName + ".deterministic", new Option_Bool(false));
85  oc.addDescription("device." + deviceName + ".deterministic", optionsTopic, "The '" + deviceName + "' devices are set deterministic using a fraction of 1000");
86 }
87 
88 
89 bool
90 MSDevice::equippedByDefaultAssignmentOptions(const OptionsCont& oc, const std::string& deviceName, SUMOVehicle& v) {
91  // assignment by number
92  bool haveByNumber = false;
93  if (oc.exists("device." + deviceName + ".deterministic") && oc.getBool("device." + deviceName + ".deterministic")) {
94  haveByNumber = MSNet::getInstance()->getVehicleControl().isInQuota(oc.getFloat("device." + deviceName + ".probability"));
95  } else {
96  if (oc.exists("device." + deviceName + ".probability") && oc.getFloat("device." + deviceName + ".probability") != 0) {
97  haveByNumber = RandHelper::rand() <= oc.getFloat("device." + deviceName + ".probability");
98  }
99  }
100  // assignment by name
101  bool haveByName = false;
102  if (oc.exists("device." + deviceName + ".explicit") && oc.isSet("device." + deviceName + ".explicit")) {
103  if (myExplicitIDs.find(deviceName) == myExplicitIDs.end()) {
104  myExplicitIDs[deviceName] = std::set<std::string>();
105  const std::vector<std::string> idList = OptionsCont::getOptions().getStringVector("device." + deviceName + ".explicit");
106  myExplicitIDs[deviceName].insert(idList.begin(), idList.end());
107  }
108  haveByName = myExplicitIDs[deviceName].count(v.getID()) > 0;
109  }
110  return haveByNumber || haveByName;
111 }
112 
113 
114 /****************************************************************************/
115 
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_HBEFA-options.
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:84
std::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String) ...
static std::map< std::string, std::set< std::string > > myExplicitIDs
vehicles which explicitly carry a device, sorted by device, first
Definition: MSDevice.h:157
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice * > &into)
Build devices for the given vehicle, if needed.
static SUMOReal rand()
Returns a random real number in [0, 1)
Definition: RandHelper.h:61
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice * > &into)
Build devices for the given vehicle, if needed.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice * > &into)
Build devices for the given vehicle, if needed.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:150
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_Example-options.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice * > &into)
Build devices for the given vehicle, if needed.
Definition: MSDevice.cpp:66
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_Routing-options.
Representation of a vehicle.
Definition: SUMOVehicle.h:63
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:248
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc)
Adds common command options that allow to assign devices to vehicles.
Definition: MSDevice.cpp:76
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice * > &into)
Build devices for the given vehicle, if needed.
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, SUMOVehicle &v)
Determines whether a vehicle should get a certain device.
Definition: MSDevice.cpp:90
A storage for options typed value containers)
Definition: OptionsCont.h:108
static MSDevice_Vehroutes * buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice * > &into, unsigned int maxRoutes=INT_MAX)
Build devices for the given vehicle, if needed.
static void insertOptions(OptionsCont &oc)
Inserts options for building devices.
Definition: MSDevice.cpp:58
bool isInQuota(SUMOReal frac=-1) const
Returns the information whether the currently vehicle number shall be emitted considering that only f...
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.
bool exists(const std::string &name) const
Returns the information whether the named option is known.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.