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