/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2003-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file MSMoveReminder.h14/// @author Christian Roessel15/// @author Daniel Krajzewicz16/// @author Sascha Krieg17/// @author Michael Behrisch18/// @author Jakob Erdmann19/// @date 2003-05-2120///21// Something on a lane to be noticed about vehicle movement22/****************************************************************************/23#pragma once24#include <config.h>2526#include <iostream>27#include <map>28#include <utils/common/SUMOTime.h>29#include <utils/common/StdDefs.h>30#include <utils/common/StringBijection.h>31#ifdef HAVE_FOX32#include <utils/foxtools/fxheader.h>33#endif343536// ===========================================================================37// class declarations38// ===========================================================================39class SUMOTrafficObject;40class OutputDevice;41class MSLane;424344// ===========================================================================45// class definitions46// ===========================================================================47/**48* @class MSMoveReminder49* @brief Something on a lane to be noticed about vehicle movement50*51* Base class of all move-reminders. During move, the vehicles call52* notifyMove() for all reminders on their current lane (all lanes53* they pass during one step). If a vehicle enters the lane the reminder is54* positioned at during insertion or lanechange notifyEnter() is55* called. If a vehicle leaves the reminder lane it calls notifyLeave().56*57* The reminder knows whom to tell about move, insertion and lanechange. The58* vehicles will remove the reminder that is not notifyMove() from59* their reminder container.60*61* @see MSLane::addMoveReminder62* @see MSLane::getMoveReminder63* @note: cannot inherit from Named because it would couse double inheritance64*/65class MSMoveReminder {66public:67/** @brief Constructor.68*69* @param[in] lane Lane on which the reminder will work.70* @param[in] doAdd whether to add the reminder to the lane71*/72MSMoveReminder(const std::string& description, MSLane* const lane = nullptr, const bool doAdd = true);737475/** @brief Destructor76*/77virtual ~MSMoveReminder() {}787980/** @brief Returns the lane the reminder works on.81*82* @return The lane the reminder is anchored on.83*/84const MSLane* getLane() const {85return myLane;86}878889/// @brief Definition of a vehicle state90enum Notification {91/// @brief The vehicle has departed (was inserted into the network)92NOTIFICATION_DEPARTED,93/// @brief The vehicle arrived at a junction94NOTIFICATION_JUNCTION,95/// @brief The vehicle changes the segment (meso only)96NOTIFICATION_SEGMENT,97/// @brief The vehicle changes lanes (micro only)98NOTIFICATION_LANE_CHANGE,99/// @brief The vehicle has been loaded from a state file100NOTIFICATION_LOAD_STATE,101/* All notifications below must result in the vehicle not being on the net102* (onLeaveLane sets amOnNet=false if reason>=NOTIFICATION_TELEPORT) */103/// @brief The vehicle is being teleported104NOTIFICATION_TELEPORT,105/// @brief The vehicle continues being teleported past an edge106NOTIFICATION_TELEPORT_CONTINUATION,107/// @brief The vehicle starts or ends parking108NOTIFICATION_PARKING,109/// @brief The vehicle changed it's route110NOTIFICATION_REROUTE,111/// @brief The vehicle needs another parking area112NOTIFICATION_PARKING_REROUTE,113/// @brief The vehicle arrived at its destination (is deleted)114NOTIFICATION_ARRIVED, // arrived and everything after is treated as permanent deletion from the net115/// @brief The vehicle was teleported out of the net116NOTIFICATION_TELEPORT_ARRIVED,117/// @brief The vehicle got removed by a calibrator118NOTIFICATION_VAPORIZED_CALIBRATOR,119/// @brief The vehicle got removed by a collision120NOTIFICATION_VAPORIZED_COLLISION,121/// @brief The vehicle got removed via TraCI122NOTIFICATION_VAPORIZED_TRACI,123/// @brief The vehicle got removed via the GUI124NOTIFICATION_VAPORIZED_GUI,125/// @brief The vehicle got vaporized with a vaporizer126NOTIFICATION_VAPORIZED_VAPORIZER,127/// @brief The vehicle got removed via stationfinder device128NOTIFICATION_VAPORIZED_BREAKDOWN,129/// @brief must be the last one130NOTIFICATION_NONE131};132133134/// @name Interface methods, to be derived by subclasses135/// @{136137/** @brief Checks whether the reminder is activated by a vehicle entering the lane138*139* Lane change means in this case that the vehicle changes to the lane140* the reminder is placed at.141*142* @param[in] veh The entering vehicle.143* @param[in] reason how the vehicle enters the lane144* @return True if vehicle enters the reminder.145* @see Notification146*/147virtual bool notifyEnter(SUMOTrafficObject& veh, Notification reason, const MSLane* enteredLane) {148UNUSED_PARAMETER(reason);149UNUSED_PARAMETER(&veh);150UNUSED_PARAMETER(&enteredLane);151return true;152}153154155/** @brief Checks whether the reminder still has to be notified about the vehicle moves156*157* Indicator if the reminders is still active for the passed158* vehicle/parameters. If false, the vehicle will erase this reminder159* from its reminder-container.160*161* @param[in] veh Vehicle that asks this reminder.162* @param[in] oldPos Position before move.163* @param[in] newPos Position after move with newSpeed.164* @param[in] newSpeed Moving speed.165*166* @return True if vehicle hasn't passed the reminder completely.167*/168virtual bool notifyMove(SUMOTrafficObject& veh,169double oldPos,170double newPos,171double newSpeed) {172UNUSED_PARAMETER(oldPos);173UNUSED_PARAMETER(newPos);174UNUSED_PARAMETER(newSpeed);175UNUSED_PARAMETER(&veh);176return true;177}178179/** @brief Computes idling emission values and adds them to the emission sums180*181* Idling implied by zero velocity, acceleration and slope182*183* @param[in] veh The vehicle184*185* @see MSMoveReminder::notifyMove186* @see PollutantsInterface187*/188virtual bool notifyIdle(SUMOTrafficObject& veh) {189UNUSED_PARAMETER(&veh);190return true;191}192193/// @brief called to update state for parking vehicles194virtual void notifyParking() {}195196/// @brief called to update state for stopped vehicles197virtual void notifyStopEnded() {}198199/** @brief Called if the vehicle leaves the reminder's lane200*201* Informs if vehicle leaves reminder lane (due to lane change, removal202* from the network, or leaving to the next lane).203* The default is to do nothing.204*205* @param[in] veh The leaving vehicle.206* @param[in] lastPos Position on the lane when leaving.207* @param[in] reason how the vehicle leaves the lane208* @see Notification209*210* @return True if the reminder wants to receive further info.211*/212virtual bool notifyLeave(SUMOTrafficObject& veh, double lastPos, Notification reason, const MSLane* enteredLane = nullptr) {213UNUSED_PARAMETER(&veh);214UNUSED_PARAMETER(lastPos);215UNUSED_PARAMETER(reason);216UNUSED_PARAMETER(enteredLane);217return true;218}219220/** @brief Called if the vehicle's back leaves the reminder's lane221*222* Informs if vehicle back leaves reminder lane (due to lane change, removal223* from the network, or leaving to the next lane).224* The default is to do nothing.225*226* @param[in] veh The leaving vehicle.227* @param[in] reason how the vehicle leaves the lane228* @param[in] leftLane The lane that the vehicle's back left229* @see Notification230*231* @return True if the reminder wants to receive further info.232*/233virtual bool notifyLeaveBack(SUMOTrafficObject& veh, Notification reason, const MSLane* leftLane) {234UNUSED_PARAMETER(&veh);235UNUSED_PARAMETER(reason);236UNUSED_PARAMETER(leftLane);237return true;238}239240/** @brief Called if the vehicle change it's route241* @param[in] veh The rerouted vehicle.242* @return True if the reminder wants to receive further info.243*/244virtual bool notifyReroute(SUMOTrafficObject& veh) {245UNUSED_PARAMETER(&veh);246return true;247}248249// TODO: Documentation250void updateDetector(SUMOTrafficObject& veh, double entryPos, double leavePos,251SUMOTime entryTime, SUMOTime currentTime, SUMOTime leaveTime,252bool cleanUp);253254/// @}255256/** @brief Internal notification about the vehicle moves.257* @note meso uses this though it never calls notifyMove()258*259* Indicator if the reminders is still active for the passed260* vehicle/parameters. If false, the vehicle will erase this reminder261* from its reminder-container.262*263* @param[in] veh Vehicle that asks this reminder.264* @param[in] frontOnLane time the front of the vehicle spent on the lane.265* @param[in] timeOnLane time some part of the vehicle spent on the lane.266* @param[in] meanSpeedFrontOnLane Average speed for the time that the front is on the lane.267* @param[in] meanSpeedVehicleOnLane Average speed for the time that the vehicle is on the lane (with front or back).268* @param[in] travelledDistanceFrontOnLane distance travelled while overlapping with the lane.269* @param[in] travelledDistanceVehicleOnLane distance travelled while front was on the lane.270* @param[in] meanLengthOnLane the average length of the vehicle's part on the lane during the last step (==complete length in meso case)271*/272virtual void notifyMoveInternal(const SUMOTrafficObject& veh,273const double frontOnLane,274const double timeOnLane,275const double meanSpeedFrontOnLane,276const double meanSpeedVehicleOnLane,277const double travelledDistanceFrontOnLane,278const double travelledDistanceVehicleOnLane,279const double meanLengthOnLane) {280UNUSED_PARAMETER(&veh);281UNUSED_PARAMETER(frontOnLane);282UNUSED_PARAMETER(timeOnLane);283UNUSED_PARAMETER(meanSpeedFrontOnLane);284UNUSED_PARAMETER(meanSpeedVehicleOnLane);285UNUSED_PARAMETER(travelledDistanceFrontOnLane);286UNUSED_PARAMETER(travelledDistanceVehicleOnLane);287UNUSED_PARAMETER(meanLengthOnLane);288}289290void setDescription(const std::string& description) {291myDescription = description;292}293294const std::string& getDescription() const {295return myDescription;296}297298// @brief return whether this moveReminder triggers parking reroute299virtual bool isParkingRerouter() const {300return false;301}302303/** @brief Saves the current state into the given stream */304void saveReminderState(OutputDevice& out, const SUMOTrafficObject& veh);305306void loadReminderState(long long int numID, SUMOTime time, double pos);307308static StringBijection<Notification> Notifications;309310protected:311void removeFromVehicleUpdateValues(SUMOTrafficObject& veh);312313protected:314315/// @brief Lane on which the reminder works316MSLane* myLane;317/// @brief a description of this moveReminder318std::string myDescription;319320#ifdef HAVE_FOX321/// @brief the mutex for notifications322mutable FXMutex myNotificationMutex;323#endif324325private:326std::map<long long int, std::pair<SUMOTime, double> > myLastVehicleUpdateValues;327static StringBijection<Notification>::Entry NotificationValues[];328329330private:331MSMoveReminder& operator=(const MSMoveReminder&); // just to avoid a compiler warning332333};334335336