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
67 void addLeaderCar(MEVehicle* veh, MSLink* link);
68
74
77
79 static bool isEnteringRoundabout(const MSEdge& e);
80
82 static int numSegmentsFor(const double length, const double slength);
83
88 void buildSegmentsFor(const MSEdge& e, const OptionsCont& oc);
89
96 MESegment* getSegmentForEdge(const MSEdge& e, double pos = 0);
97
102 SUMOTime changeSegment(MEVehicle* veh, SUMOTime leaveTime, MESegment* const toSegment,
103 MSMoveReminder::Notification reason, const bool ignoreLink = false) const;
104
106 void clearState();
107
108private:
116 void checkCar(MEVehicle* veh);
117
130
131
136 void teleportVehicle(MEVehicle* veh, MESegment* const toSegment, bool disconnected);
137
138private:
139
140 struct LeaderEvent {
142
144 // eventIndex ensures stable sorting of vehicles with the same event time
145 long long int eventIndex;
146 // nid allows safely comparing events for deleted vehicles (myInvalidatedLeaderCars)
147 long long int nid;
149
150 bool operator<(const LeaderEvent& b) const {
151 if (time == b.time) {
152 return eventIndex > b.eventIndex;
153 }
154 return time > b.time;
155 }
156
157 bool operator==(const LeaderEvent& b) const {
158 return time == b.time && nid == b.nid;
159 }
160
161 static long long int myEventCounter;
162 };
163
165 typedef std::priority_queue<LeaderEvent> LeaderEventQeue;
168
170 std::vector<MESegment*> myEdges2FirstSegments;
171
174
177
178private:
180 MELoop(const MELoop&);
181
184};
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:279
static bool isEnteringRoundabout(const MSEdge &e)
whether the given edge is entering a roundabout
Definition MELoop.cpp:361
MELoop(const MELoop &)
Invalidated copy constructor.
LeaderEventQeue myInvalidatedLeaderCars
Definition MELoop.h:167
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:88
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
Definition MELoop.cpp:344
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:176
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:173
void vaporizeCar(MEVehicle *v, MSMoveReminder::Notification reason)
remove the given car and clean up the relevant data structures
Definition MELoop.cpp:271
void addLeaderCar(MEVehicle *veh, MSLink *link)
Adds the given car to the leading vehicles.
Definition MELoop.cpp:251
void clearState()
Remove all vehicles before quick-loading state.
Definition MELoop.cpp:258
void removeLeaderCar(MEVehicle *v)
Removes the given car from the leading vehicles.
Definition MELoop.cpp:265
LeaderEventQeue myLeaderCars
Definition MELoop.h:166
std::vector< MESegment * > myEdges2FirstSegments
mapping from internal edge ids to their initial segments
Definition MELoop.h:170
~MELoop()
Definition MELoop.cpp:51
std::priority_queue< LeaderEvent > LeaderEventQeue
leader cars in the segments sorted by exit time
Definition MELoop.h:165
void checkCar(MEVehicle *veh)
Check whether the vehicle may move.
Definition MELoop.cpp:145
void teleportVehicle(MEVehicle *veh, MESegment *const toSegment, bool disconnected)
teleports a vehicle or continues a teleport
Definition MELoop.cpp:188
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:304
void buildSegmentsFor(const MSEdge &e, const OptionsCont &oc)
Build the segments for a given edge.
Definition MELoop.cpp:315
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:77
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:150
long long int eventIndex
Definition MELoop.h:145
MEVehicle * veh
Definition MELoop.h:148
static long long int myEventCounter
Definition MELoop.h:161
long long int nid
Definition MELoop.h:147
bool operator==(const LeaderEvent &b) const
Definition MELoop.h:157