Eclipse 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-2019 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(SUMOTrafficObject& veh, Notification reason, const MSLane* enteredLane = 0);
101 
102 
116  bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed);
117 
118 
129  bool notifyLeave(SUMOTrafficObject& 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 
301 
306  SUMOTime execute(SUMOTime currentTime);
307 
308 
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 
MSDevice_BTreceiver::SeenDevice::SeenDevice
SeenDevice(const MeetingPoint &meetingBegin_)
Constructor.
Definition: MSDevice_BTreceiver.h:179
SUMOTrafficObject
Representation of a vehicle or person.
Definition: SUMOTrafficObject.h:48
MSDevice_BTreceiver::VehicleInformation::operator=
VehicleInformation & operator=(const VehicleInformation &)
Invalidated assignment operator.
MSDevice_BTreceiver::SeenDevice::meetingEnd
MeetingPoint * meetingEnd
Description of the meeting's end.
Definition: MSDevice_BTreceiver.h:196
MSDevice_BTreceiver
A BT receiver.
Definition: MSDevice_BTreceiver.h:50
MSDevice_BTreceiver::cleanUp
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.
SUMOTime.h
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
MSDevice_BTreceiver::inquiryDelaySlots
static double inquiryDelaySlots(const int backoffLimit)
Definition: MSDevice_BTreceiver.cpp:286
MSDevice_BTreceiver::notifyLeave
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, Notification reason, const MSLane *enteredLane=0)
Moves (the known) vehicle from running to arrived vehicles' list.
Definition: MSDevice_BTreceiver.cpp:416
MSDevice_BTreceiver::BTreceiverUpdate::execute
SUMOTime execute(SUMOTime currentTime)
Performs the update.
Definition: MSDevice_BTreceiver.cpp:113
MSVehicleDevice.h
MSDevice_BTreceiver::notifyEnter
bool notifyEnter(SUMOTrafficObject &veh, Notification reason, const MSLane *enteredLane=0)
Adds the vehicle to running vehicles if it (re-) enters the network.
Definition: MSDevice_BTreceiver.cpp:386
MSDevice_BTreceiver::SeenDevice::lastView
double lastView
Last recognition point.
Definition: MSDevice_BTreceiver.h:198
MSDevice_BTreceiver::SeenDevice
Class representing a single seen device.
Definition: MSDevice_BTreceiver.h:174
MSDevice_BTreceiver::sVehicles
static std::map< std::string, VehicleInformation * > sVehicles
The list of arrived receivers.
Definition: MSDevice_BTreceiver.h:373
MSDevice_BTreceiver::VehicleInformation::range
const double range
Recognition range of the vehicle.
Definition: MSDevice_BTreceiver.h:272
MSDevice_BTreceiver::SeenDevice::nextView
double nextView
Next possible recognition point.
Definition: MSDevice_BTreceiver.h:200
MSDevice_BTreceiver::operator=
MSDevice_BTreceiver & operator=(const MSDevice_BTreceiver &)
Invalidated assignment operator.
MSDevice_BTreceiver::myWasInitialised
static bool myWasInitialised
Whether the bt-system was already initialised.
Definition: MSDevice_BTreceiver.h:236
MSDevice_BTreceiver::MeetingPoint::observerState
const MSDevice_BTsender::VehicleState observerState
The state the observer had at the time.
Definition: MSDevice_BTreceiver.h:159
MSDevice_BTreceiver::SeenDevice::meetingBegin
const MeetingPoint meetingBegin
Description of the meeting's begin.
Definition: MSDevice_BTreceiver.h:194
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:35
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:61
MSDevice_BTreceiver::MeetingPoint::~MeetingPoint
~MeetingPoint()
Destructor.
Definition: MSDevice_BTreceiver.h:153
MSDevice_BTreceiver::sRecognitionRNG
static std::mt19937 sRecognitionRNG
A random number generator used to determine whether the opposite was recognized.
Definition: MSDevice_BTreceiver.h:370
MSDevice_BTreceiver::VehicleInformation::seen
std::map< std::string, std::vector< SeenDevice * > > seen
The past episodes of removed vehicle.
Definition: MSDevice_BTreceiver.h:278
MSDevice_BTreceiver::VehicleInformation::~VehicleInformation
~VehicleInformation()
Destructor.
Definition: MSDevice_BTreceiver.h:257
MSDevice_BTreceiver::MeetingPoint::seenState
const MSDevice_BTsender::VehicleState seenState
The state the seen vehicle had at the time.
Definition: MSDevice_BTreceiver.h:161
MSDevice_BTsender::VehicleInformation
Stores the information of a vehicle.
Definition: MSDevice_BTsender.h:172
MSDevice_BTreceiver::BTreceiverUpdate::leaveRange
void leaveRange(VehicleInformation &receiverInfo, const MSDevice_BTsender::VehicleState &receiverState, MSDevice_BTsender::VehicleInformation &senderInfo, const MSDevice_BTsender::VehicleState &senderState, double tOffset)
Removes the sender from the currently seen devices to past episodes.
Definition: MSDevice_BTreceiver.cpp:266
MSDevice_BTreceiver::MSDevice_BTreceiver
MSDevice_BTreceiver(SUMOVehicle &holder, const std::string &id)
Constructor.
Definition: MSDevice_BTreceiver.cpp:376
MSDevice_BTreceiver::getRange
static double getRange()
Returns the configured range.
Definition: MSDevice_BTreceiver.h:74
MSDevice_BTreceiver::VehicleInformation
Stores the information of a vehicle.
Definition: MSDevice_BTreceiver.h:248
MSDevice_BTreceiver::SeenDevice::operator=
SeenDevice & operator=(const SeenDevice &)
Invalidated assignment operator.
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:90
MSDevice_BTreceiver::deviceName
const std::string deviceName() const
return the name for this type of device
Definition: MSDevice_BTreceiver.h:133
MSDevice_BTreceiver::BTreceiverUpdate::enterRange
void enterRange(double 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.
Definition: MSDevice_BTreceiver.cpp:255
MSDevice_BTsender.h
MSDevice_BTreceiver::getRNG
static std::mt19937 * getRNG()
Definition: MSDevice_BTreceiver.h:79
MSDevice_BTreceiver::BTreceiverUpdate::addRecognitionPoint
void addRecognitionPoint(const double tEnd, const MSDevice_BTsender::VehicleState &receiverState, const MSDevice_BTsender::VehicleState &senderState, SeenDevice *senderDevice) const
Adds a point of recognition.
Definition: MSDevice_BTreceiver.cpp:315
MSDevice_BTreceiver::MeetingPoint::t
const double t
The time of the meeting.
Definition: MSDevice_BTreceiver.h:157
MSDevice_BTreceiver::MeetingPoint
Holds the information about exact positions/speeds/time of the begin/end of a meeting.
Definition: MSDevice_BTreceiver.h:141
MSDevice_BTreceiver::SeenDevice::senderRoute
std::string senderRoute
string of travelled sender edges
Definition: MSDevice_BTreceiver.h:206
MSDevice_BTreceiver::insertOptions
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_BTreceiver-options.
Definition: MSDevice_BTreceiver.cpp:58
MSDevice_BTreceiver::buildVehicleDevices
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
Definition: MSDevice_BTreceiver.cpp:75
MSDevice_BTsender
A BT sender.
Definition: MSDevice_BTsender.h:50
MSDevice_BTreceiver::~MSDevice_BTreceiver
~MSDevice_BTreceiver()
Destructor.
Definition: MSDevice_BTreceiver.cpp:381
MSDevice_BTreceiver::BTreceiverUpdate
A global update performer.
Definition: MSDevice_BTreceiver.h:294
MSDevice_BTreceiver::VehicleInformation::VehicleInformation
VehicleInformation(const std::string &id, const double _range)
Constructor.
Definition: MSDevice_BTreceiver.h:254
Command
Base (microsim) event class.
Definition: Command.h:53
config.h
RandHelper.h
MSDevice_BTreceiver::MeetingPoint::MeetingPoint
MeetingPoint(double _t, const MSDevice_BTsender::VehicleState &_observerState, const MSDevice_BTsender::VehicleState &_seenState)
Constructor.
Definition: MSDevice_BTreceiver.h:148
MSDevice_BTreceiver::BTreceiverUpdate::BTreceiverUpdate
BTreceiverUpdate()
Constructor.
Definition: MSDevice_BTreceiver.cpp:94
MSDevice_BTreceiver::BTreceiverUpdate::updateVisibility
void updateVisibility(VehicleInformation &receiver, MSDevice_BTsender::VehicleInformation &sender)
Rechecks the visibility for a given receiver/sender pair.
Definition: MSDevice_BTreceiver.cpp:179
MSDevice_BTreceiver::SeenDevice::receiverRoute
std::string receiverRoute
string of travelled receiver edges
Definition: MSDevice_BTreceiver.h:204
Command.h
MSDevice_BTreceiver::BTreceiverUpdate::~BTreceiverUpdate
~BTreceiverUpdate()
Destructor.
Definition: MSDevice_BTreceiver.cpp:99
MSDevice_BTreceiver::notifyMove
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
Definition: MSDevice_BTreceiver.cpp:404
MSDevice_BTreceiver::SeenDevice::~SeenDevice
~SeenDevice()
Destructor.
Definition: MSDevice_BTreceiver.h:183
MSDevice_BTreceiver::myRange
static double myRange
The range of the device.
Definition: MSDevice_BTreceiver.h:239
MSMoveReminder::Notification
Notification
Definition of a vehicle state.
Definition: MSMoveReminder.h:89
MSDevice_BTsender::VehicleState
A single movement state of the vehicle.
Definition: MSDevice_BTsender.h:139
MSDevice_BTreceiver::SeenDevice::recognitionPoints
std::vector< MeetingPoint * > recognitionPoints
List of recognition points.
Definition: MSDevice_BTreceiver.h:202
MSDevice_BTreceiver::MeetingPoint::operator=
MeetingPoint & operator=(const MeetingPoint &)
Invalidated assignment operator.
MSDevice_BTreceiver::myOffTime
static double myOffTime
The offtime of the device.
Definition: MSDevice_BTreceiver.h:242
MSDevice_BTreceiver::BTreceiverUpdate::writeOutput
void writeOutput(const std::string &id, const std::map< std::string, std::vector< SeenDevice * > > &seen, bool allRecognitions)
Writes the output.
Definition: MSDevice_BTreceiver.cpp:331
MSVehicleDevice
Abstract in-vehicle device.
Definition: MSVehicleDevice.h:55
MSDevice_BTreceiver::VehicleInformation::currentlySeen
std::map< std::string, SeenDevice * > currentlySeen
The map of devices seen by the vehicle at removal time.
Definition: MSDevice_BTreceiver.h:275