SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MSDevice_BTreceiver.h
Go to the documentation of this file.
1 /****************************************************************************/
8 // A BT receiver
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2013-2016 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 #ifndef MSDevice_BTreceiver_h
22 #define MSDevice_BTreceiver_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include "MSDevice.h"
35 #include "MSDevice_BTsender.h"
36 #include <utils/common/SUMOTime.h>
37 #include <utils/common/Command.h>
39 
40 
41 // ===========================================================================
42 // class declarations
43 // ===========================================================================
44 class SUMOVehicle;
45 
46 
47 // ===========================================================================
48 // class definitions
49 // ===========================================================================
56 class MSDevice_BTreceiver : public MSDevice {
57 public:
61  static void insertOptions(OptionsCont& oc);
62 
63 
74  static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into);
75 
76 
80  static SUMOReal getRange() {
81  return myRange;
82  }
83 
84 
85 
86 public:
89 
90 
91 
94 
103  bool notifyEnter(SUMOVehicle& veh, Notification reason);
104 
105 
119  bool notifyMove(SUMOVehicle& veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed);
120 
121 
132  bool notifyLeave(SUMOVehicle& veh, SUMOReal lastPos, Notification reason);
134 
135 
136 
140  class MeetingPoint {
141  public:
148  const MSDevice_BTsender::VehicleState& _seenState)
149  : t(_t), observerState(_observerState), seenState(_seenState) {}
150 
153 
154  public:
156  const SUMOReal t;
161 
162  private:
165 
166  };
167 
168 
169 
173  class SeenDevice {
174  public:
178  SeenDevice(const MeetingPoint& meetingBegin_)
179  : meetingBegin(meetingBegin_), meetingEnd(0), lastView(meetingBegin_.t), nextView(-1.) {}
180 
183  delete meetingEnd;
184  for (std::vector<MeetingPoint*>::iterator i = recognitionPoints.begin(); i != recognitionPoints.end(); ++i) {
185  delete *i;
186  }
187  recognitionPoints.clear();
188  }
189 
190 
191  public:
201  std::vector<MeetingPoint*> recognitionPoints;
203  std::string receiverRoute;
205  std::string senderRoute;
206 
207  private:
210 
211  };
212 
213 
214 
219  static void cleanUp(std::map<std::string, SeenDevice*>& c, std::map<std::string, std::vector<SeenDevice*> >& s);
220 
221 
222 
223 protected:
229  MSDevice_BTreceiver(SUMOVehicle& holder, const std::string& id);
230 
231 
232 
233 private:
235  static bool myWasInitialised;
236 
239 
242 
243 
248  public:
253  VehicleInformation(const std::string& id, const SUMOReal _range) : MSDevice_BTsender::VehicleInformation(id), range(_range) {}
254 
257  std::map<std::string, SeenDevice*>::iterator i;
258  for (i = currentlySeen.begin(); i != currentlySeen.end(); i++) {
259  delete i->second;
260  }
261  std::map<std::string, std::vector<SeenDevice*> >::iterator j;
262  std::vector<SeenDevice*>::iterator k;
263  for (j = seen.begin(); j != seen.end(); j++) {
264  for (k = j->second.begin(); k != j->second.end(); k++) {
265  delete *k;
266  }
267  }
268  }
269 
272 
274  std::map<std::string, SeenDevice*> currentlySeen;
275 
277  std::map<std::string, std::vector<SeenDevice*> > seen;
278 
279  private:
282 
285 
286  };
287 
288 
289 
293  class BTreceiverUpdate : public Command {
294  public:
297 
300 
305  SUMOTime execute(SUMOTime currentTime);
306 
307 
313 
314 
322  void enterRange(SUMOReal atOffset, const MSDevice_BTsender::VehicleState& receiverState,
323  const std::string& senderID, const MSDevice_BTsender::VehicleState& senderState,
324  std::map<std::string, SeenDevice*>& currentlySeen);
325 
326 
334  void leaveRange(VehicleInformation& receiverInfo, const MSDevice_BTsender::VehicleState& receiverState,
336  SUMOReal tOffset);
337 
338 
339 
340 
347  void addRecognitionPoint(const SUMOReal tEnd, const MSDevice_BTsender::VehicleState& receiverState,
348  const MSDevice_BTsender::VehicleState& senderState,
349  SeenDevice* senderDevice) const;
350 
351 
357  void writeOutput(const std::string& id, const std::map<std::string, std::vector<SeenDevice*> >& seen,
358  bool allRecognitions);
359 
360 
361 
362 
363  };
364 
365 
366  static SUMOReal inquiryDelaySlots(const int backoffLimit);
367 
370 
372  static std::map<std::string, VehicleInformation*> sVehicles;
373 
374 
375 
376 private:
379 
382 
383 
384 };
385 
386 #endif
387 
388 /****************************************************************************/
389 
std::string receiverRoute
string of travelled receiver edges
const MeetingPoint meetingBegin
Description of the meeting's begin.
long long int SUMOTime
Definition: SUMOTime.h:43
VehicleInformation(const std::string &id, const SUMOReal _range)
Constructor.
const MSDevice_BTsender::VehicleState seenState
The state the seen vehicle had at the time.
SeenDevice(const MeetingPoint &meetingBegin_)
Constructor.
Notification
Definition of a vehicle state.
std::vector< MeetingPoint * > recognitionPoints
List of recognition points.
static MTRand sRecognitionRNG
A random number generator used to determine whether the opposite was recognized.
VehicleInformation & operator=(const VehicleInformation &)
Invalidated assignment operator.
MSDevice_BTreceiver & operator=(const MSDevice_BTreceiver &)
Invalidated assignment operator.
bool notifyLeave(SUMOVehicle &veh, SUMOReal lastPos, Notification reason)
Moves (the known) vehicle from running to arrived vehicles' list.
SUMOReal lastView
Last recognition point.
Base (microsim) event class.
Definition: Command.h:61
MSDevice_BTreceiver(SUMOVehicle &holder, const std::string &id)
Constructor.
std::map< std::string, std::vector< SeenDevice * > > seen
The past episodes of removed vehicle.
static SUMOReal myRange
The range of the device.
static SUMOReal inquiryDelaySlots(const int backoffLimit)
Class representing a single seen device.
std::string senderRoute
string of travelled sender edges
Representation of a vehicle.
Definition: SUMOVehicle.h:66
static bool myWasInitialised
Whether the bt-system was already initialised.
A single movement state of the vehicle.
SUMOReal nextView
Next possible recognition point.
void writeOutput(const std::string &id, const std::map< std::string, std::vector< SeenDevice * > > &seen, bool allRecognitions)
Writes the output.
static void cleanUp(std::map< std::string, SeenDevice * > &c, std::map< std::string, std::vector< SeenDevice * > > &s)
Clears the given containers deleting the stored items.
bool notifyEnter(SUMOVehicle &veh, Notification reason)
Adds the vehicle to running vehicles if it (re-) enters the network.
~MSDevice_BTreceiver()
Destructor.
SUMOTime execute(SUMOTime currentTime)
Performs the update.
static std::map< std::string, VehicleInformation * > sVehicles
The list of arrived receivers.
void leaveRange(VehicleInformation &receiverInfo, const MSDevice_BTsender::VehicleState &receiverState, MSDevice_BTsender::VehicleInformation &senderInfo, const MSDevice_BTsender::VehicleState &senderState, SUMOReal tOffset)
Removes the sender from the currently seen devices to past episodes.
Stores the information of a vehicle.
const SUMOReal t
The time of the meeting.
Abstract in-vehicle device.
Definition: MSDevice.h:69
Holds the information about exact positions/speeds/time of the begin/end of a meeting.
SeenDevice & operator=(const SeenDevice &)
Invalidated assignment operator.
void enterRange(SUMOReal atOffset, const MSDevice_BTsender::VehicleState &receiverState, const std::string &senderID, const MSDevice_BTsender::VehicleState &senderState, std::map< std::string, SeenDevice * > &currentlySeen)
Informs the receiver about a sender entering it's radius.
void addRecognitionPoint(const SUMOReal tEnd, const MSDevice_BTsender::VehicleState &receiverState, const MSDevice_BTsender::VehicleState &senderState, SeenDevice *senderDevice) const
Adds a point of recognition.
std::map< std::string, SeenDevice * > currentlySeen
The map of devices seen by the vehicle at removal time.
static SUMOReal myOffTime
The offtime of the device.
A storage for options typed value containers)
Definition: OptionsCont.h:99
MeetingPoint(SUMOReal _t, const MSDevice_BTsender::VehicleState &_observerState, const MSDevice_BTsender::VehicleState &_seenState)
Constructor.
const SUMOReal range
Recognition range of the vehicle.
#define SUMOReal
Definition: config.h:214
Stores the information of a vehicle.
void updateVisibility(VehicleInformation &receiver, MSDevice_BTsender::VehicleInformation &sender)
Rechecks the visibility for a given receiver/sender pair.
static SUMOReal getRange()
Returns the configured range.
MeetingPoint * meetingEnd
Description of the meeting's end.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice * > &into)
Build devices for the given vehicle, if needed.
const MSDevice_BTsender::VehicleState observerState
The state the observer had at the time.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_BTreceiver-options.
bool notifyMove(SUMOVehicle &veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
MeetingPoint & operator=(const MeetingPoint &)
Invalidated assignment operator.