1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2003-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 /****************************************************************************/
10 /// @file    MSMoveReminder.h
11 /// @author  Christian Roessel
12 /// @author  Daniel Krajzewicz
13 /// @author  Sascha Krieg
14 /// @author  Michael Behrisch
15 /// @author  Jakob Erdmann
16 /// @date    2003-05-21
17 /// @version $Id$
18 ///
19 // Something on a lane to be noticed about vehicle movement
20 /****************************************************************************/
21 #ifndef MSMoveReminder_h
22 #define MSMoveReminder_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #include <config.h>
29 
30 #include <iostream>
31 #include <map>
32 #include <utils/common/SUMOTime.h>
33 #include <utils/common/StdDefs.h>
34 
35 
36 // ===========================================================================
37 // class declarations
38 // ===========================================================================
39 class SUMOTrafficObject;
40 class MSLane;
41 
42 
43 // ===========================================================================
44 // class definitions
45 // ===========================================================================
46 /**
47  * @class MSMoveReminder
48  * @brief Something on a lane to be noticed about vehicle movement
49  *
50  * Base class of all move-reminders. During move, the vehicles call
51  *  notifyMove() for all reminders on their current lane (all lanes
52  *  they pass during one step). If a vehicle enters the lane the reminder is
53  *  positioned at during insertion or lanechange notifyEnter() is
54  *  called. If a vehicle leaves the reminder lane it calls notifyLeave().
55  *
56  * The reminder knows whom to tell about move, insertion and lanechange. The
57  * vehicles will remove the reminder that is not notifyMove() from
58  * their reminder container.
59  *
60  * @see MSLane::addMoveReminder
61  * @see MSLane::getMoveReminder
62  * @note: cannot inherit from Named because it would couse double inheritance
63  */
64 class MSMoveReminder {
65 public:
66     /** @brief Constructor.
67      *
68      * @param[in] lane Lane on which the reminder will work.
69      * @param[in] doAdd whether to add the reminder to the lane
70      */
71     MSMoveReminder(const std::string& description, MSLane* const lane = 0, const bool doAdd = true);
72 
73 
74     /** @brief Destructor
75      */
~MSMoveReminder()76     virtual ~MSMoveReminder() {}
77 
78 
79     /** @brief Returns the lane the reminder works on.
80      *
81      * @return The lane the reminder is anchored on.
82      */
getLane()83     const MSLane* getLane() const {
84         return myLane;
85     }
86 
87 
88     /// @brief Definition of a vehicle state
89     enum Notification {
90         /// @brief The vehicle has departed (was inserted into the network)
91         NOTIFICATION_DEPARTED,
92         /// @brief The vehicle arrived at a junction
93         NOTIFICATION_JUNCTION,
94         /// @brief The vehicle changes the segment (meso only)
95         NOTIFICATION_SEGMENT,
96         /// @brief The vehicle changes lanes (micro only)
97         NOTIFICATION_LANE_CHANGE,
98         /* All notifications below must result in the vehicle not being on the net
99          * (onLeaveLane sets amOnNet=false if reason>=NOTIFICATION_TELEPORT) */
100         /// @brief The vehicle is being teleported
101         NOTIFICATION_TELEPORT,
102         /// @brief The vehicle starts or ends parking
103         NOTIFICATION_PARKING,
104         /// @brief The vehicle arrived at its destination (is deleted)
105         NOTIFICATION_ARRIVED, // arrived and everything after is treated as permanent deletion from the net
106         /// @brief The vehicle got vaporized
107         NOTIFICATION_VAPORIZED,
108         /// @brief The vehicle was teleported out of the net
109         NOTIFICATION_TELEPORT_ARRIVED,
110         /// @brief The vehicle needs another parking area
111         NOTIFICATION_PARKING_REROUTE
112     };
113 
114 
115     /// @name Interface methods, to be derived by subclasses
116     /// @{
117 
118     /** @brief Checks whether the reminder is activated by a vehicle entering the lane
119      *
120      * Lane change means in this case that the vehicle changes to the lane
121      *  the reminder is placed at.
122      *
123      * @param[in] veh The entering vehicle.
124      * @param[in] reason how the vehicle enters the lane
125      * @return True if vehicle enters the reminder.
126      * @see Notification
127      */
notifyEnter(SUMOTrafficObject & veh,Notification reason,const MSLane * enteredLane)128     virtual bool notifyEnter(SUMOTrafficObject& veh, Notification reason, const MSLane* enteredLane) {
129         UNUSED_PARAMETER(reason);
130         UNUSED_PARAMETER(&veh);
131         UNUSED_PARAMETER(&enteredLane);
132         return true;
133     }
134 
135 
136     /** @brief Checks whether the reminder still has to be notified about the vehicle moves
137      *
138      * Indicator if the reminders is still active for the passed
139      * vehicle/parameters. If false, the vehicle will erase this reminder
140      * from it's reminder-container.
141      *
142      * @param[in] veh Vehicle that asks this reminder.
143      * @param[in] oldPos Position before move.
144      * @param[in] newPos Position after move with newSpeed.
145      * @param[in] newSpeed Moving speed.
146      *
147      * @return True if vehicle hasn't passed the reminder completely.
148      */
notifyMove(SUMOTrafficObject & veh,double oldPos,double newPos,double newSpeed)149     virtual bool notifyMove(SUMOTrafficObject& veh,
150                             double oldPos,
151                             double newPos,
152                             double newSpeed) {
153         UNUSED_PARAMETER(oldPos);
154         UNUSED_PARAMETER(newPos);
155         UNUSED_PARAMETER(newSpeed);
156         UNUSED_PARAMETER(&veh);
157         return true;
158     }
159 
160 
161     /** @brief Called if the vehicle leaves the reminder's lane
162      *
163      * Informs if vehicle leaves reminder lane (due to lane change, removal
164      *  from the network, or leaving to the next lane).
165      *  The default is to do nothing.
166      *
167      * @param[in] veh The leaving vehicle.
168      * @param[in] lastPos Position on the lane when leaving.
169      * @param[in] reason how the vehicle leaves the lane
170      * @see Notification
171      *
172      * @return True if the reminder wants to receive further info.
173      */
174     virtual bool notifyLeave(SUMOTrafficObject& veh, double lastPos, Notification reason, const MSLane* enteredLane = 0) {
175         UNUSED_PARAMETER(&veh);
176         UNUSED_PARAMETER(lastPos);
177         UNUSED_PARAMETER(reason);
178         UNUSED_PARAMETER(enteredLane);
179         return true;
180     }
181 
182 
183     // TODO: Documentation
184     void updateDetector(SUMOTrafficObject& veh, double entryPos, double leavePos,
185                         SUMOTime entryTime, SUMOTime currentTime, SUMOTime leaveTime,
186                         bool cleanUp);
187 
188     /// @}
189 
190     /** @brief Internal notification about the vehicle moves.
191      *  @note meso uses this though it never calls notifyMove()
192      *
193      * Indicator if the reminders is still active for the passed
194      * vehicle/parameters. If false, the vehicle will erase this reminder
195      * from it's reminder-container.
196      *
197      * @param[in] veh Vehicle that asks this reminder.
198      * @param[in] frontOnLane time the front of the vehicle spent on the lane.
199      * @param[in] timeOnLane time some part of the vehicle spent on the lane.
200      * @param[in] meanSpeedFrontOnLane Average speed for the time that the front is on the lane.
201      * @param[in] meanSpeedVehicleOnLane Average speed for the time that the vehicle is on the lane (with front or back).
202      * @param[in] travelledDistanceFrontOnLane distance travelled while overlapping with the lane.
203      * @param[in] travelledDistanceVehicleOnLane distance travelled while front was on the lane.
204      * @param[in] meanLengthOnLane the average length of the vehicle's part on the lane during the last step (==complete length in meso case)
205      */
notifyMoveInternal(const SUMOTrafficObject & veh,const double frontOnLane,const double timeOnLane,const double meanSpeedFrontOnLane,const double meanSpeedVehicleOnLane,const double travelledDistanceFrontOnLane,const double travelledDistanceVehicleOnLane,const double meanLengthOnLane)206     virtual void notifyMoveInternal(const SUMOTrafficObject& veh,
207                                     const double frontOnLane,
208                                     const double timeOnLane,
209                                     const double meanSpeedFrontOnLane,
210                                     const double meanSpeedVehicleOnLane,
211                                     const double travelledDistanceFrontOnLane,
212                                     const double travelledDistanceVehicleOnLane,
213                                     const double meanLengthOnLane) {
214         UNUSED_PARAMETER(meanLengthOnLane);
215         UNUSED_PARAMETER(travelledDistanceFrontOnLane);
216         UNUSED_PARAMETER(travelledDistanceVehicleOnLane);
217         UNUSED_PARAMETER(meanSpeedVehicleOnLane);
218         UNUSED_PARAMETER(meanSpeedFrontOnLane);
219         UNUSED_PARAMETER(frontOnLane);
220         UNUSED_PARAMETER(timeOnLane);
221         UNUSED_PARAMETER(&veh);
222     }
223 
setDescription(const std::string & description)224     void setDescription(const std::string& description) {
225         myDescription = description;
226     }
227 
getDescription()228     const std::string& getDescription() const {
229         return myDescription;
230     }
231 
232 protected:
233     void removeFromVehicleUpdateValues(SUMOTrafficObject& veh);
234 
235 protected:
236 
237     /// @brief Lane on which the reminder works
238     MSLane* const myLane;
239     /// @brief a description of this moveReminder
240     std::string myDescription;
241 
242 private:
243     std::map<SUMOTrafficObject*, std::pair<SUMOTime, double> > myLastVehicleUpdateValues;
244 
245 
246 private:
247     MSMoveReminder& operator=(const MSMoveReminder&); // just to avoid a compiler warning
248 
249 };
250 
251 
252 #endif
253 
254 /****************************************************************************/
255 
256