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 
32 #include <microsim/MSVehicle.h>
33 #include "MSDevice.h"
34 #include "MSDevice_Vehroutes.h"
35 #include "MSDevice_Tripinfo.h"
36 #include "MSDevice_Routing.h"
37 #include "MSDevice_Person.h"
38 #include "MSDevice_HBEFA.h"
39 #include "MSDevice_BTreceiver.h"
40 #include "MSDevice_BTsender.h"
41 #include "MSDevice_Example.h"
42 
43 #ifdef CHECK_MEMORY_LEAKS
44 #include <foreign/nvwa/debug_new.h>
45 #endif // CHECK_MEMORY_LEAKS
46 
47 
48 // ===========================================================================
49 // static member variables
50 // ===========================================================================
51 std::map<std::string, std::set<std::string> > MSDevice::myExplicitIDs;
52 
53 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
57 // ---------------------------------------------------------------------------
58 // static initialisation methods
59 // ---------------------------------------------------------------------------
60 void
67 }
68 
69 
70 void
71 MSDevice::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into) {
79 }
80 
81 
82 void
83 MSDevice::insertDefaultAssignmentOptions(const std::string& deviceName, const std::string& optionsTopic, OptionsCont& oc) {
84  oc.doRegister("device." + deviceName + ".probability", new Option_Float(0.));
85  oc.addDescription("device." + deviceName + ".probability", optionsTopic, "The probability for a vehicle to have a '" + deviceName + "' device");
86 
87  oc.doRegister("device." + deviceName + ".explicit", new Option_String());
88  oc.addSynonyme("device." + deviceName + ".explicit", "device." + deviceName + ".knownveh", true);
89  oc.addDescription("device." + deviceName + ".explicit", optionsTopic, "Assign a '" + deviceName + "' device to named vehicles");
90 
91  oc.doRegister("device." + deviceName + ".deterministic", new Option_Bool(false));
92  oc.addDescription("device." + deviceName + ".deterministic", optionsTopic, "The '" + deviceName + "' devices are set deterministic using a fraction of 1000");
93 }
94 
95 
96 bool
97 MSDevice::equippedByDefaultAssignmentOptions(const OptionsCont& oc, const std::string& deviceName, SUMOVehicle& v) {
98  // assignment by number
99  bool haveByNumber = false;
100  if (oc.exists("device." + deviceName + ".deterministic") && oc.getBool("device." + deviceName + ".deterministic")) {
101  haveByNumber = MSNet::getInstance()->getVehicleControl().isInQuota(oc.getFloat("device." + deviceName + ".probability"));
102  } else {
103  if (oc.exists("device." + deviceName + ".probability") && oc.getFloat("device." + deviceName + ".probability") != 0) {
104  haveByNumber = RandHelper::rand() <= oc.getFloat("device." + deviceName + ".probability");
105  }
106  }
107  // assignment by name
108  bool haveByName = false;
109  if (oc.exists("device." + deviceName + ".explicit") && oc.isSet("device." + deviceName + ".explicit")) {
110  if (myExplicitIDs.find(deviceName) == myExplicitIDs.end()) {
111  myExplicitIDs[deviceName] = std::set<std::string>();
112  const std::vector<std::string> idList = OptionsCont::getOptions().getStringVector("device." + deviceName + ".explicit");
113  myExplicitIDs[deviceName].insert(idList.begin(), idList.end());
114  }
115  haveByName = myExplicitIDs[deviceName].count(v.getID()) > 0;
116  }
117  // assignment by abstract parameters
118  bool haveByParameter = false;
119  if (v.getParameter().knowsParameter("has." + deviceName + ".device")) {
120  haveByParameter = TplConvert::_2bool(v.getParameter().getParameter("has." + deviceName + ".device", "false").c_str());
121  } else {
122  haveByParameter = TplConvert::_2bool(v.getVehicleType().getParameter().getParameter("has." + deviceName + ".device", "false").c_str());
123  }
124  return haveByNumber || haveByName || haveByParameter;
125 }
126 
127 
128 /****************************************************************************/
129