Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSDriveWay.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2002-2024 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// A sequende of rail tracks (lanes) that may be used as a "set route" (Fahrstraße)
19/****************************************************************************/
20#pragma once
21#include <config.h>
22
23#include <utils/common/Named.h>
25#include <microsim/MSRoute.h>
26
27// ===========================================================================
28// class declarations
29// ===========================================================================
30class SUMOVehicle;
31class MSLane;
32class MSLink;
33class MSRailSignal;
34
35// ===========================================================================
36// class definitions
37// ===========================================================================
41class MSDriveWay : public MSMoveReminder, public Named {
42public:
43 typedef std::pair<const SUMOVehicle* const, const MSLink::ApproachingVehicleInformation> Approaching;
44 typedef std::set<const MSLane*, ComparatorNumericalIdLess> LaneSet;
45 typedef std::map<const MSLane*, int, ComparatorNumericalIdLess> LaneVisitedMap;
46
47 struct VehicleEvent {
48 VehicleEvent(SUMOTime _time, bool _isEntry, const std::string& _id, Notification _reason):
49 time(_time), isEntry(_isEntry), id(_id), reason(_reason) {}
51 bool isEntry;
52 std::string id;
54 };
55
56 /* The driveways (Fahrstrassen) for each link index of MSRailSignal
57 * Each link index has at least one driveway
58 * A driveway describes one possible route that passes the signal up to
59 * the next secure point
60 * When a signal guards a switch (indirect guard) that signal stores two
61 * or more driveways
62 */
63 MSDriveWay(const MSLink* origin, const std::string& id, bool temporary = false);
64
66 virtual ~MSDriveWay();
67
68 static void cleanup();
69
70 static void clearState();
71
72 static bool haveDriveWays() {
73 return myGlobalDriveWayIndex > 0;
74 }
75
76 static const MSDriveWay* retrieveDepartDriveWay(const MSEdge* edge, const std::string& id);
77
78 bool notifyEnter(SUMOTrafficObject& veh, Notification reason, const MSLane* enteredLane);
79 bool notifyLeave(SUMOTrafficObject& veh, double lastPos, Notification reason, const MSLane* enteredLane = 0);
80 bool notifyLeaveBack(SUMOTrafficObject& veh, Notification reason, const MSLane* leftLane);
81
83 bool flankConflict(const MSDriveWay& other) const;
84
86 bool crossingConflict(const MSDriveWay& other) const;
87
89 bool bidiBlockedBy(const MSDriveWay& other) const;
90
92 bool bidiBlockedByEnd(const MSDriveWay& other) const;
93
95 bool forwardRouteConflict(std::set<const MSEdge*> forward, const MSDriveWay& other, bool secondCheck = false);
96
98 bool conflictLaneOccupied(bool store = true, const SUMOVehicle* ego = nullptr) const;
99
101 bool foeDriveWayOccupied(bool store, const SUMOVehicle* ego, MSEdgeVector& occupied) const;
102
104 bool foeDriveWayApproached() const;
105
107 bool reserve(const Approaching& closest, MSEdgeVector& occupied);
108
110 void writeBlocks(OutputDevice& od) const;
111 void writeBlockVehicles(OutputDevice& od) const;
112
113 const std::vector<const MSEdge*>& getRoute() const {
114 return myRoute;
115 }
116
117 const std::vector<const MSLane*>& getFlank() const {
118 return myFlank;
119 }
120
121 const std::vector<const MSLane*>& getBidi() const {
122 return myBidi;
123 }
124
125 const std::vector<MSLink*>& getConflictLinks() const {
126 return myConflictLinks;
127 }
128
129 int getNumericalID() const {
130 return myNumericalID;
131 }
132
133 const std::vector<VehicleEvent>& getEvents() const {
134 return myVehicleEvents;
135 }
136
137 void setEvents(const std::vector<VehicleEvent>& events) {
138 myVehicleEvents = events;
139 }
140
141 void setVehicle(const std::string& vehID) {
142 myFirstVehicle = vehID;
143 }
144
145 const std::vector<MSDriveWay*>& getFoes() const {
146 return myFoes;
147 }
148
149 const std::vector<const MSLane*>& getForward() const {
150 return myForward;
151 }
152
154 bool match(MSRouteIterator firstIt, MSRouteIterator endIt) const;
155
156 void addDWDeadlock(const std::vector<const MSDriveWay*>& deadlockFoes);
157
158 bool isDepartDriveway() const {
159 return myOrigin == nullptr;
160 };
161
162 const MSLink* getOrigin() const {
163 return myOrigin;
164 }
165
166 static void init();
167
168 static bool hasRS(const MSEdge* cur, const MSEdge* next);
169
171 static bool mustYield(const Approaching& veh, const Approaching& foe);
172
174 static MSDriveWay* buildDriveWay(const std::string& id, const MSLink* link, MSRouteIterator first, MSRouteIterator end);
175
177 static std::string getClickableTLLinkID(const MSLink* link);
178
179 static const MSDriveWay* getDepartureDriveway(const SUMOVehicle* veh);
180
181 static void writeDepatureBlocks(OutputDevice& od, bool writeVehicles);
182
184 static void saveState(OutputDevice& out);
185 static void loadState(const SUMOSAXAttributes& attrs, int tag);
186
187protected:
188
191
194
197
200
202 std::vector<const MSEdge*> myRoute;
203
206
216
217 /* @brief the actual driveway part up to the next railsignal (halting position)
218 * This must be free of other trains */
219 std::vector<const MSLane*> myForward;
220
221 /* @brief the list of bidirectional edges that can enter the forward
222 * section and which must also be free of traffic
223 * (up to the first element that could give protection) */
224 std::vector<const MSLane*> myBidi;
225
226 /* @brief the list of bidirectional edges that can enter the forward
227 * section and which might contain deadlock-relevant traffic */
228 std::vector<const MSLane*> myBidiExtended;
229
230 /* @brief the list of edges that merge with the forward section
231 * (found via backward search, up to the first element that could give protection) */
232 std::vector<const MSLane*> myFlank;
233
235 std::vector<const MSLane*> myConflictLanes;
236
237 /* The conflict links for this block
238 * Conflict resolution must be performed if vehicles are approaching the
239 * current link and any of the conflict links */
240 std::vector<MSLink*> myConflictLinks;
241
243 bool hasLinkConflict(const Approaching& closest, const MSLink* foeLink) const;
244
246 bool overlap(const MSDriveWay& other) const;
247
248 /* @brief determine route that identifies this driveway (a subset of the
249 * vehicle route)
250 * collects:
251 * myRoute
252 * myForward
253 * myBidi
254 * myProtectedBidi
255 *
256 * returns edge that is assumed to safe from oncoming-deadlock or nullptr
257 */
258 void buildRoute(const MSLink* origin, MSRouteIterator next, MSRouteIterator end, LaneVisitedMap& visited, std::set<MSLink*>&);
259
260 /* @brief find switches that threaten this driveway
261 * @param[out] flankSwitches collect the switches
262 */
263 void checkFlanks(const MSLink* originLink, const std::vector<const MSLane*>& lanes, const LaneVisitedMap& visited, bool allFoes, std::set<MSLink*>& flankSwitches) const;
264
265 /* @brief find links that cross the driveway without entering it
266 * @param[out] flankSwitches collect the switches
267 */
268 void checkCrossingFlanks(MSLink* dwLink, const LaneVisitedMap& visited, std::set<MSLink*>& flankSwitches) const;
269
270 /* @brief find upstream protection from the given link
271 * @param[out] flank: the stored flank lanes
272 */
273 void findFlankProtection(MSLink* link, MSLink* origLink, std::vector<const MSLane*>& flank);
274
276 void addFoes(const MSLink* link);
277
279 void addSidings(MSDriveWay* foe, bool addToFoe = false);
280
282 void addBidiFoes(const MSRailSignal* ownSignal, bool extended);
283
285 void addParallelFoes(const MSLink* link, const MSEdge* first);
286
288 void addReversalFoes();
289
290 /* @brief build shortened driveway that ends where the foe train leaves the conflict zone of this driveway
291 * @return whether the foe has received a new entry in myFoes
292 */
293 bool buildSubFoe(MSDriveWay* foe, bool movingBlock);
294
296 void addConflictLink(const MSLink* link);
297
299 std::pair<bool, const MSDriveWay*> canUseSiding(const SUMOVehicle* ego, const MSDriveWay* foe, bool recurse = true) const;
300
301 bool isFoeOrSubFoe(const MSDriveWay* foe) const;
302
303 bool forwardEndOnRoute(const MSDriveWay* foe) const;
304
305 void addSwitchFoes(MSLink* link);
306
307 bool haveSubTrains() const;
308
309 static bool hasJoin(const SUMOVehicle* ego, const SUMOVehicle* foe);
310
311 static bool isSwitch(const MSLink* link);
312
313 void _saveState(OutputDevice& out) const;
314
316 static std::string getTLLinkID(const MSLink* link);
317
319 static std::string getJunctionLinkID(const MSLink* link);
320
322 static std::string formatVisitedMap(const LaneVisitedMap& visited);
323
325 static void appendMapIndex(LaneVisitedMap& map, const MSLane* lane);
326
327private:
328
329 struct Siding {
330 Siding(int s, int e, double l) : start(s), end(e), length(l) {}
331 // indices along route
332 int start;
333 int end;
334 double length;
335 };
336
337 std::set<SUMOVehicle*> myTrains;
338
339 std::vector<VehicleEvent> myVehicleEvents;
340 std::vector<MSDriveWay*> myFoes;
341 std::map<const MSDriveWay*, std::vector<Siding>, ComparatorIdLess> mySidings;
342 std::vector<std::set <const MSDriveWay*> > myDeadlocks;
343
344 /* @brief shortened versions of this driveway to be used as foes instead of the long original
345 * (ends as soon as the train has left a particular conflict section)
346 * they are never attached to a LinkInfo and thus never the target of the match() function */
347 std::vector<MSDriveWay*> mySubDriveWays;
348
350 std::vector<const MSEdge*> myReversals;
351
353 std::string myFirstVehicle;
354
356 static bool myWriteVehicles;
357 static std::set<const MSEdge*> myBlockLengthWarnings;
358
360 static std::map<const MSLink*, std::vector<MSDriveWay*> > mySwitchDriveWays;
361
363 static std::map<const MSEdge*, std::vector<MSDriveWay*> > myReversalDriveWays;
364
366 static std::map<const MSEdge*, std::vector<MSDriveWay*>, ComparatorNumericalIdLess > myDepartureDriveways;
367 static std::map<const MSJunction*, int> myDepartDrivewayIndex;
369 static std::map<const MSEdge*, std::vector<MSDriveWay*> > myDepartureDrivewaysEnds;
370
372 static std::map<const MSEdge*, std::vector<MSDriveWay*>, ComparatorNumericalIdLess> myEndingDriveways;
373
375 static std::map<ConstMSEdgeVector, MSDriveWay*> myDriveWayRouteLookup;
376 static std::map<std::string, MSDriveWay*> myDriveWayLookup;
377
378};
long long int SUMOTime
Definition GUI.h:36
std::vector< MSEdge * > MSEdgeVector
Definition MSEdge.h:73
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition MSRoute.h:57
void addFoes(const MSLink *link)
add all driveWays that start at the given link as foes
std::vector< MSLink * > myConflictLinks
Definition MSDriveWay.h:240
const SUMOVehicle * myActive
whether the current signal is switched green for a train approaching this block
Definition MSDriveWay.h:199
bool crossingConflict(const MSDriveWay &other) const
Wether there is a crossing conflict with the given driveway.
static std::string getJunctionLinkID(const MSLink *link)
return junctionID_junctionLinkIndex
static void clearState()
bool haveSubTrains() const
bool myIsSubDriveway
Definition MSDriveWay.h:215
std::vector< MSDriveWay * > mySubDriveWays
Definition MSDriveWay.h:347
std::vector< std::set< const MSDriveWay * > > myDeadlocks
Definition MSDriveWay.h:342
void checkFlanks(const MSLink *originLink, const std::vector< const MSLane * > &lanes, const LaneVisitedMap &visited, bool allFoes, std::set< MSLink * > &flankSwitches) const
bool myAbortedBuild
whether driveway building was aborted due to MAX_BLOCK_LENGTH
Definition MSDriveWay.h:212
bool buildSubFoe(MSDriveWay *foe, bool movingBlock)
static std::map< const MSJunction *, int > myDepartDrivewayIndex
Definition MSDriveWay.h:367
static bool hasJoin(const SUMOVehicle *ego, const SUMOVehicle *foe)
bool isDepartDriveway() const
Definition MSDriveWay.h:158
static std::string getClickableTLLinkID(const MSLink *link)
return logicID_linkIndex in a way that allows clicking in sumo-gui
double myMaxFlankLength
the maximum flank length searched while building this driveway
Definition MSDriveWay.h:196
const MSLink * myOrigin
the link that enters this driveway or nullptr for a departure driveWay
Definition MSDriveWay.h:193
bool myTerminateRoute
Definition MSDriveWay.h:210
std::vector< const MSLane * > myBidi
Definition MSDriveWay.h:224
static bool myWriteVehicles
Definition MSDriveWay.h:356
void checkCrossingFlanks(MSLink *dwLink, const LaneVisitedMap &visited, std::set< MSLink * > &flankSwitches) const
bool hasLinkConflict(const Approaching &closest, const MSLink *foeLink) const
Whether the approaching vehicle is prevent from driving by another vehicle approaching the given link...
void findFlankProtection(MSLink *link, MSLink *origLink, std::vector< const MSLane * > &flank)
std::vector< const MSLane * > myBidiExtended
Definition MSDriveWay.h:228
void addReversalFoes()
derive foe driveways that enter the bidi section by reversing
static bool hasRS(const MSEdge *cur, const MSEdge *next)
void addBidiFoes(const MSRailSignal *ownSignal, bool extended)
derive foe driveways based on myBidi or myBidiExtended
static const MSDriveWay * retrieveDepartDriveWay(const MSEdge *edge, const std::string &id)
static bool haveDriveWays()
Definition MSDriveWay.h:72
void writeBlocks(OutputDevice &od) const
Write block items for this driveway.
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, Notification reason, const MSLane *enteredLane=0)
Called if the vehicle leaves the reminder's lane.
std::vector< const MSLane * > myForward
Definition MSDriveWay.h:219
const std::vector< const MSLane * > & getBidi() const
Definition MSDriveWay.h:121
std::vector< const MSEdge * > myReversals
track own occurences in myReversalDriveWays for cleanup in destructor
Definition MSDriveWay.h:350
std::map< const MSDriveWay *, std::vector< Siding >, ComparatorIdLess > mySidings
Definition MSDriveWay.h:341
void writeBlockVehicles(OutputDevice &od) const
virtual ~MSDriveWay()
Destructor.
bool match(MSRouteIterator firstIt, MSRouteIterator endIt) const
whether the give route matches this driveway
static void appendMapIndex(LaneVisitedMap &map, const MSLane *lane)
append to map by map index and avoid undefined behavior
bool overlap(const MSDriveWay &other) const
Wether this driveway (route) overlaps with the given one.
void setEvents(const std::vector< VehicleEvent > &events)
Definition MSDriveWay.h:137
void buildRoute(const MSLink *origin, MSRouteIterator next, MSRouteIterator end, LaneVisitedMap &visited, std::set< MSLink * > &)
std::vector< const MSLane * > myFlank
Definition MSDriveWay.h:232
static std::string getTLLinkID(const MSLink *link)
return logicID_linkIndex
const std::vector< const MSLane * > & getForward() const
Definition MSDriveWay.h:149
std::vector< const MSEdge * > myRoute
list of edges for matching against train routes
Definition MSDriveWay.h:202
std::map< const MSLane *, int, ComparatorNumericalIdLess > LaneVisitedMap
Definition MSDriveWay.h:45
static void writeDepatureBlocks(OutputDevice &od, bool writeVehicles)
static std::map< ConstMSEdgeVector, MSDriveWay * > myDriveWayRouteLookup
lookup table for state loading
Definition MSDriveWay.h:375
int getNumericalID() const
Definition MSDriveWay.h:129
static std::set< const MSEdge * > myBlockLengthWarnings
Definition MSDriveWay.h:357
static std::map< const MSEdge *, std::vector< MSDriveWay * > > myReversalDriveWays
all driveways reversing on the given switch (used to look up flank foes)
Definition MSDriveWay.h:363
static void init()
void _saveState(OutputDevice &out) const
static std::string formatVisitedMap(const LaneVisitedMap &visited)
print link descriptions
static std::map< std::string, MSDriveWay * > myDriveWayLookup
Definition MSDriveWay.h:376
const std::vector< MSLink * > & getConflictLinks() const
Definition MSDriveWay.h:125
const std::vector< MSDriveWay * > & getFoes() const
Definition MSDriveWay.h:145
const MSLink * getOrigin() const
Definition MSDriveWay.h:162
bool flankConflict(const MSDriveWay &other) const
Wether there is a flank conflict with the given driveway.
bool conflictLaneOccupied(bool store=true, const SUMOVehicle *ego=nullptr) const
whether any of myConflictLanes is occupied (vehicles that are the target of a join must be ignored)
void addSwitchFoes(MSLink *link)
static std::map< const MSEdge *, std::vector< MSDriveWay * > > myDepartureDrivewaysEnds
all driveways that do not start at a rail signal (and are only used at departure) by end edge
Definition MSDriveWay.h:369
int myCoreSize
number of edges in myRoute where overlap with other driveways is forbidden
Definition MSDriveWay.h:205
std::pair< const SUMOVehicle *const, const MSLink::ApproachingVehicleInformation > Approaching
Definition MSDriveWay.h:43
void addConflictLink(const MSLink *link)
add symmetical conflict link for foes when building a new driveway
static void cleanup()
bool notifyLeaveBack(SUMOTrafficObject &veh, Notification reason, const MSLane *leftLane)
Called if the vehicle's back leaves the reminder's lane.
std::string myFirstVehicle
the first vehicle using this driveway
Definition MSDriveWay.h:353
int myNumericalID
global driveway index
Definition MSDriveWay.h:190
bool forwardEndOnRoute(const MSDriveWay *foe) const
bool myFoundJump
Definition MSDriveWay.h:209
static void saveState(OutputDevice &out)
Save driveway occupancy into the given stream.
static std::map< const MSEdge *, std::vector< MSDriveWay * >, ComparatorNumericalIdLess > myDepartureDriveways
all driveways that do not start at a rail signal (and are only used at departure)
Definition MSDriveWay.h:366
void setVehicle(const std::string &vehID)
Definition MSDriveWay.h:141
bool myBidiEnded
whether driveway building was aborted when no further bidi edge was found
Definition MSDriveWay.h:214
static bool mustYield(const Approaching &veh, const Approaching &foe)
Whether veh must yield to the foe train.
static const MSDriveWay * getDepartureDriveway(const SUMOVehicle *veh)
const std::vector< const MSEdge * > & getRoute() const
Definition MSDriveWay.h:113
void addSidings(MSDriveWay *foe, bool addToFoe=false)
add sidings for the given foe
bool bidiBlockedByEnd(const MSDriveWay &other) const
Wether there is a bidi conflict with the end of the given driveway.
static int myGlobalDriveWayIndex
Definition MSDriveWay.h:355
static MSDriveWay * buildDriveWay(const std::string &id, const MSLink *link, MSRouteIterator first, MSRouteIterator end)
construct a new driveway by searching along the given route until all block structures are found
bool myFoundSignal
whether this driveway ends its forward section with a rail signal (and thus comprises a full block)
Definition MSDriveWay.h:208
static std::map< const MSLink *, std::vector< MSDriveWay * > > mySwitchDriveWays
all driveways passing the given switch (used to look up flank foes)
Definition MSDriveWay.h:360
bool isFoeOrSubFoe(const MSDriveWay *foe) const
const std::vector< const MSLane * > & getFlank() const
Definition MSDriveWay.h:117
const std::vector< VehicleEvent > & getEvents() const
Definition MSDriveWay.h:133
void addDWDeadlock(const std::vector< const MSDriveWay * > &deadlockFoes)
static std::map< const MSEdge *, std::vector< MSDriveWay * >, ComparatorNumericalIdLess > myEndingDriveways
all driveways that end on the given edge
Definition MSDriveWay.h:372
bool foeDriveWayApproached() const
whether any of my Foes is being approached
static void loadState(const SUMOSAXAttributes &attrs, int tag)
bool forwardRouteConflict(std::set< const MSEdge * > forward, const MSDriveWay &other, bool secondCheck=false)
Wether the route of other passes into the forward section of this driveway.
std::pair< bool, const MSDriveWay * > canUseSiding(const SUMOVehicle *ego, const MSDriveWay *foe, bool recurse=true) const
return whether a siding can be used. If a siding exist but is occupied, also return the occupied driv...
std::vector< const MSLane * > myConflictLanes
the lanes that must be clear of trains before this signal can switch to green
Definition MSDriveWay.h:235
std::vector< MSDriveWay * > myFoes
Definition MSDriveWay.h:340
std::vector< VehicleEvent > myVehicleEvents
Definition MSDriveWay.h:339
std::set< const MSLane *, ComparatorNumericalIdLess > LaneSet
Definition MSDriveWay.h:44
static bool isSwitch(const MSLink *link)
bool notifyEnter(SUMOTrafficObject &veh, Notification reason, const MSLane *enteredLane)
Checks whether the reminder is activated by a vehicle entering the lane.
bool bidiBlockedBy(const MSDriveWay &other) const
Wether there is a bidi conflict with the given driveway.
bool reserve(const Approaching &closest, MSEdgeVector &occupied)
attempt reserve this driveway for the given vehicle
std::set< SUMOVehicle * > myTrains
Definition MSDriveWay.h:337
void addParallelFoes(const MSLink *link, const MSEdge *first)
derive foe driveways that start at the same signal
bool foeDriveWayOccupied(bool store, const SUMOVehicle *ego, MSEdgeVector &occupied) const
whether any of myFoes is occupied (vehicles that are the target of a join must be ignored)
A road/street connecting two junctions.
Definition MSEdge.h:77
Representation of a lane in the micro simulation.
Definition MSLane.h:84
Something on a lane to be noticed about vehicle movement.
Notification
Definition of a vehicle state.
A signal for rails.
Base class for objects which have an id.
Definition Named.h:54
Static storage of an output device and its base (abstract) implementation.
Encapsulated SAX-Attributes.
Representation of a vehicle, person, or container.
Representation of a vehicle.
Definition SUMOVehicle.h:62
Function-object for stable sorting of objects acting like Named without being derived (SUMOVehicle)
Definition Named.h:30
Function-object for stable sorting of objects with numerical ids.
Definition Named.h:39
Siding(int s, int e, double l)
Definition MSDriveWay.h:330
VehicleEvent(SUMOTime _time, bool _isEntry, const std::string &_id, Notification _reason)
Definition MSDriveWay.h:48