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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // A BT receiver
17 /****************************************************************************/
18 #ifndef MSDevice_BTreceiver_h
19 #define MSDevice_BTreceiver_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <random>
28 #include "MSVehicleDevice.h"
29 #include "MSDevice_BTsender.h"
30 #include <utils/common/SUMOTime.h>
31 #include <utils/common/Command.h>
33 
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 class SUMOVehicle;
39 
40 
41 // ===========================================================================
42 // class definitions
43 // ===========================================================================
51 public:
55  static void insertOptions(OptionsCont& oc);
56 
57 
68  static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into);
69 
70 
74  static double getRange() {
75  return myRange;
76  }
77 
78 
79  static std::mt19937* getRNG() {
80  return &sRecognitionRNG;
81  }
82 
83 public:
86 
87 
88 
91 
100  bool notifyEnter(SUMOVehicle& veh, Notification reason, const MSLane* enteredLane = 0);
101 
102 
116  bool notifyMove(SUMOVehicle& veh, double oldPos, double newPos, double newSpeed);
117 
118 
129  bool notifyLeave(SUMOVehicle& veh, double lastPos, Notification reason, const MSLane* enteredLane = 0);
131 
133  const std::string deviceName() const {
134  return "btreceiver";
135  }
136 
137 
141  class MeetingPoint {
142  public:
148  MeetingPoint(double _t, const MSDevice_BTsender::VehicleState& _observerState,
149  const MSDevice_BTsender::VehicleState& _seenState)
150  : t(_t), observerState(_observerState), seenState(_seenState) {}
151 
154 
155  public:
157  const double t;
162 
163  private:
166 
167  };
168 
169 
170 
174  class SeenDevice {
175  public:
179  SeenDevice(const MeetingPoint& meetingBegin_)
180  : meetingBegin(meetingBegin_), meetingEnd(0), lastView(meetingBegin_.t), nextView(-1.) {}
181 
184  delete meetingEnd;
185  for (std::vector<MeetingPoint*>::iterator i = recognitionPoints.begin(); i != recognitionPoints.end(); ++i) {
186  delete *i;
187  }
188  recognitionPoints.clear();
189  }
190 
191 
192  public:
198  double lastView;
200  double nextView;
202  std::vector<MeetingPoint*> recognitionPoints;
204  std::string receiverRoute;
206  std::string senderRoute;
207 
208  private:
211 
212  };
213 
214 
215 
220  static void cleanUp(std::map<std::string, SeenDevice*>& c, std::map<std::string, std::vector<SeenDevice*> >& s);
221 
222 
223 
224 protected:
230  MSDevice_BTreceiver(SUMOVehicle& holder, const std::string& id);
231 
232 
233 
234 private:
236  static bool myWasInitialised;
237 
239  static double myRange;
240 
242  static double myOffTime;
243 
244 
249  public:
254  VehicleInformation(const std::string& id, const double _range) : MSDevice_BTsender::VehicleInformation(id), range(_range) {}
255 
258  std::map<std::string, SeenDevice*>::iterator i;
259  for (i = currentlySeen.begin(); i != currentlySeen.end(); i++) {
260  delete i->second;
261  }
262  std::map<std::string, std::vector<SeenDevice*> >::iterator j;
263  std::vector<SeenDevice*>::iterator k;
264  for (j = seen.begin(); j != seen.end(); j++) {
265  for (k = j->second.begin(); k != j->second.end(); k++) {
266  delete *k;
267  }
268  }
269  }
270 
272  const double range;
273 
275  std::map<std::string, SeenDevice*> currentlySeen;
276 
278  std::map<std::string, std::vector<SeenDevice*> > seen;
279 
280  private:
283 
286 
287  };
288 
289 
290 
294  class BTreceiverUpdate : public Command {
295  public:
298 
300  ~BTreceiverUpdate();
301 
306  SUMOTime execute(SUMOTime currentTime);
307 
308 
313  void updateVisibility(VehicleInformation& receiver, MSDevice_BTsender::VehicleInformation& sender);
314 
315 
323  void enterRange(double atOffset, const MSDevice_BTsender::VehicleState& receiverState,
324  const std::string& senderID, const MSDevice_BTsender::VehicleState& senderState,
325  std::map<std::string, SeenDevice*>& currentlySeen);
326 
327 
335  void leaveRange(VehicleInformation& receiverInfo, const MSDevice_BTsender::VehicleState& receiverState,
337  double tOffset);
338 
339 
340 
341 
348  void addRecognitionPoint(const double tEnd, const MSDevice_BTsender::VehicleState& receiverState,
349  const MSDevice_BTsender::VehicleState& senderState,
350  SeenDevice* senderDevice) const;
351 
352 
358  void writeOutput(const std::string& id, const std::map<std::string, std::vector<SeenDevice*> >& seen,
359  bool allRecognitions);
360 
361 
362 
363 
364  };
365 
366 
367  static double inquiryDelaySlots(const int backoffLimit);
368 
370  static std::mt19937 sRecognitionRNG;
371 
373  static std::map<std::string, VehicleInformation*> sVehicles;
374 
375 
376 
377 private:
380 
383 
384 
385 };
386 
387 #endif
388 
389 /****************************************************************************/
390 
std::string receiverRoute
string of travelled receiver edges
const MeetingPoint meetingBegin
Description of the meeting&#39;s begin.
long long int SUMOTime
Definition: SUMOTime.h:36
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.
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.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice *> &into)
Build devices for the given vehicle, if needed.
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:54
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:60
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.
Holds the information about exact positions/speeds/time of the begin/end of a meeting.
const double t
The time of the meeting.
static std::mt19937 * getRNG()
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:92
Abstract in-vehicle device.
Stores the information of a vehicle.
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:78
MeetingPoint & operator=(const MeetingPoint &)
Invalidated assignment operator.