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 /****************************************************************************/
8 // Abstract in-vehicle device
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
11 // Copyright (C) 2013-2014 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
33 #include <microsim/MSVehicle.h>
34 #include "MSDevice.h"
35 #include "MSDevice_Vehroutes.h"
36 #include "MSDevice_Tripinfo.h"
37 #include "MSDevice_Routing.h"
38 #include "MSDevice_Person.h"
39 #include "MSDevice_Emissions.h"
40 #include "MSDevice_BTreceiver.h"
41 #include "MSDevice_BTsender.h"
42 #include "MSDevice_Example.h"
43 
44 #ifdef CHECK_MEMORY_LEAKS
45 #include <foreign/nvwa/debug_new.h>
46 #endif // CHECK_MEMORY_LEAKS
47 
48 
49 // ===========================================================================
50 // static member variables
51 // ===========================================================================
52 std::map<std::string, std::set<std::string> > MSDevice::myExplicitIDs;
53 
54 
55 // ===========================================================================
56 // method definitions
57 // ===========================================================================
58 // ---------------------------------------------------------------------------
59 // static initialisation methods
60 // ---------------------------------------------------------------------------
61 void
68 }
69 
70 
71 void
72 MSDevice::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into) {
80 }
81 
82 
83 void
84 MSDevice::insertDefaultAssignmentOptions(const std::string& deviceName, const std::string& optionsTopic, OptionsCont& oc) {
85  oc.doRegister("device." + deviceName + ".probability", new Option_Float(0.));
86  oc.addDescription("device." + deviceName + ".probability", optionsTopic, "The probability for a vehicle to have a '" + deviceName + "' device");
87 
88  oc.doRegister("device." + deviceName + ".explicit", new Option_String());
89  oc.addSynonyme("device." + deviceName + ".explicit", "device." + deviceName + ".knownveh", true);
90  oc.addDescription("device." + deviceName + ".explicit", optionsTopic, "Assign a '" + deviceName + "' device to named vehicles");
91 
92  oc.doRegister("device." + deviceName + ".deterministic", new Option_Bool(false));
93  oc.addDescription("device." + deviceName + ".deterministic", optionsTopic, "The '" + deviceName + "' devices are set deterministic using a fraction of 1000");
94 }
95 
96 
97 bool
98 MSDevice::equippedByDefaultAssignmentOptions(const OptionsCont& oc, const std::string& deviceName, SUMOVehicle& v) {
99  // assignment by number
100  bool haveByNumber = false;
101  if (oc.exists("device." + deviceName + ".deterministic") && oc.getBool("device." + deviceName + ".deterministic")) {
102  haveByNumber = MSNet::getInstance()->getVehicleControl().getQuota(oc.getFloat("device." + deviceName + ".probability")) == 1;
103  } else {
104  if (oc.exists("device." + deviceName + ".probability") && oc.getFloat("device." + deviceName + ".probability") != 0) {
105  haveByNumber = RandHelper::rand() <= oc.getFloat("device." + deviceName + ".probability");
106  }
107  }
108  // assignment by name
109  bool haveByName = false;
110  if (oc.exists("device." + deviceName + ".explicit") && oc.isSet("device." + deviceName + ".explicit")) {
111  if (myExplicitIDs.find(deviceName) == myExplicitIDs.end()) {
112  myExplicitIDs[deviceName] = std::set<std::string>();
113  const std::vector<std::string> idList = OptionsCont::getOptions().getStringVector("device." + deviceName + ".explicit");
114  myExplicitIDs[deviceName].insert(idList.begin(), idList.end());
115  }
116  haveByName = myExplicitIDs[deviceName].count(v.getID()) > 0;
117  }
118  // assignment by abstract parameters
119  bool haveByParameter = false;
120  if (v.getParameter().knowsParameter("has." + deviceName + ".device")) {
121  haveByParameter = TplConvert::_2bool(v.getParameter().getParameter("has." + deviceName + ".device", "false").c_str());
122  } else {
123  haveByParameter = TplConvert::_2bool(v.getVehicleType().getParameter().getParameter("has." + deviceName + ".device", "false").c_str());
124  }
125  return haveByNumber || haveByName || haveByParameter;
126 }
127 
128 
129 /****************************************************************************/
130