SUMO - Simulation of Urban MObility
MSDevice_BTreceiver.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2013-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 // A BT receiver
19 /****************************************************************************/
20 #ifndef MSDevice_BTreceiver_h
21 #define MSDevice_BTreceiver_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <random>
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 double getRange() {
81  return myRange;
82  }
83 
84 
85 
86 public:
89 
90 
91 
94 
103  bool notifyEnter(SUMOVehicle& veh, Notification reason, const MSLane* enteredLane = 0);
104 
105 
119  bool notifyMove(SUMOVehicle& veh, double oldPos, double newPos, double newSpeed);
120 
121 
132  bool notifyLeave(SUMOVehicle& veh, double lastPos, Notification reason, const MSLane* enteredLane = 0);
134 
136  const std::string deviceName() const {
137  return "btreceiver";
138  }
139 
140 
144  class MeetingPoint {
145  public:
151  MeetingPoint(double _t, const MSDevice_BTsender::VehicleState& _observerState,
152  const MSDevice_BTsender::VehicleState& _seenState)
153  : t(_t), observerState(_observerState), seenState(_seenState) {}
154 
157 
158  public:
160  const double t;
165 
166  private:
169 
170  };
171 
172 
173 
177  class SeenDevice {
178  public:
182  SeenDevice(const MeetingPoint& meetingBegin_)
183  : meetingBegin(meetingBegin_), meetingEnd(0), lastView(meetingBegin_.t), nextView(-1.) {}
184 
187  delete meetingEnd;
188  for (std::vector<MeetingPoint*>::iterator i = recognitionPoints.begin(); i != recognitionPoints.end(); ++i) {
189  delete *i;
190  }
191  recognitionPoints.clear();
192  }
193 
194 
195  public:
201  double lastView;
203  double nextView;
205  std::vector<MeetingPoint*> recognitionPoints;
207  std::string receiverRoute;
209  std::string senderRoute;
210 
211  private:
214 
215  };
216 
217 
218 
223  static void cleanUp(std::map<std::string, SeenDevice*>& c, std::map<std::string, std::vector<SeenDevice*> >& s);
224 
225 
226 
227 protected:
233  MSDevice_BTreceiver(SUMOVehicle& holder, const std::string& id);
234 
235 
236 
237 private:
239  static bool myWasInitialised;
240 
242  static double myRange;
243 
245  static double myOffTime;
246 
247 
252  public:
257  VehicleInformation(const std::string& id, const double _range) : MSDevice_BTsender::VehicleInformation(id), range(_range) {}
258 
261  std::map<std::string, SeenDevice*>::iterator i;
262  for (i = currentlySeen.begin(); i != currentlySeen.end(); i++) {
263  delete i->second;
264  }
265  std::map<std::string, std::vector<SeenDevice*> >::iterator j;
266  std::vector<SeenDevice*>::iterator k;
267  for (j = seen.begin(); j != seen.end(); j++) {
268  for (k = j->second.begin(); k != j->second.end(); k++) {
269  delete *k;
270  }
271  }
272  }
273 
275  const double range;
276 
278  std::map<std::string, SeenDevice*> currentlySeen;
279 
281  std::map<std::string, std::vector<SeenDevice*> > seen;
282 
283  private:
286 
289 
290  };
291 
292 
293 
297  class BTreceiverUpdate : public Command {
298  public:
301 
303  ~BTreceiverUpdate();
304 
309  SUMOTime execute(SUMOTime currentTime);
310 
311 
316  void updateVisibility(VehicleInformation& receiver, MSDevice_BTsender::VehicleInformation& sender);
317 
318 
326  void enterRange(double atOffset, const MSDevice_BTsender::VehicleState& receiverState,
327  const std::string& senderID, const MSDevice_BTsender::VehicleState& senderState,
328  std::map<std::string, SeenDevice*>& currentlySeen);
329 
330 
338  void leaveRange(VehicleInformation& receiverInfo, const MSDevice_BTsender::VehicleState& receiverState,
340  double tOffset);
341 
342 
343 
344 
351  void addRecognitionPoint(const double tEnd, const MSDevice_BTsender::VehicleState& receiverState,
352  const MSDevice_BTsender::VehicleState& senderState,
353  SeenDevice* senderDevice) const;
354 
355 
361  void writeOutput(const std::string& id, const std::map<std::string, std::vector<SeenDevice*> >& seen,
362  bool allRecognitions);
363 
364 
365 
366 
367  };
368 
369 
370  static double inquiryDelaySlots(const int backoffLimit);
371 
373  static std::mt19937 sRecognitionRNG;
374 
376  static std::map<std::string, VehicleInformation*> sVehicles;
377 
378 
379 
380 private:
383 
386 
387 
388 };
389 
390 #endif
391 
392 /****************************************************************************/
393 
std::string receiverRoute
string of travelled receiver edges
const MeetingPoint meetingBegin
Description of the meeting&#39;s begin.
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.
const MSDevice_BTsender::VehicleState seenState
The state the seen vehicle had at the time.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice *> &into)
Build devices for the given vehicle, if needed.
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.
const std::string deviceName() const
return the name for this type of device
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:60
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:66
static bool myWasInitialised
Whether the bt-system was already initialised.
A single movement state of the vehicle.
~MSDevice_BTreceiver()
Destructor.
static std::map< std::string, VehicleInformation * > sVehicles
The list of arrived receivers.
VehicleInformation(const std::string &id, const double _range)
Constructor.
Stores the information of a vehicle.
Abstract in-vehicle device.
Definition: MSDevice.h:70
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:98
Stores the information of a vehicle.
long long int SUMOTime
Definition: TraCIDefs.h:51
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.
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:77
MeetingPoint & operator=(const MeetingPoint &)
Invalidated assignment operator.