Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/mesosim/MELoop.h
169666 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file MELoop.h
15
/// @author Daniel Krajzewicz
16
/// @date Tue, May 2005
17
///
18
// The main mesocopic simulation loop
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <vector>
24
#include <map>
25
#include <utils/common/SUMOTime.h>
26
#include <microsim/MSMoveReminder.h>
27
28
29
// ===========================================================================
30
// class declarations
31
// ===========================================================================
32
class MESegment;
33
class MEVehicle;
34
class MSEdge;
35
class MSLink;
36
class MSVehicleControl;
37
class OptionsCont;
38
39
40
// ===========================================================================
41
// class definitions
42
// ===========================================================================
43
/**
44
* @class MELoop
45
* @brief The main mesocopic simulation loop
46
*/
47
class MELoop {
48
public:
49
/// SUMO constructor
50
MELoop(const SUMOTime recheckInterval);
51
52
~MELoop();
53
54
/** @brief Perform simulation up to the given time
55
*
56
* Checks all vehicles with an event time less or equal than the given time.
57
*
58
* @param[in] tMax the end time for the sim step
59
*/
60
void simulate(SUMOTime tMax);
61
62
/** @brief Adds the given car to the leading vehicles
63
*
64
* @param[in] veh the car which became a leading one
65
* @param[in] link the link on which the car shall register its approach
66
*/
67
void addLeaderCar(MEVehicle* veh, MSLink* link);
68
69
/** @brief Removes the given car from the leading vehicles
70
*
71
* @param[in] v the car which was a leading one
72
*/
73
bool removeLeaderCar(MEVehicle* v);
74
75
/** @brief remove the given car and clean up the relevant data structures */
76
void vaporizeCar(MEVehicle* v, MSMoveReminder::Notification reason);
77
78
/// @brief whether the given edge is entering a roundabout
79
static bool isEnteringRoundabout(const MSEdge& e);
80
81
/** @brief Compute number of segments per edge (best value stay close to the configured segment length) */
82
static int numSegmentsFor(const double length, const double slength);
83
84
/** @brief Build the segments for a given edge
85
*
86
* @param[in] e the edge to build for
87
*/
88
void buildSegmentsFor(const MSEdge& e, const OptionsCont& oc);
89
90
/** @brief Update segments after loading meso edge type parameters from
91
* additional file
92
* @param[in] e the edge to update
93
*/
94
void updateSegmentsForEdge(const MSEdge& e);
95
96
/** @brief Get the segment for a given edge at a given position
97
*
98
* @param[in] e the edge to get the segment for
99
* @param[in] pos the position to get the segment for
100
* @return The relevant segment
101
*/
102
MESegment* getSegmentForEdge(const MSEdge& e, double pos = 0);
103
104
/** @brief change to the next segment
105
* this handles combinations of the following cases:
106
* (ending / continuing route) and (leaving segment / finishing teleport)
107
*/
108
SUMOTime changeSegment(MEVehicle* veh, SUMOTime leaveTime, MESegment* const toSegment,
109
MSMoveReminder::Notification reason, const bool ignoreLink = false) const;
110
111
/** @brief Remove all vehicles before quick-loading state */
112
void clearState();
113
114
private:
115
/** @brief Check whether the vehicle may move
116
*
117
* This method is called when the vehicle reaches its event time and checks
118
* whether it may proceed to the next segment.
119
*
120
* @param[in] veh The vehicle to check
121
*/
122
void checkCar(MEVehicle* veh);
123
124
/** @brief Retrieve next segment
125
*
126
* If the segment is not the last on the current edge, its successor is returned.
127
* Otherwise, the first segment of the edge at which the vehicle continues
128
* his journey is returned.
129
*
130
* @param[in] s The segment the vehicle is currently at
131
* @param[in] v The vehicle to get the next segment for
132
* @return The vehicle's next segment
133
* @todo Recheck the "quick and dirty" stuff (@see MESegment::saveState, @see MESegment::loadState)
134
*/
135
MESegment* nextSegment(MESegment* s, MEVehicle* v);
136
137
138
/** @brief teleports a vehicle or continues a teleport
139
* @param[in] veh The vehicle to teleport
140
* @param[in] toSegment The first segment where the vehicle may reenter the network
141
*/
142
void teleportVehicle(MEVehicle* veh, MESegment* const toSegment, bool disconnected);
143
144
private:
145
/// @brief leader cars in the segments sorted by exit time
146
std::map<SUMOTime, std::vector<MEVehicle*> > myLeaderCars;
147
148
/// @brief mapping from internal edge ids to their initial segments
149
std::vector<MESegment*> myEdges2FirstSegments;
150
151
/// @brief the interval at which to recheck at full segments (<=0 means asap)
152
const SUMOTime myFullRecheckInterval;
153
154
/// @brief the interval at which to recheck at blocked junctions (<=0 means asap)
155
const SUMOTime myLinkRecheckInterval;
156
157
private:
158
/// @brief Invalidated copy constructor.
159
MELoop(const MELoop&);
160
161
/// @brief Invalidated assignment operator.
162
MELoop& operator=(const MELoop&);
163
};
164
165