SUMO - Simulation of Urban MObility
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-2017 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 <random>
35 #include "MSDevice.h"
36 #include "MSDevice_BTsender.h"
37 #include <utils/common/SUMOTime.h>
38 #include <utils/common/Command.h>
40 
41 
42 // ===========================================================================
43 // class declarations
44 // ===========================================================================
45 class SUMOVehicle;
46 
47 
48 // ===========================================================================
49 // class definitions
50 // ===========================================================================
57 class MSDevice_BTreceiver : public MSDevice {
58 public:
62  static void insertOptions(OptionsCont& oc);
63 
64 
75  static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into);
76 
77 
81  static double getRange() {
82  return myRange;
83  }
84 
85 
86 
87 public:
90 
91 
92 
95 
104  bool notifyEnter(SUMOVehicle& veh, Notification reason, const MSLane* enteredLane = 0);
105 
106 
120  bool notifyMove(SUMOVehicle& veh, double oldPos, double newPos, double newSpeed);
121 
122 
133  bool notifyLeave(SUMOVehicle& veh, double lastPos, Notification reason, const MSLane* enteredLane = 0);
135 
137  const std::string deviceName() const {
138  return "btreceiver";
139  }
140 
141 
145  class MeetingPoint {
146  public:
152  MeetingPoint(double _t, const MSDevice_BTsender::VehicleState& _observerState,
153  const MSDevice_BTsender::VehicleState& _seenState)
154  : t(_t), observerState(_observerState), seenState(_seenState) {}
155 
158 
159  public:
161  const double t;
166 
167  private:
170 
171  };
172 
173 
174 
178  class SeenDevice {
179  public:
183  SeenDevice(const MeetingPoint& meetingBegin_)
184  : meetingBegin(meetingBegin_), meetingEnd(0), lastView(meetingBegin_.t), nextView(-1.) {}
185 
188  delete meetingEnd;
189  for (std::vector<MeetingPoint*>::iterator i = recognitionPoints.begin(); i != recognitionPoints.end(); ++i) {
190  delete *i;
191  }
192  recognitionPoints.clear();
193  }
194 
195 
196  public:
202  double lastView;
204  double nextView;
206  std::vector<MeetingPoint*> recognitionPoints;
208  std::string receiverRoute;
210  std::string senderRoute;
211 
212  private:
215 
216  };
217 
218 
219 
224  static void cleanUp(std::map<std::string, SeenDevice*>& c, std::map<std::string, std::vector<SeenDevice*> >& s);
225 
226 
227 
228 protected:
234  MSDevice_BTreceiver(SUMOVehicle& holder, const std::string& id);
235 
236 
237 
238 private:
240  static bool myWasInitialised;
241 
243  static double myRange;
244 
246  static double myOffTime;
247 
248 
253  public:
258  VehicleInformation(const std::string& id, const double _range) : MSDevice_BTsender::VehicleInformation(id), range(_range) {}
259 
262  std::map<std::string, SeenDevice*>::iterator i;
263  for (i = currentlySeen.begin(); i != currentlySeen.end(); i++) {
264  delete i->second;
265  }
266  std::map<std::string, std::vector<SeenDevice*> >::iterator j;
267  std::vector<SeenDevice*>::iterator k;
268  for (j = seen.begin(); j != seen.end(); j++) {
269  for (k = j->second.begin(); k != j->second.end(); k++) {
270  delete *k;
271  }
272  }
273  }
274 
276  const double range;
277 
279  std::map<std::string, SeenDevice*> currentlySeen;
280 
282  std::map<std::string, std::vector<SeenDevice*> > seen;
283 
284  private:
287 
290 
291  };
292 
293 
294 
298  class BTreceiverUpdate : public Command {
299  public:
302 
304  ~BTreceiverUpdate();
305 
310  SUMOTime execute(SUMOTime currentTime);
311 
312 
317  void updateVisibility(VehicleInformation& receiver, MSDevice_BTsender::VehicleInformation& sender);
318 
319 
327  void enterRange(double atOffset, const MSDevice_BTsender::VehicleState& receiverState,
328  const std::string& senderID, const MSDevice_BTsender::VehicleState& senderState,
329  std::map<std::string, SeenDevice*>& currentlySeen);
330 
331 
339  void leaveRange(VehicleInformation& receiverInfo, const MSDevice_BTsender::VehicleState& receiverState,
341  double tOffset);
342 
343 
344 
345 
352  void addRecognitionPoint(const double tEnd, const MSDevice_BTsender::VehicleState& receiverState,
353  const MSDevice_BTsender::VehicleState& senderState,
354  SeenDevice* senderDevice) const;
355 
356 
362  void writeOutput(const std::string& id, const std::map<std::string, std::vector<SeenDevice*> >& seen,
363  bool allRecognitions);
364 
365 
366 
367 
368  };
369 
370 
371  static double inquiryDelaySlots(const int backoffLimit);
372 
374  static std::mt19937 sRecognitionRNG;
375 
377  static std::map<std::string, VehicleInformation*> sVehicles;
378 
379 
380 
381 private:
384 
387 
388 
389 };
390 
391 #endif
392 
393 /****************************************************************************/
394 
std::string receiverRoute
string of travelled receiver edges
const MeetingPoint meetingBegin
Description of the meeting&#39;s begin.
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 double getRange()
Returns the configured range.
double lastView
Last recognition point.
MeetingPoint(double _t, const MSDevice_BTsender::VehicleState &_observerState, const MSDevice_BTsender::VehicleState &_seenState)
Constructor.
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 double inquiryDelaySlots(const int backoffLimit)
bool notifyMove(SUMOVehicle &veh, double oldPos, double newPos, double newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
static std::mt19937 sRecognitionRNG
A random number generator used to determine whether the opposite was recognized.
Class representing a single seen device.
double nextView
Next possible recognition point.
std::string senderRoute
string of travelled sender edges
Representation of a vehicle.
Definition: SUMOVehicle.h:67
static bool myWasInitialised
Whether the bt-system was already initialised.
A single movement state of the vehicle.
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.
~MSDevice_BTreceiver()
Destructor.
static std::map< std::string, VehicleInformation * > sVehicles
The list of arrived receivers.
const std::string deviceName() const
return the name for this type of device
VehicleInformation(const std::string &id, const double _range)
Constructor.
Stores the information of a vehicle.
Abstract in-vehicle device.
Definition: MSDevice.h:71
Holds the information about exact positions/speeds/time of the begin/end of a meeting.
const double t
The time of the meeting.
bool notifyEnter(SUMOVehicle &veh, Notification reason, const MSLane *enteredLane=0)
Adds the vehicle to running vehicles if it (re-) enters the network.
bool notifyLeave(SUMOVehicle &veh, double lastPos, Notification reason, const MSLane *enteredLane=0)
Moves (the known) vehicle from running to arrived vehicles&#39; list.
std::map< std::string, SeenDevice * > currentlySeen
The map of devices seen by the vehicle at removal time.
A storage for options typed value containers)
Definition: OptionsCont.h:99
Stores the information of a vehicle.
long long int SUMOTime
Definition: TraCIDefs.h:52
static double myRange
The range of the device.
const double range
Recognition range of the vehicle.
static double myOffTime
The offtime of the device.
MeetingPoint * meetingEnd
Description of the meeting&#39;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.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
MeetingPoint & operator=(const MeetingPoint &)
Invalidated assignment operator.