Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MELoop.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2026 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/****************************************************************************/
18// The main mesocopic simulation loop
19/****************************************************************************/
20#pragma once
21#include <config.h>
22
23#include <vector>
24#include <queue>
25#include <map>
28
29
30// ===========================================================================
31// class declarations
32// ===========================================================================
33class MESegment;
34class MEVehicle;
35class MSEdge;
36class MSLink;
38class OptionsCont;
39
40// ===========================================================================
41// class definitions
42// ===========================================================================
47class MELoop {
48public:
50 MELoop(const SUMOTime recheckInterval);
51
52 ~MELoop();
53
60 void simulate(SUMOTime tMax);
61
68 void addLeaderCar(MEVehicle* veh, MSLink* link, const bool fromState = false);
69
75
78
80 static bool isEnteringRoundabout(const MSEdge& e);
81
83 static int numSegmentsFor(const double length, const double slength);
84
89 void buildSegmentsFor(const MSEdge& e, const OptionsCont& oc);
90
97 MESegment* getSegmentForEdge(const MSEdge& e, double pos = 0);
98
103 SUMOTime changeSegment(MEVehicle* veh, SUMOTime leaveTime, MESegment* const toSegment,
104 MSMoveReminder::Notification reason, const bool ignoreLink = false) const;
105
107 void clearState();
108
110 static long long int getEventCounter() {
112 }
113
114 static void setEventCounter(long long int counter) {
116 }
117
118private:
126 void checkCar(MEVehicle* veh);
127
140
141
146 void teleportVehicle(MEVehicle* veh, MESegment* const toSegment, bool disconnected);
147
148private:
149
150 struct LeaderEvent {
152
154 // eventIndex ensures stable sorting of vehicles with the same event time
155 long long int eventIndex;
156 // nid allows safely comparing events for deleted vehicles (myInvalidatedLeaderCars)
157 long long int nid;
159
160 bool operator<(const LeaderEvent& b) const {
161 if (time == b.time) {
162 return eventIndex > b.eventIndex;
163 }
164 return time > b.time;
165 }
166
167 bool operator==(const LeaderEvent& b) const {
168 return time == b.time && nid == b.nid;
169 }
170
171 static long long int myEventCounter;
172 };
173
175 bool wasInvalidated(const LeaderEvent& e);
176
177
179 typedef std::priority_queue<LeaderEvent> LeaderEventQeue;
182
184 std::vector<MESegment*> myEdges2FirstSegments;
185
188
191
192private:
194 MELoop(const MELoop&);
195
198};
long long int SUMOTime
Definition GUI.h:36
The main mesocopic simulation loop.
Definition MELoop.h:47
MESegment * nextSegment(MESegment *s, MEVehicle *v)
Retrieve next segment.
Definition MELoop.cpp:332
static void setEventCounter(long long int counter)
Definition MELoop.h:114
static bool isEnteringRoundabout(const MSEdge &e)
whether the given edge is entering a roundabout
Definition MELoop.cpp:414
static long long int getEventCounter()
the number of leader events so far (for saving and loading state)
Definition MELoop.h:110
void addLeaderCar(MEVehicle *veh, MSLink *link, const bool fromState=false)
Adds the given car to the leading vehicles.
Definition MELoop.cpp:301
MELoop(const MELoop &)
Invalidated copy constructor.
bool wasInvalidated(const LeaderEvent &e)
check whether the current car was invalidated and remove it from myInvalidatedLeaderCars
Definition MELoop.cpp:87
LeaderEventQeue myInvalidatedLeaderCars
Definition MELoop.h:181
SUMOTime changeSegment(MEVehicle *veh, SUMOTime leaveTime, MESegment *const toSegment, MSMoveReminder::Notification reason, const bool ignoreLink=false) const
change to the next segment this handles combinations of the following cases: (ending / continuing rou...
Definition MELoop.cpp:114
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
Definition MELoop.cpp:397
MELoop & operator=(const MELoop &)
Invalidated assignment operator.
const SUMOTime myLinkRecheckInterval
the interval at which to recheck at blocked junctions (<=0 means asap)
Definition MELoop.h:190
void simulate(SUMOTime tMax)
Perform simulation up to the given time.
Definition MELoop.cpp:63
const SUMOTime myFullRecheckInterval
the interval at which to recheck at full segments (<=0 means asap)
Definition MELoop.h:187
void vaporizeCar(MEVehicle *v, MSMoveReminder::Notification reason)
remove the given car and clean up the relevant data structures
Definition MELoop.cpp:324
void clearState()
Remove all vehicles before quick-loading state.
Definition MELoop.cpp:311
void removeLeaderCar(MEVehicle *v)
Removes the given car from the leading vehicles.
Definition MELoop.cpp:318
LeaderEventQeue myLeaderCars
Definition MELoop.h:180
std::vector< MESegment * > myEdges2FirstSegments
mapping from internal edge ids to their initial segments
Definition MELoop.h:184
~MELoop()
Definition MELoop.cpp:51
std::priority_queue< LeaderEvent > LeaderEventQeue
leader cars in the segments sorted by exit time
Definition MELoop.h:179
void checkCar(MEVehicle *veh)
Check whether the vehicle may move.
Definition MELoop.cpp:186
void teleportVehicle(MEVehicle *veh, MESegment *const toSegment, bool disconnected)
teleports a vehicle or continues a teleport
Definition MELoop.cpp:238
static int numSegmentsFor(const double length, const double slength)
Compute number of segments per edge (best value stay close to the configured segment length)
Definition MELoop.cpp:357
void buildSegmentsFor(const MSEdge &e, const OptionsCont &oc)
Build the segments for a given edge.
Definition MELoop.cpp:368
A single mesoscopic segment (cell)
Definition MESegment.h:50
A vehicle from the mesoscopic point of view.
Definition MEVehicle.h:42
A road/street connecting two junctions.
Definition MSEdge.h:78
Notification
Definition of a vehicle state.
The class responsible for building and deletion of vehicles.
A storage for options typed value containers)
Definition OptionsCont.h:89
bool operator<(const LeaderEvent &b) const
Definition MELoop.h:160
long long int eventIndex
Definition MELoop.h:155
MEVehicle * veh
Definition MELoop.h:158
static long long int myEventCounter
Definition MELoop.h:171
long long int nid
Definition MELoop.h:157
bool operator==(const LeaderEvent &b) const
Definition MELoop.h:167