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 /****************************************************************************/
15 // A BT receiver
16 /****************************************************************************/
17 #ifndef MSDevice_BTreceiver_h
18 #define MSDevice_BTreceiver_h
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <random>
27 #include "MSVehicleDevice.h"
28 #include "MSDevice_BTsender.h"
29 #include <utils/common/SUMOTime.h>
30 #include <utils/common/Command.h>
32 
33 
34 // ===========================================================================
35 // class declarations
36 // ===========================================================================
37 class SUMOVehicle;
38 
39 
40 // ===========================================================================
41 // class definitions
42 // ===========================================================================
50 public:
54  static void insertOptions(OptionsCont& oc);
55 
56 
67  static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into);
68 
69 
73  static double getRange() {
74  return myRange;
75  }
76 
77 
78  static std::mt19937* getRNG() {
79  return &sRecognitionRNG;
80  }
81 
82 public:
85 
86 
87 
90 
99  bool notifyEnter(SUMOTrafficObject& veh, Notification reason, const MSLane* enteredLane = 0);
100 
101 
115  bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed);
116 
117 
128  bool notifyLeave(SUMOTrafficObject& veh, double lastPos, Notification reason, const MSLane* enteredLane = 0);
130 
132  const std::string deviceName() const {
133  return "btreceiver";
134  }
135 
136 
140  class MeetingPoint {
141  public:
147  MeetingPoint(double _t, const MSDevice_BTsender::VehicleState& _observerState,
148  const MSDevice_BTsender::VehicleState& _seenState)
149  : t(_t), observerState(_observerState), seenState(_seenState) {}
150 
153 
154  public:
156  const double 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:
197  double lastView;
199  double nextView;
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 
238  static double myRange;
239 
241  static double myOffTime;
242 
243 
248  public:
253  VehicleInformation(const std::string& id, const double _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 
271  const double range;
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(double 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  double tOffset);
337 
338 
339 
340 
347  void addRecognitionPoint(const double 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 double inquiryDelaySlots(const int backoffLimit);
367 
369  static std::mt19937 sRecognitionRNG;
370 
372  static std::map<std::string, VehicleInformation*> sVehicles;
373 
374 
375 
376 private:
379 
382 
383 
384 };
385 
386 #endif
387 
388 /****************************************************************************/
389 
MSDevice_BTreceiver::SeenDevice::SeenDevice
SeenDevice(const MeetingPoint &meetingBegin_)
Constructor.
Definition: MSDevice_BTreceiver.h:178
SUMOTrafficObject
Representation of a vehicle or person.
Definition: SUMOTrafficObject.h:47
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:195
MSDevice_BTreceiver
A BT receiver.
Definition: MSDevice_BTreceiver.h:49
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:82
MSDevice_BTreceiver::inquiryDelaySlots
static double inquiryDelaySlots(const int backoffLimit)
Definition: MSDevice_BTreceiver.cpp:285
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:417
MSDevice_BTreceiver::BTreceiverUpdate::execute
SUMOTime execute(SUMOTime currentTime)
Performs the update.
Definition: MSDevice_BTreceiver.cpp:112
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:385
MSDevice_BTreceiver::SeenDevice::lastView
double lastView
Last recognition point.
Definition: MSDevice_BTreceiver.h:197
MSDevice_BTreceiver::SeenDevice
Class representing a single seen device.
Definition: MSDevice_BTreceiver.h:173
MSDevice_BTreceiver::sVehicles
static std::map< std::string, VehicleInformation * > sVehicles
The list of arrived receivers.
Definition: MSDevice_BTreceiver.h:372
MSDevice_BTreceiver::MSDevice_BTreceiver
MSDevice_BTreceiver(const MSDevice_BTreceiver &)
Invalidated copy constructor.
MSDevice_BTreceiver::VehicleInformation::range
const double range
Recognition range of the vehicle.
Definition: MSDevice_BTreceiver.h:271
MSDevice_BTreceiver::SeenDevice::nextView
double nextView
Next possible recognition point.
Definition: MSDevice_BTreceiver.h:199
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:235
MSDevice_BTreceiver::MeetingPoint::observerState
const MSDevice_BTsender::VehicleState observerState
The state the observer had at the time.
Definition: MSDevice_BTreceiver.h:158
MSDevice_BTreceiver::SeenDevice::meetingBegin
const MeetingPoint meetingBegin
Description of the meeting's begin.
Definition: MSDevice_BTreceiver.h:193
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:60
MSDevice_BTreceiver::MeetingPoint::~MeetingPoint
~MeetingPoint()
Destructor.
Definition: MSDevice_BTreceiver.h:152
MSDevice_BTreceiver::sRecognitionRNG
static std::mt19937 sRecognitionRNG
A random number generator used to determine whether the opposite was recognized.
Definition: MSDevice_BTreceiver.h:369
MSDevice_BTreceiver::VehicleInformation::seen
std::map< std::string, std::vector< SeenDevice * > > seen
The past episodes of removed vehicle.
Definition: MSDevice_BTreceiver.h:277
MSDevice_BTreceiver::VehicleInformation::~VehicleInformation
~VehicleInformation()
Destructor.
Definition: MSDevice_BTreceiver.h:256
MSDevice_BTreceiver::MeetingPoint::seenState
const MSDevice_BTsender::VehicleState seenState
The state the seen vehicle had at the time.
Definition: MSDevice_BTreceiver.h:160
MSDevice_BTsender::VehicleInformation
Stores the information of a vehicle.
Definition: MSDevice_BTsender.h:171
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:265
MSDevice_BTreceiver::MSDevice_BTreceiver
MSDevice_BTreceiver(SUMOVehicle &holder, const std::string &id)
Constructor.
Definition: MSDevice_BTreceiver.cpp:375
MSDevice_BTreceiver::getRange
static double getRange()
Returns the configured range.
Definition: MSDevice_BTreceiver.h:73
MSDevice_BTreceiver::VehicleInformation
Stores the information of a vehicle.
Definition: MSDevice_BTreceiver.h:247
MSDevice_BTreceiver::SeenDevice::operator=
SeenDevice & operator=(const SeenDevice &)
Invalidated assignment operator.
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:89
MSDevice_BTreceiver::deviceName
const std::string deviceName() const
return the name for this type of device
Definition: MSDevice_BTreceiver.h:132
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:254
MSDevice_BTsender.h
MSDevice_BTreceiver::getRNG
static std::mt19937 * getRNG()
Definition: MSDevice_BTreceiver.h:78
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:314
MSDevice_BTreceiver::MeetingPoint::t
const double t
The time of the meeting.
Definition: MSDevice_BTreceiver.h:156
MSDevice_BTreceiver::MeetingPoint
Holds the information about exact positions/speeds/time of the begin/end of a meeting.
Definition: MSDevice_BTreceiver.h:140
MSDevice_BTreceiver::SeenDevice::senderRoute
std::string senderRoute
string of travelled sender edges
Definition: MSDevice_BTreceiver.h:205
MSDevice_BTreceiver::insertOptions
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_BTreceiver-options.
Definition: MSDevice_BTreceiver.cpp:57
MSDevice_BTreceiver::buildVehicleDevices
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
Definition: MSDevice_BTreceiver.cpp:74
MSDevice_BTsender
A BT sender.
Definition: MSDevice_BTsender.h:49
MSDevice_BTreceiver::~MSDevice_BTreceiver
~MSDevice_BTreceiver()
Destructor.
Definition: MSDevice_BTreceiver.cpp:380
MSDevice_BTreceiver::BTreceiverUpdate
A global update performer.
Definition: MSDevice_BTreceiver.h:293
MSDevice_BTreceiver::VehicleInformation::VehicleInformation
VehicleInformation(const std::string &id, const double _range)
Constructor.
Definition: MSDevice_BTreceiver.h:253
Command
Base (microsim) event class.
Definition: Command.h:52
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:147
MSDevice_BTreceiver::BTreceiverUpdate::BTreceiverUpdate
BTreceiverUpdate()
Constructor.
Definition: MSDevice_BTreceiver.cpp:93
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:178
MSDevice_BTreceiver::SeenDevice::receiverRoute
std::string receiverRoute
string of travelled receiver edges
Definition: MSDevice_BTreceiver.h:203
Command.h
MSDevice_BTreceiver::BTreceiverUpdate::~BTreceiverUpdate
~BTreceiverUpdate()
Destructor.
Definition: MSDevice_BTreceiver.cpp:98
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::VehicleInformation::VehicleInformation
VehicleInformation(const VehicleInformation &)
Invalidated copy constructor.
MSDevice_BTreceiver::SeenDevice::~SeenDevice
~SeenDevice()
Destructor.
Definition: MSDevice_BTreceiver.h:182
MSDevice_BTreceiver::myRange
static double myRange
The range of the device.
Definition: MSDevice_BTreceiver.h:238
MSMoveReminder::Notification
Notification
Definition of a vehicle state.
Definition: MSMoveReminder.h:91
MSDevice_BTsender::VehicleState
A single movement state of the vehicle.
Definition: MSDevice_BTsender.h:138
MSDevice_BTreceiver::SeenDevice::recognitionPoints
std::vector< MeetingPoint * > recognitionPoints
List of recognition points.
Definition: MSDevice_BTreceiver.h:201
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:241
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:330
MSVehicleDevice
Abstract in-vehicle device.
Definition: MSVehicleDevice.h:54
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:274