1 /****************************************************************************/ 2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo 3 // Copyright (C) 2001-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 MELoop.h 11 /// @author Daniel Krajzewicz 12 /// @date Tue, May 2005 13 /// @version $Id$ 14 /// 15 // The main mesocopic simulation loop 16 /****************************************************************************/ 17 #ifndef MELoop_h 18 #define MELoop_h 19 20 21 // =========================================================================== 22 // included modules 23 // =========================================================================== 24 #include <config.h> 25 26 #include <vector> 27 #include <map> 28 29 30 // =========================================================================== 31 // class declarations 32 // =========================================================================== 33 class MESegment; 34 class MEVehicle; 35 class MSEdge; 36 class MSLink; 37 class MSVehicleControl; 38 class BinaryInputDevice; 39 class OptionsCont; 40 41 42 // =========================================================================== 43 // class definitions 44 // =========================================================================== 45 /** 46 * @class MELoop 47 * @brief The main mesocopic simulation loop 48 */ 49 class MELoop { 50 public: 51 /// SUMO constructor 52 MELoop(const SUMOTime recheckInterval); 53 54 ~MELoop(); 55 56 /** @brief Perform simulation up to the given time 57 * 58 * Checks all vehicles with an event time less or equal than the given time. 59 * 60 * @param[in] tMax the end time for the sim step 61 */ 62 void simulate(SUMOTime tMax); 63 64 /** @brief Adds the given car to the leading vehicles 65 * 66 * @param[in] veh the car which became a leading one 67 * @param[in] link the link on which the car shall register its approach 68 */ 69 void addLeaderCar(MEVehicle* veh, MSLink* link); 70 71 /** @brief Removes the given car from the leading vehicles 72 * 73 * @param[in] v the car which was a leading one 74 */ 75 void removeLeaderCar(MEVehicle* v); 76 77 /** @brief Compute number of segments per edge (best value stay close to the configured segment length) */ 78 static int numSegmentsFor(const double length, const double slength); 79 80 /** @brief Build the segments for a given edge 81 * 82 * @param[in] e the edge to build for 83 */ 84 void buildSegmentsFor(const MSEdge& e, const OptionsCont& oc); 85 86 /** @brief Get the segment for a given edge at a given position 87 * 88 * @param[in] e the edge to get the segment for 89 * @param[in] pos the position to get the segment for 90 * @return The relevant segment 91 */ 92 MESegment* getSegmentForEdge(const MSEdge& e, double pos = 0); 93 94 /** @brief change to the next segment 95 * this handles combinations of the following cases: 96 * (ending / continuing route) and (leaving segment / finishing teleport) 97 */ 98 bool changeSegment(MEVehicle* veh, SUMOTime leaveTime, MESegment* const toSegment, const bool ignoreLink = false); 99 100 /** @brief registers vehicle with the given link 101 * 102 * @param[in] veh the car to register 103 * @param[in] link the link on which the car shall register its approach 104 */ 105 static void setApproaching(MEVehicle* veh, MSLink* link); 106 107 108 private: 109 /** @brief Check whether the vehicle may move 110 * 111 * This method is called when the vehicle reaches its event time and checks 112 * whether it may proceed to the next segment. 113 * 114 * @param[in] veh The vehicle to check 115 */ 116 void checkCar(MEVehicle* veh); 117 118 /** @brief Retrieve next segment 119 * 120 * If the segment is not the last on the current edge, its successor is returned. 121 * Otherwise, the first segment of the edge at which the vehicle continues 122 * his journey is returned. 123 * 124 * @param[in] s The segment the vehicle is currently at 125 * @param[in] v The vehicle to get the next segment for 126 * @return The vehicle's next segment 127 * @todo Recheck the "quick and dirty" stuff (@see MESegment::saveState, @see MESegment::loadState) 128 */ 129 MESegment* nextSegment(MESegment* s, MEVehicle* v); 130 131 132 /** @brief teleports a vehicle or continues a teleport 133 * @param[in] veh The vehicle to teleport 134 * @param[in] toSegment The first segment where the vehicle may reenter the network 135 */ 136 void teleportVehicle(MEVehicle* veh, MESegment* const toSegment); 137 138 /// @brief whether the given edge is entering a roundabout 139 static bool isEnteringRoundabout(const MSEdge& e); 140 141 private: 142 /// @brief leader cars in the segments sorted by exit time 143 std::map<SUMOTime, std::vector<MEVehicle*> > myLeaderCars; 144 145 /// @brief mapping from internal edge ids to their initial segments 146 std::vector<MESegment*> myEdges2FirstSegments; 147 148 /// @brief the interval at which to recheck at full segments (<=0 means asap) 149 const SUMOTime myFullRecheckInterval; 150 151 /// @brief the interval at which to recheck at blocked junctions (<=0 means asap) 152 const SUMOTime myLinkRecheckInterval; 153 154 private: 155 /// @brief Invalidated copy constructor. 156 MELoop(const MELoop&); 157 158 /// @brief Invalidated assignment operator. 159 MELoop& operator=(const MELoop&); 160 }; 161 162 163 #endif 164 165 /****************************************************************************/ 166 167