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-2023 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;
31
32
33// ===========================================================================
34// class definitions
35// ===========================================================================
41public:
42
44 PREDECESSOR = 0, // swaps to PREDECESSOR
45 INSERTION_PREDECESSOR = 1, // swaps to FOE_INSERTION
46 FOE_INSERTION = 2, // swaps to INSERTION_PREDECESSOR
47 INSERTION_ORDER = 3, // swaps to INSERTION_ORDER
48 BIDI_PREDECESSOR = 4 // swaps to BIDI_PREDECESSOR
49 };
50
54
57
59 virtual bool cleared() const = 0;
60
61 virtual void setActive(bool active) = 0;
62
63 virtual bool isActive() const = 0;
64
65 virtual std::string getDescription() const {
66 return "RailSignalConstraint";
67 }
68
69 virtual void write(OutputDevice& out, const std::string& tripId) const = 0;
70
72 return myType;
73 }
74
76 switch (myType) {
79 case FOE_INSERTION:
81 case INSERTION_ORDER:
85 default:
87 }
88 }
89
91 switch (myType) {
93 return FOE_INSERTION;
94 case FOE_INSERTION:
96 default:
97 return myType;
98 }
99 }
100
104
106 static void cleanup();
107
109 static void saveState(OutputDevice& out);
110
112 static void clearState();
113
115 static void clearAll();
116
117protected:
118 static std::string getVehID(const std::string& tripID);
119
121};
122
123
125public:
128 MSRailSignalConstraint_Predecessor(ConstraintType type, const MSRailSignal* signal, const std::string& tripId, int limit, bool active);
129
132
133 void write(OutputDevice& out, const std::string& tripId) const;
134
136 static void cleanup();
137
139 static void saveState(OutputDevice& out);
140
142 static void loadState(const SUMOSAXAttributes& attrs);
143
145 static void clearState();
146
147 bool cleared() const;
148
149 void setActive(bool active) {
150 myAmActive = active;
151 }
152
153 bool isActive() const {
154 return myAmActive;
155 }
156
157 std::string getDescription() const;
158
160 public:
161 PassedTracker(MSLane* lane);
162
164
165
166 bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
168
169 void raiseLimit(int limit);
170
171 bool hasPassed(const std::string& tripId, int limit) const;
172
174 void clearState();
175
177 void saveState(OutputDevice& out);
178
180 void loadState(int index, const std::vector<std::string>& tripIDs);
181
183 std::vector<std::string> myPassed;
184
187 };
188
190 std::vector<PassedTracker*> myTrackers;
191
193 const std::string myTripId;
194
196 const int myLimit;
197
200
203
204
205 static std::map<const MSLane*, PassedTracker*> myTrackerLookup;
206
207private:
210};
211
212
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.
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.
static std::map< const MSLane *, PassedTracker * > myTrackerLookup
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 void saveState(OutputDevice &out)
Saves the current constraint states into the given stream.
ConstraintType getType() const
static std::string getVehID(const std::string &tripID)
static void clearState()
Clear all constraint states before quick-loading state.
virtual bool isActive() const =0
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
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.