SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSDevice_BTreceiver.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A BT sender
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
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 
34 #include <microsim/MSNet.h>
35 #include <microsim/MSLane.h>
36 #include <microsim/MSEdge.h>
37 #include <microsim/MSVehicle.h>
38 #include "MSDevice_Tripinfo.h"
39 #include "MSDevice_BTreceiver.h"
40 
41 #ifdef CHECK_MEMORY_LEAKS
42 #include <foreign/nvwa/debug_new.h>
43 #endif // CHECK_MEMORY_LEAKS
44 
45 
46 // ===========================================================================
47 // method definitions
48 // ===========================================================================
49 // ---------------------------------------------------------------------------
50 // static initialisation methods
51 // ---------------------------------------------------------------------------
52 void
54  oc.addOptionSubTopic("Communication");
55 
56  insertDefaultAssignmentOptions("btreceiver", "Communication", oc);
57 
58  oc.doRegister("device.btreceiver.range", new Option_String("0", "TIME"));
59  oc.addDescription("device.btreceiver.range", "Communication", "The period with which the vehicle shall be rerouted");
60 }
61 
62 
63 void
64 MSDevice_BTreceiver::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into) {
66  if (equippedByDefaultAssignmentOptions(oc, "btreceiver", v)) {
67  MSDevice_BTreceiver* device = new MSDevice_BTreceiver(v, "btreceiver_" + v.getID(), oc.getFloat("device.btreceiver.range"));
68  into.push_back(device);
69  }
70 }
71 
72 
73 // ---------------------------------------------------------------------------
74 // MSDevice_BTreceiver-methods
75 // ---------------------------------------------------------------------------
76 MSDevice_BTreceiver::MSDevice_BTreceiver(SUMOVehicle& holder, const std::string& id, SUMOReal range)
77  : MSDevice(holder, id), myRange(range) {
78 }
79 
80 
82 }
83 
84 
85 bool
87  SUMOReal newPos, SUMOReal newSpeed) {
88  Position p = static_cast<MSVehicle&>(veh).getPosition();
89  // collect edges around
90  std::set<std::string> tmp;
91  Named::StoringVisitor sv(tmp);
92  std::set<std::string> inRange;
94 
95  // check vehicles in range first;
96  // determine when they've entered range
97  for (std::set<std::string>::const_iterator i = tmp.begin(); i != tmp.end(); ++i) {
98  MSLane* l = MSLane::dictionary(*i);
99  if (l == 0) {
100  continue;
101  }
102 
103  const MSLane::VehCont& vehs = l->getVehiclesSecure();
104  for (MSLane::VehCont::const_iterator j = vehs.begin(); j != vehs.end(); ++j) {
105  if (static_cast<MSVehicle&>(myHolder).getPosition().distanceTo((*j)->getPosition()) > myRange) {
106  continue;
107  }
108  // save, we have to investigate vehicles we do not see anymore
109  inRange.insert((*j)->getID());
110  // add new vehicles to myCurrentlySeen
111  if (myCurrentlySeen.find((*j)->getID()) == myCurrentlySeen.end()) {
112  MeetingPoint mp(MSNet::getInstance()->getCurrentTimeStep(),
113  static_cast<MSVehicle&>(myHolder).getPosition(), myHolder.getSpeed(), (*j)->getPosition(), (*j)->getSpeed());
114  SeenDevice* sd = new SeenDevice(mp);
115  myCurrentlySeen[(*j)->getID()] = sd;
116  }
117  }
118  l->releaseVehicles();
119  }
120  // check vehicles that are not longer in range
121  // set their range exit information
122  for (std::map<std::string, SeenDevice*>::const_iterator i = myCurrentlySeen.begin(); i != myCurrentlySeen.end(); ++i) {
123  if (inRange.find((*i).first) != inRange.end()) {
124  continue;
125  }
126  MSVehicle* v = static_cast<MSVehicle*>(MSNet::getInstance()->getVehicleControl().getVehicle((*i).first));
127  MeetingPoint mp(MSNet::getInstance()->getCurrentTimeStep(),
128  static_cast<MSVehicle&>(myHolder).getPosition(), myHolder.getSpeed(), v->getPosition(), v->getSpeed());
129  myCurrentlySeen[(*i).first]->meetingEnd = mp;
130  if (mySeen.find((*i).first) == mySeen.end()) {
131  mySeen[(*i).first] = std::vector<SeenDevice*>();
132  }
133  mySeen[(*i).first].push_back(myCurrentlySeen[(*i).first]);
134  myCurrentlySeen.erase(myCurrentlySeen.find((*i).first));
135  }
136  return true; // keep the device
137 }
138 
139 
140 void
142 }
143 
144 
145 
146 /****************************************************************************/
147