/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-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 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 Update segments after loading meso edge type parameters from90* additional file91* @param[in] e the edge to update92*/93void updateSegmentsForEdge(const MSEdge& e);9495/** @brief Get the segment for a given edge at a given position96*97* @param[in] e the edge to get the segment for98* @param[in] pos the position to get the segment for99* @return The relevant segment100*/101MESegment* getSegmentForEdge(const MSEdge& e, double pos = 0);102103/** @brief change to the next segment104* this handles combinations of the following cases:105* (ending / continuing route) and (leaving segment / finishing teleport)106*/107SUMOTime changeSegment(MEVehicle* veh, SUMOTime leaveTime, MESegment* const toSegment,108MSMoveReminder::Notification reason, const bool ignoreLink = false) const;109110/** @brief Remove all vehicles before quick-loading state */111void clearState();112113private:114/** @brief Check whether the vehicle may move115*116* This method is called when the vehicle reaches its event time and checks117* whether it may proceed to the next segment.118*119* @param[in] veh The vehicle to check120*/121void checkCar(MEVehicle* veh);122123/** @brief Retrieve next segment124*125* If the segment is not the last on the current edge, its successor is returned.126* Otherwise, the first segment of the edge at which the vehicle continues127* his journey is returned.128*129* @param[in] s The segment the vehicle is currently at130* @param[in] v The vehicle to get the next segment for131* @return The vehicle's next segment132* @todo Recheck the "quick and dirty" stuff (@see MESegment::saveState, @see MESegment::loadState)133*/134MESegment* nextSegment(MESegment* s, MEVehicle* v);135136137/** @brief teleports a vehicle or continues a teleport138* @param[in] veh The vehicle to teleport139* @param[in] toSegment The first segment where the vehicle may reenter the network140*/141void teleportVehicle(MEVehicle* veh, MESegment* const toSegment, bool disconnected);142143private:144/// @brief leader cars in the segments sorted by exit time145std::map<SUMOTime, std::vector<MEVehicle*> > myLeaderCars;146147/// @brief mapping from internal edge ids to their initial segments148std::vector<MESegment*> myEdges2FirstSegments;149150/// @brief the interval at which to recheck at full segments (<=0 means asap)151const SUMOTime myFullRecheckInterval;152153/// @brief the interval at which to recheck at blocked junctions (<=0 means asap)154const SUMOTime myLinkRecheckInterval;155156private:157/// @brief Invalidated copy constructor.158MELoop(const MELoop&);159160/// @brief Invalidated assignment operator.161MELoop& operator=(const MELoop&);162};163164165