/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2026 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 MELoop.h14/// @author Daniel Krajzewicz15/// @date Tue, May 200516///17// The main mesocopic simulation loop18/****************************************************************************/19#pragma once20#include <config.h>2122#include <vector>23#include <map>24#include <utils/common/SUMOTime.h>25#include <microsim/MSMoveReminder.h>262728// ===========================================================================29// class declarations30// ===========================================================================31class MESegment;32class MEVehicle;33class MSEdge;34class MSLink;35class MSVehicleControl;36class OptionsCont;373839// ===========================================================================40// class definitions41// ===========================================================================42/**43* @class MELoop44* @brief The main mesocopic simulation loop45*/46class MELoop {47public:48/// SUMO constructor49MELoop(const SUMOTime recheckInterval);5051~MELoop();5253/** @brief Perform simulation up to the given time54*55* Checks all vehicles with an event time less or equal than the given time.56*57* @param[in] tMax the end time for the sim step58*/59void simulate(SUMOTime tMax);6061/** @brief Adds the given car to the leading vehicles62*63* @param[in] veh the car which became a leading one64* @param[in] link the link on which the car shall register its approach65*/66void addLeaderCar(MEVehicle* veh, MSLink* link);6768/** @brief Removes the given car from the leading vehicles69*70* @param[in] v the car which was a leading one71*/72bool removeLeaderCar(MEVehicle* v);7374/** @brief remove the given car and clean up the relevant data structures */75void vaporizeCar(MEVehicle* v, MSMoveReminder::Notification reason);7677/// @brief whether the given edge is entering a roundabout78static bool isEnteringRoundabout(const MSEdge& e);7980/** @brief Compute number of segments per edge (best value stay close to the configured segment length) */81static int numSegmentsFor(const double length, const double slength);8283/** @brief Build the segments for a given edge84*85* @param[in] e the edge to build for86*/87void buildSegmentsFor(const MSEdge& e, const OptionsCont& oc);8889/** @brief Get the segment for a given edge at a given position90*91* @param[in] e the edge to get the segment for92* @param[in] pos the position to get the segment for93* @return The relevant segment94*/95MESegment* getSegmentForEdge(const MSEdge& e, double pos = 0);9697/** @brief change to the next segment98* this handles combinations of the following cases:99* (ending / continuing route) and (leaving segment / finishing teleport)100*/101SUMOTime changeSegment(MEVehicle* veh, SUMOTime leaveTime, MESegment* const toSegment,102MSMoveReminder::Notification reason, const bool ignoreLink = false) const;103104/** @brief Remove all vehicles before quick-loading state */105void clearState();106107private:108/** @brief Check whether the vehicle may move109*110* This method is called when the vehicle reaches its event time and checks111* whether it may proceed to the next segment.112*113* @param[in] veh The vehicle to check114*/115void checkCar(MEVehicle* veh);116117/** @brief Retrieve next segment118*119* If the segment is not the last on the current edge, its successor is returned.120* Otherwise, the first segment of the edge at which the vehicle continues121* his journey is returned.122*123* @param[in] s The segment the vehicle is currently at124* @param[in] v The vehicle to get the next segment for125* @return The vehicle's next segment126* @todo Recheck the "quick and dirty" stuff (@see MESegment::saveState, @see MESegment::loadState)127*/128MESegment* nextSegment(MESegment* s, MEVehicle* v);129130131/** @brief teleports a vehicle or continues a teleport132* @param[in] veh The vehicle to teleport133* @param[in] toSegment The first segment where the vehicle may reenter the network134*/135void teleportVehicle(MEVehicle* veh, MESegment* const toSegment, bool disconnected);136137private:138/// @brief leader cars in the segments sorted by exit time139std::map<SUMOTime, std::vector<MEVehicle*> > myLeaderCars;140141/// @brief mapping from internal edge ids to their initial segments142std::vector<MESegment*> myEdges2FirstSegments;143144/// @brief the interval at which to recheck at full segments (<=0 means asap)145const SUMOTime myFullRecheckInterval;146147/// @brief the interval at which to recheck at blocked junctions (<=0 means asap)148const SUMOTime myLinkRecheckInterval;149150private:151/// @brief Invalidated copy constructor.152MELoop(const MELoop&);153154/// @brief Invalidated assignment operator.155MELoop& operator=(const MELoop&);156};157158159