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.dev/sumo
3 // Copyright (C) 2013-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
19 // A BT receiver
20 /****************************************************************************/
21 #pragma once
22 #include <config.h>
23 
24 #include <random>
25 #include "MSVehicleDevice.h"
26 #include "MSDevice_BTsender.h"
27 #include <utils/common/SUMOTime.h>
28 #include <utils/common/Command.h>
30 
31 
32 // ===========================================================================
33 // class declarations
34 // ===========================================================================
35 class SUMOVehicle;
36 
37 
38 // ===========================================================================
39 // class definitions
40 // ===========================================================================
48 public:
49 
53  static double getRange() {
54  return myRange;
55  }
56 
57 
58  static SumoRNG* getRNG() {
59  return &sRecognitionRNG;
60  }
61 
62 public:
63 
66 
67 
68 
71 
80  bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
81 
82 
96  bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed);
97 
98 
108  bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
110 
114  class MeetingPoint {
115  public:
121  MeetingPoint(double _t, const MSDevice_BTsender::VehicleState& _observerState,
122  const MSDevice_BTsender::VehicleState& _seenState)
123  : t(_t), observerState(_observerState), seenState(_seenState) {}
124 
127 
128  public:
130  const double t;
135 
136  private:
139 
140  };
141 
142 
143 
147  class SeenDevice {
148  public:
152  SeenDevice(const MeetingPoint& meetingBegin_)
153  : meetingBegin(meetingBegin_), meetingEnd(0), lastView(meetingBegin_.t), nextView(-1.) {}
154 
157  delete meetingEnd;
158  for (std::vector<MeetingPoint*>::iterator i = recognitionPoints.begin(); i != recognitionPoints.end(); ++i) {
159  delete *i;
160  }
161  recognitionPoints.clear();
162  }
163 
164 
165  public:
171  double lastView;
173  double nextView;
175  std::vector<MeetingPoint*> recognitionPoints;
177  std::string receiverRoute;
179  std::string senderRoute;
180 
181  private:
184 
185  };
186 
187 
188 
193  static void cleanUp(std::map<std::string, SeenDevice*>& c, std::map<std::string, std::vector<SeenDevice*> >& s);
194 
196  return &sRecognitionRNG;
197  }
198 
199  static void hasSendingPersons() {
200  myHasPersons = true;
201  }
202 
203 protected:
210 
211 
213  static bool myWasInitialised;
214 
216  static bool myHasPersons;
217 
219  static double myRange;
220 
222  static double myOffTime;
223 
224 
229  public:
234  VehicleInformation(const std::string& id, const double _range) : MSDevice_BTsender::VehicleInformation(id), range(_range) {}
235 
238  std::map<std::string, SeenDevice*>::iterator i;
239  for (i = currentlySeen.begin(); i != currentlySeen.end(); i++) {
240  delete i->second;
241  }
242  std::map<std::string, std::vector<SeenDevice*> >::iterator j;
243  std::vector<SeenDevice*>::iterator k;
244  for (j = seen.begin(); j != seen.end(); j++) {
245  for (k = j->second.begin(); k != j->second.end(); k++) {
246  delete *k;
247  }
248  }
249  }
250 
252  const double range;
253 
255  std::map<std::string, SeenDevice*> currentlySeen;
256 
258  std::map<std::string, std::vector<SeenDevice*> > seen;
259 
260  private:
263 
266 
267  };
268 
269 
270 
274  class BTreceiverUpdate : public Command {
275  public:
278 
281 
286  SUMOTime execute(SUMOTime currentTime);
287 
288 
294 
295 
303  void enterRange(double atOffset, const MSDevice_BTsender::VehicleState& receiverState,
304  const std::string& senderID, const MSDevice_BTsender::VehicleState& senderState,
305  std::map<std::string, SeenDevice*>& currentlySeen);
306 
307 
315  void leaveRange(VehicleInformation& receiverInfo, const MSDevice_BTsender::VehicleState& receiverState,
317  double tOffset);
318 
319 
320 
321 
328  void addRecognitionPoint(const double tEnd, const MSDevice_BTsender::VehicleState& receiverState,
329  const MSDevice_BTsender::VehicleState& senderState,
330  SeenDevice* senderDevice) const;
331 
332 
338  void writeOutput(const std::string& id, const std::map<std::string, std::vector<SeenDevice*> >& seen,
339  bool allRecognitions);
340 
341 
342 
343 
344  };
345 
346 
347  static double inquiryDelaySlots(const int backoffLimit);
348 
351 
353  static std::map<std::string, VehicleInformation*> sVehicles;
354 
355 
356 
357 private:
360 
363 
364 };
365 
366 
368 public:
369 
373  static void insertOptions(OptionsCont& oc);
374 
375 
386  static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into);
387 
389  const std::string deviceName() const {
390  return "btreceiver";
391  }
392 
393  bool notifyEnter(SUMOTrafficObject& veh, Notification reason, const MSLane* enteredLane = 0) {
394  return MSDevice_BTreceiver::notifyEnter(veh, reason, enteredLane);
395  }
396 
397  bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed) {
398  return MSDevice_BTreceiver::notifyMove(veh, oldPos, newPos, newSpeed);
399  }
400 
401  bool notifyLeave(SUMOTrafficObject& veh, double lastPos, Notification reason, const MSLane* enteredLane = 0) {
402  return MSDevice_BTreceiver::notifyLeave(veh, lastPos, reason, enteredLane);
403  }
404 
405 
411  MSVehicleDevice_BTreceiver(SUMOVehicle& holder, const std::string& id) :
412  MSVehicleDevice(holder, id) {
413  }
414 
415 };
416 
418 public:
419 
423  static void insertOptions(OptionsCont& oc);
424 
425 
436  static void buildDevices(MSTransportable& t, std::vector<MSTransportableDevice*>& into);
437 
439  const std::string deviceName() const {
440  return "btreceiver";
441  }
442 
443  bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0) {
444  return MSDevice_BTreceiver::notifyEnter(veh, reason, enteredLane);
445  }
446 
447  bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed) {
448  return MSDevice_BTreceiver::notifyMove(veh, oldPos, newPos, newSpeed);
449  }
450 
451  bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0) {
452  return MSDevice_BTreceiver::notifyLeave(veh, lastPos, reason, enteredLane);
453  }
454 
455 
456 private:
462  MSTransportableDevice_BTreceiver(MSTransportable& holder, const std::string& id) :
463  MSTransportableDevice(holder, id) {
464  }
465 
466 };
long long int SUMOTime
Definition: GUI.h:35
Base (microsim) event class.
Definition: Command.h:50
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.
void writeOutput(const std::string &id, const std::map< std::string, std::vector< SeenDevice * > > &seen, bool allRecognitions)
Writes the output.
void addRecognitionPoint(const double tEnd, const MSDevice_BTsender::VehicleState &receiverState, const MSDevice_BTsender::VehicleState &senderState, SeenDevice *senderDevice) const
Adds a point of recognition.
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.
void updateVisibility(VehicleInformation &receiver, MSDevice_BTsender::VehicleInformation &sender)
Rechecks the visibility for a given receiver/sender pair.
SUMOTime execute(SUMOTime currentTime)
Performs the update.
Holds the information about exact positions/speeds/time of the begin/end of a meeting.
const MSDevice_BTsender::VehicleState seenState
The state the seen vehicle had at the time.
const double t
The time of the meeting.
MeetingPoint(double _t, const MSDevice_BTsender::VehicleState &_observerState, const MSDevice_BTsender::VehicleState &_seenState)
Constructor.
MeetingPoint & operator=(const MeetingPoint &)=delete
Invalidated assignment operator.
const MSDevice_BTsender::VehicleState observerState
The state the observer had at the time.
Class representing a single seen device.
std::string receiverRoute
string of travelled receiver edges
std::string senderRoute
string of travelled sender edges
SeenDevice(const MeetingPoint &meetingBegin_)
Constructor.
MeetingPoint * meetingEnd
Description of the meeting's end.
double nextView
Next possible recognition point.
SeenDevice & operator=(const SeenDevice &)
Invalidated assignment operator.
const MeetingPoint meetingBegin
Description of the meeting's begin.
double lastView
Last recognition point.
std::vector< MeetingPoint * > recognitionPoints
List of recognition points.
Stores the information of a vehicle.
VehicleInformation(const VehicleInformation &)
Invalidated copy constructor.
std::map< std::string, SeenDevice * > currentlySeen
The map of devices seen by the vehicle at removal time.
std::map< std::string, std::vector< SeenDevice * > > seen
The past episodes of removed vehicle.
VehicleInformation & operator=(const VehicleInformation &)
Invalidated assignment operator.
const double range
Recognition range of the vehicle.
VehicleInformation(const std::string &id, const double _range)
Constructor.
MSDevice_BTreceiver()
Constructor.
static double getRange()
Returns the configured range.
static bool myWasInitialised
Whether the bt-system was already initialised.
static double inquiryDelaySlots(const int backoffLimit)
static SumoRNG * getRecognitionRNG()
static SumoRNG * getRNG()
static double myRange
The range of the device.
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
static void hasSendingPersons()
MSDevice_BTreceiver(const MSDevice_BTreceiver &)
Invalidated copy constructor.
static SumoRNG sRecognitionRNG
A random number generator used to determine whether the opposite was recognized.
static std::map< std::string, VehicleInformation * > sVehicles
The list of arrived receivers.
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.
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Adds the vehicle to running vehicles if it (re-) enters the network.
static bool myHasPersons
Whether the bt-system includes persons.
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Moves (the known) vehicle from running to arrived vehicles' list.
MSDevice_BTreceiver & operator=(const MSDevice_BTreceiver &)
Invalidated assignment operator.
static double myOffTime
The offtime of the device.
Stores the information of a vehicle.
A single movement state of the vehicle.
Representation of a lane in the micro simulation.
Definition: MSLane.h:84
Notification
Definition of a vehicle state.
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Checks whether the reminder is activated by a vehicle entering the lane.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_BTreceiver-options.
MSTransportableDevice_BTreceiver(MSTransportable &holder, const std::string &id)
Constructor.
const std::string deviceName() const
return the name for this type of device
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Called if the vehicle leaves the reminder's lane.
static void buildDevices(MSTransportable &t, std::vector< MSTransportableDevice * > &into)
Build devices for the given vehicle, if needed.
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
Abstract in-person device.
MSVehicleDevice_BTreceiver(SUMOVehicle &holder, const std::string &id)
Constructor.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_BTreceiver-options.
const std::string deviceName() const
return the name for this type of device
bool notifyEnter(SUMOTrafficObject &veh, Notification reason, const MSLane *enteredLane=0)
Checks whether the reminder is activated by a vehicle entering the lane.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, Notification reason, const MSLane *enteredLane=0)
Called if the vehicle leaves the reminder's lane.
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
Abstract in-vehicle device.
A storage for options typed value containers)
Definition: OptionsCont.h:89
Representation of a vehicle, person, or container.
Representation of a vehicle.
Definition: SUMOVehicle.h:60