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-2020 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:
52  static void insertOptions(OptionsCont& oc);
53 
54 
65  static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into);
66 
67 
71  static double getRange() {
72  return myRange;
73  }
74 
75 
76  static std::mt19937* getRNG() {
77  return &sRecognitionRNG;
78  }
79 
80 public:
83 
84 
85 
88 
97  bool notifyEnter(SUMOTrafficObject& veh, Notification reason, const MSLane* enteredLane = 0);
98 
99 
113  bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed);
114 
115 
125  bool notifyLeave(SUMOTrafficObject& veh, double lastPos, Notification reason, const MSLane* enteredLane = 0);
127 
129  const std::string deviceName() const {
130  return "btreceiver";
131  }
132 
133 
137  class MeetingPoint {
138  public:
144  MeetingPoint(double _t, const MSDevice_BTsender::VehicleState& _observerState,
145  const MSDevice_BTsender::VehicleState& _seenState)
146  : t(_t), observerState(_observerState), seenState(_seenState) {}
147 
150 
151  public:
153  const double t;
158 
159  private:
162 
163  };
164 
165 
166 
170  class SeenDevice {
171  public:
175  SeenDevice(const MeetingPoint& meetingBegin_)
176  : meetingBegin(meetingBegin_), meetingEnd(0), lastView(meetingBegin_.t), nextView(-1.) {}
177 
180  delete meetingEnd;
181  for (std::vector<MeetingPoint*>::iterator i = recognitionPoints.begin(); i != recognitionPoints.end(); ++i) {
182  delete *i;
183  }
184  recognitionPoints.clear();
185  }
186 
187 
188  public:
194  double lastView;
196  double nextView;
198  std::vector<MeetingPoint*> recognitionPoints;
200  std::string receiverRoute;
202  std::string senderRoute;
203 
204  private:
207 
208  };
209 
210 
211 
216  static void cleanUp(std::map<std::string, SeenDevice*>& c, std::map<std::string, std::vector<SeenDevice*> >& s);
217 
218 
219 
220 protected:
226  MSDevice_BTreceiver(SUMOVehicle& holder, const std::string& id);
227 
228 
229 
230 private:
232  static bool myWasInitialised;
233 
235  static double myRange;
236 
238  static double myOffTime;
239 
240 
245  public:
250  VehicleInformation(const std::string& id, const double _range) : MSDevice_BTsender::VehicleInformation(id), range(_range) {}
251 
254  std::map<std::string, SeenDevice*>::iterator i;
255  for (i = currentlySeen.begin(); i != currentlySeen.end(); i++) {
256  delete i->second;
257  }
258  std::map<std::string, std::vector<SeenDevice*> >::iterator j;
259  std::vector<SeenDevice*>::iterator k;
260  for (j = seen.begin(); j != seen.end(); j++) {
261  for (k = j->second.begin(); k != j->second.end(); k++) {
262  delete *k;
263  }
264  }
265  }
266 
268  const double range;
269 
271  std::map<std::string, SeenDevice*> currentlySeen;
272 
274  std::map<std::string, std::vector<SeenDevice*> > seen;
275 
276  private:
279 
282 
283  };
284 
285 
286 
290  class BTreceiverUpdate : public Command {
291  public:
294 
297 
302  SUMOTime execute(SUMOTime currentTime);
303 
304 
310 
311 
319  void enterRange(double atOffset, const MSDevice_BTsender::VehicleState& receiverState,
320  const std::string& senderID, const MSDevice_BTsender::VehicleState& senderState,
321  std::map<std::string, SeenDevice*>& currentlySeen);
322 
323 
331  void leaveRange(VehicleInformation& receiverInfo, const MSDevice_BTsender::VehicleState& receiverState,
333  double tOffset);
334 
335 
336 
337 
344  void addRecognitionPoint(const double tEnd, const MSDevice_BTsender::VehicleState& receiverState,
345  const MSDevice_BTsender::VehicleState& senderState,
346  SeenDevice* senderDevice) const;
347 
348 
354  void writeOutput(const std::string& id, const std::map<std::string, std::vector<SeenDevice*> >& seen,
355  bool allRecognitions);
356 
357 
358 
359 
360  };
361 
362 
363  static double inquiryDelaySlots(const int backoffLimit);
364 
366  static std::mt19937 sRecognitionRNG;
367 
369  static std::map<std::string, VehicleInformation*> sVehicles;
370 
371 
372 
373 private:
376 
379 
380 
381 };
long long int SUMOTime
Definition: SUMOTime.h:31
Base (microsim) event class.
Definition: Command.h:49
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.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_BTreceiver-options.
static double getRange()
Returns the configured range.
static bool myWasInitialised
Whether the bt-system was already initialised.
static double inquiryDelaySlots(const int backoffLimit)
static std::mt19937 sRecognitionRNG
A random number generator used to determine whether the opposite was recognized.
static double myRange
The range of the device.
static std::mt19937 * getRNG()
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
MSDevice_BTreceiver(const MSDevice_BTreceiver &)
Invalidated copy constructor.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
static std::map< std::string, VehicleInformation * > sVehicles
The list of arrived receivers.
const std::string deviceName() const
return the name for this type of device
bool notifyEnter(SUMOTrafficObject &veh, Notification reason, const MSLane *enteredLane=0)
Adds the vehicle to running vehicles if it (re-) enters the network.
MSDevice_BTreceiver(SUMOVehicle &holder, const std::string &id)
Constructor.
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.
MSDevice_BTreceiver & operator=(const MSDevice_BTreceiver &)
Invalidated assignment operator.
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, Notification reason, const MSLane *enteredLane=0)
Moves (the known) vehicle from running to arrived vehicles' list.
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:82
Notification
Definition of a vehicle state.
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:58