Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSRailSignalConstraint.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 constraint on rail signal switching
19/****************************************************************************/
20#pragma once
21#include <config.h>
22
25
26// ===========================================================================
27// class declarations
28// ===========================================================================
29class MSRailSignal;
30class SUMOVehicle;
32
33
34// ===========================================================================
35// class definitions
36// ===========================================================================
42public:
43
45 PREDECESSOR = 0, // swaps to PREDECESSOR
46 INSERTION_PREDECESSOR = 1, // swaps to FOE_INSERTION
47 FOE_INSERTION = 2, // swaps to INSERTION_PREDECESSOR
48 INSERTION_ORDER = 3, // swaps to INSERTION_ORDER
49 BIDI_PREDECESSOR = 4 // swaps to BIDI_PREDECESSOR
50 };
51
55
58
60 virtual bool cleared() const = 0;
61
62 virtual void setActive(bool active) = 0;
63
64 virtual bool isActive() const = 0;
65
66 virtual std::string getDescription() const {
67 return "RailSignalConstraint";
68 }
69
70 virtual const SUMOVehicle* getFoe() const {
71 return nullptr;
72 }
73
74 virtual void write(OutputDevice& out, const std::string& tripId) const = 0;
75
77 return myType;
78 }
79
81 switch (myType) {
84 case FOE_INSERTION:
86 case INSERTION_ORDER:
90 default:
92 }
93 }
94
96 switch (myType) {
98 return FOE_INSERTION;
99 case FOE_INSERTION:
101 default:
102 return myType;
103 }
104 }
105
109
110 static void storeTripId(const std::string& tripId, const std::string& vehID);
111
112 static const std::string& lookupVehId(const std::string& tripId);
113
115 static void cleanup();
116
118 static void saveState(OutputDevice& out);
119
121 static void clearState();
122
124 static void clearAll();
125
126protected:
127 static const SUMOVehicle* getVeh(const std::string& tripID, bool checkID = false);
128
130
131 static std::map<std::string, std::string> myTripIdLookup;
132};
133
134
136public:
139 MSRailSignalConstraint_Predecessor(ConstraintType type, const MSRailSignal* signal, const std::string& tripId, int limit, bool active);
140
143
144 void write(OutputDevice& out, const std::string& tripId) const;
145
147 static void cleanup();
148
150 static void saveState(OutputDevice& out);
151
153 static void loadState(const SUMOSAXAttributes& attrs);
154
156 static void clearState();
157
158 bool cleared() const;
159
160 void setActive(bool active) {
161 myAmActive = active;
162 }
163
164 bool isActive() const {
165 return myAmActive;
166 }
167
168 std::string getDescription() const;
169
170 const SUMOVehicle* getFoe() const;
171
173 public:
174 PassedTracker(MSLane* lane);
175
177
178
179 bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
181
182 void raiseLimit(int limit);
183
184 bool hasPassed(const std::string& tripId, int limit) const;
185
187 void clearState();
188
190 void saveState(OutputDevice& out);
191
193 void loadState(int index, const std::vector<std::string>& tripIDs);
194
196 std::vector<std::string> myPassed;
197
200 };
201
203 std::vector<PassedTracker*> myTrackers;
204
206 const std::string myTripId;
207
209 const int myLimit;
210
213
216
217
218 static std::map<const MSLane*, PassedTracker*, ComparatorNumericalIdLess> myTrackerLookup;
219
220private:
223};
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_BIDI_PREDECESSOR
Predecessor constraint for rail signal before bidirectional section.
@ SUMO_TAG_INSERTION_PREDECESSOR
Predecessor constraint on insertion before rail signal.
@ SUMO_TAG_FOE_INSERTION
Predecessor constraint on switching a rail signal.
@ SUMO_TAG_INSERTION_ORDER
Predecessor constraint on insertion before rail signal.
@ SUMO_TAG_PREDECESSOR
Predecessor constraint on switching a rail signal.
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.
bool hasPassed(const std::string &tripId, int limit) const
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
tracks vehicles that passed this link (entered the next lane)
void loadState(int index, const std::vector< std::string > &tripIDs)
loads the current passed states into the given stream
void clearState()
Clear all passed states before quick-loading state.
std::vector< std::string > myPassed
passed tripIds
void saveState(OutputDevice &out)
Saves the current passed states into the given stream.
static std::map< const MSLane *, PassedTracker *, ComparatorNumericalIdLess > myTrackerLookup
const MSRailSignal * myFoeSignal
store the foe signal (for TraCI access)
bool cleared() const
whether the constraint has been met
bool myAmActive
Whether this constraint is currently active.
MSRailSignalConstraint_Predecessor & operator=(const MSRailSignalConstraint_Predecessor &s)=delete
invalidated assignment operator
static void loadState(const SUMOSAXAttributes &attrs)
loads the constraint state from the given attrs
static void saveState(OutputDevice &out)
Saves the current constraint states into the given stream.
const std::string myTripId
id of the predecessor that must already have passed
static void clearState()
Clear all constraint states before quick-loading state.
std::vector< PassedTracker * > myTrackers
the tracker object for this constraint
void write(OutputDevice &out, const std::string &tripId) const
const int myLimit
the number of passed vehicles within which tripId must have occured
A base class for constraints.
MSRailSignalConstraint(ConstraintType type)
Constructor.
virtual std::string getDescription() const
virtual void setActive(bool active)=0
static const SUMOVehicle * getVeh(const std::string &tripID, bool checkID=false)
static void saveState(OutputDevice &out)
Saves the current constraint states into the given stream.
static std::map< std::string, std::string > myTripIdLookup
ConstraintType getType() const
static void clearState()
Clear all constraint states before quick-loading state.
virtual bool isActive() const =0
virtual const SUMOVehicle * getFoe() const
static void clearAll()
Remove all constraints before quick-loading state.
virtual bool cleared() const =0
whether the constraint has been met
ConstraintType getSwappedType() const
static void cleanup()
clean up state
static void storeTripId(const std::string &tripId, const std::string &vehID)
static const std::string & lookupVehId(const std::string &tripId)
virtual void write(OutputDevice &out, const std::string &tripId) const =0
virtual ~MSRailSignalConstraint()
Destructor.
A signal for rails.
Static storage of an output device and its base (abstract) implementation.
An upper class for objects with additional parameters.
Encapsulated SAX-Attributes.
Representation of a vehicle, person, or container.
Representation of a vehicle.
Definition SUMOVehicle.h:62