Eclipse SUMO - Simulation of Urban MObility
MSRailSignalConstraint.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2002-2022 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 
24 
25 // ===========================================================================
26 // class declarations
27 // ===========================================================================
28 class MSRailSignal;
29 class SUMOSAXAttributes;
30 
31 
32 // ===========================================================================
33 // class definitions
34 // ===========================================================================
40 public:
44 
47 
49  virtual bool cleared() const = 0;
50 
51  virtual std::string getDescription() const {
52  return "RailSignalConstraint";
53  }
54 
55  virtual void write(OutputDevice& out, SumoXMLTag tag, const std::string& tripId) const = 0;
56 
58  static void cleanup();
59 
61  static void saveState(OutputDevice& out);
62 
64  static void clearState();
65 
67  static void clearAll();
68 
69 protected:
70  static std::string getVehID(const std::string& tripID);
71 };
72 
73 
75 public:
78  MSRailSignalConstraint_Predecessor(const MSRailSignal* signal, const std::string& tripId, int limit);
79 
82 
83  void write(OutputDevice& out, SumoXMLTag tag, const std::string& tripId) const;
84 
86  static void cleanup();
87 
89  static void saveState(OutputDevice& out);
90 
92  static void loadState(const SUMOSAXAttributes& attrs);
93 
95  static void clearState();
96 
97  bool cleared() const;
98 
99  std::string getDescription() const;
100 
101  class PassedTracker : public MSMoveReminder {
102  public:
103  PassedTracker(MSLane* lane);
104 
106 
107  bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
110 
111  void raiseLimit(int limit);
112 
113  bool hasPassed(const std::string& tripId, int limit) const;
114 
116  void clearState();
117 
119  void saveState(OutputDevice& out);
120 
122  void loadState(int index, const std::vector<std::string>& tripIDs);
123 
125  std::vector<std::string> myPassed;
126 
129  };
130 
132  std::vector<PassedTracker*> myTrackers;
133 
135  const std::string myTripId;
136 
138  const int myLimit;
139 
142 
143 
144  static std::map<const MSLane*, PassedTracker*> myTrackerLookup;
145 
146 private:
149 };
150 
151 
SumoXMLTag
Numbers representing SUMO-XML - element names.
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
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.
MSRailSignalConstraint_Predecessor & operator=(const MSRailSignalConstraint_Predecessor &s)=delete
invalidated assignment operator
const MSRailSignal * myFoeSignal
store the foe signal (for TraCI access)
void write(OutputDevice &out, SumoXMLTag tag, const std::string &tripId) const
bool cleared() const
whether the constraint has been met
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
const int myLimit
the number of passed vehicles within which tripId must have occured
MSRailSignalConstraint_Predecessor(const MSRailSignal *signal, const std::string &tripId, int limit)
Constructor.
A base class for constraints.
virtual std::string getDescription() const
static void saveState(OutputDevice &out)
Saves the current constraint states into the given stream.
static std::string getVehID(const std::string &tripID)
static void clearState()
Clear all constraint states before quick-loading state.
virtual void write(OutputDevice &out, SumoXMLTag tag, const std::string &tripId) const =0
static void clearAll()
Remove all constraints before quick-loading state.
virtual bool cleared() const =0
whether the constraint has been met
static void cleanup()
clean up state
virtual ~MSRailSignalConstraint()
Destructor.
A signal for rails.
Definition: MSRailSignal.h:46
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
Encapsulated SAX-Attributes.
Representation of a vehicle, person, or container.