Eclipse SUMO - Simulation of Urban MObility
TrafficLight.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2012-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 /****************************************************************************/
20 // C++ TraCI client API implementation
21 /****************************************************************************/
22 #pragma once
23 #include <vector>
24 #include <libsumo/TraCIDefs.h>
25 #include <libsumo/TraCIConstants.h>
26 
27 // ===========================================================================
28 // class declarations
29 // ===========================================================================
30 #ifndef LIBTRACI
32 class SUMOVehicle;
33 #endif
34 
35 // ===========================================================================
36 // class definitions
37 // ===========================================================================
42 namespace LIBSUMO_NAMESPACE {
43 class TrafficLight {
44 public:
45 
46  static std::string getRedYellowGreenState(const std::string& tlsID);
47  static std::vector<libsumo::TraCILogic> getAllProgramLogics(const std::string& tlsID);
48  static std::vector<std::string> getControlledJunctions(const std::string& tlsID);
49  static std::vector<std::string> getControlledLanes(const std::string& tlsID);
50  static std::vector<std::vector<libsumo::TraCILink> > getControlledLinks(const std::string& tlsID);
51  static std::string getProgram(const std::string& tlsID);
52  static int getPhase(const std::string& tlsID);
53  static std::string getPhaseName(const std::string& tlsID);
54  static double getPhaseDuration(const std::string& tlsID);
55  static double getNextSwitch(const std::string& tlsID);
56  static int getServedPersonCount(const std::string& tlsID, int index);
57  static std::vector<std::string> getBlockingVehicles(const std::string& tlsID, int linkIndex);
58  static std::vector<std::string> getRivalVehicles(const std::string& tlsID, int linkIndex);
59  static std::vector<std::string> getPriorityVehicles(const std::string& tlsID, int linkIndex);
60  static std::vector<libsumo::TraCISignalConstraint> getConstraints(const std::string& tlsID, const std::string& tripId = "");
61  static std::vector<libsumo::TraCISignalConstraint> getConstraintsByFoe(const std::string& foeSignal, const std::string& foeId = "");
62 
65 
66 
67  static void setRedYellowGreenState(const std::string& tlsID, const std::string& state);
68  static void setPhase(const std::string& tlsID, const int index);
69  static void setPhaseName(const std::string& tlsID, const std::string& name);
70  static void setProgram(const std::string& tlsID, const std::string& programID);
71  static void setPhaseDuration(const std::string& tlsID, const double phaseDuration);
72  static void setProgramLogic(const std::string& tlsID, const libsumo::TraCILogic& logic);
73 
74  static std::vector<libsumo::TraCISignalConstraint> swapConstraints(const std::string& tlsID, const std::string& tripId, const std::string& foeSignal, const std::string& foeId);
75  static void removeConstraints(const std::string& tlsID, const std::string& tripId, const std::string& foeSignal, const std::string& foeId);
76 
77  // aliases for backward compatibility
78  inline static std::vector<libsumo::TraCILogic> getCompleteRedYellowGreenDefinition(const std::string& tlsID) {
79  return getAllProgramLogics(tlsID);
80  }
81  inline static void setCompleteRedYellowGreenDefinition(const std::string& tlsID, const libsumo::TraCILogic& logic) {
82  setProgramLogic(tlsID, logic);
83  }
84 
85  static void setNemaSplits(const std::string& tlsID, const std::vector<double>& splits);
86  static void setNemaMaxGreens(const std::string& tlsID, const std::vector<double>& maxGreens);
87  static void setNemaCycleLength(const std::string& tlsID, double cycleLength);
88  static void setNemaOffset(const std::string& tlsID, double offset);
89 
90 #ifndef LIBTRACI
91 #ifndef SWIG
92  static std::shared_ptr<VariableWrapper> makeWrapper();
93 
94  static bool handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData);
95 
96 private:
97  static libsumo::TraCISignalConstraint buildConstraint(const std::string& tlsID, const std::string& tripId, MSRailSignalConstraint* constraint, bool insertionConstraint);
99  static std::vector<libsumo::TraCISignalConstraint> findConstraintsDeadLocks(const std::string& foeId, const std::string& tripId, const std::string& foeSignal, const std::string& tlsID);
100  static SUMOVehicle* getVehicleByTripId(const std::string tripOrVehID);
101 
102 private:
105 #endif
106 #endif
108  TrafficLight() = delete;
109 };
110 
111 
112 }
#define LIBSUMO_ID_PARAMETER_API
Definition: TraCIDefs.h:108
#define LIBSUMO_SUBSCRIPTION_API
Definition: TraCIDefs.h:56
static std::string getProgram(const std::string &tlsID)
static std::vector< std::string > getRivalVehicles(const std::string &tlsID, int linkIndex)
static std::vector< libsumo::TraCILogic > getCompleteRedYellowGreenDefinition(const std::string &tlsID)
Definition: TrafficLight.h:78
static void setProgramLogic(const std::string &tlsID, const libsumo::TraCILogic &logic)
static ContextSubscriptionResults myContextSubscriptionResults
Definition: TrafficLight.h:104
static void setProgram(const std::string &tlsID, const std::string &programID)
static bool handleVariable(const std::string &objID, const int variable, VariableWrapper *wrapper, tcpip::Storage *paramData)
static void setCompleteRedYellowGreenDefinition(const std::string &tlsID, const libsumo::TraCILogic &logic)
Definition: TrafficLight.h:81
static int getPhase(const std::string &tlsID)
static double getPhaseDuration(const std::string &tlsID)
static void setPhaseName(const std::string &tlsID, const std::string &name)
static SUMOVehicle * getVehicleByTripId(const std::string tripOrVehID)
static int getServedPersonCount(const std::string &tlsID, int index)
static std::shared_ptr< VariableWrapper > makeWrapper()
static std::vector< std::string > getControlledJunctions(const std::string &tlsID)
static std::vector< std::vector< libsumo::TraCILink > > getControlledLinks(const std::string &tlsID)
static std::vector< libsumo::TraCISignalConstraint > getConstraintsByFoe(const std::string &foeSignal, const std::string &foeId="")
static std::vector< std::string > getControlledLanes(const std::string &tlsID)
static std::string getPhaseName(const std::string &tlsID)
static SubscriptionResults mySubscriptionResults
Definition: TrafficLight.h:103
static void setNemaMaxGreens(const std::string &tlsID, const std::vector< double > &maxGreens)
static void setPhase(const std::string &tlsID, const int index)
static std::vector< std::string > getBlockingVehicles(const std::string &tlsID, int linkIndex)
TrafficLight()=delete
invalidated standard constructor
static void removeConstraints(const std::string &tlsID, const std::string &tripId, const std::string &foeSignal, const std::string &foeId)
static std::vector< libsumo::TraCISignalConstraint > getConstraints(const std::string &tlsID, const std::string &tripId="")
static std::vector< libsumo::TraCISignalConstraint > swapConstraints(const std::string &tlsID, const std::string &tripId, const std::string &foeSignal, const std::string &foeId)
static std::string getRedYellowGreenState(const std::string &tlsID)
static libsumo::TraCISignalConstraint buildConstraint(const std::string &tlsID, const std::string &tripId, MSRailSignalConstraint *constraint, bool insertionConstraint)
static void setPhaseDuration(const std::string &tlsID, const double phaseDuration)
static void setNemaCycleLength(const std::string &tlsID, double cycleLength)
static void setNemaOffset(const std::string &tlsID, double offset)
static std::vector< libsumo::TraCILogic > getAllProgramLogics(const std::string &tlsID)
static void setNemaSplits(const std::string &tlsID, const std::vector< double > &splits)
LIBSUMO_ID_PARAMETER_API static LIBSUMO_SUBSCRIPTION_API void setRedYellowGreenState(const std::string &tlsID, const std::string &state)
static std::vector< std::string > getPriorityVehicles(const std::string &tlsID, int linkIndex)
static double getNextSwitch(const std::string &tlsID)
static std::vector< libsumo::TraCISignalConstraint > findConstraintsDeadLocks(const std::string &foeId, const std::string &tripId, const std::string &foeSignal, const std::string &tlsID)
perform swapConstraints to resolve deadlocks and return the new constraints
A base class for constraints.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
std::map< std::string, libsumo::SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:279
std::map< std::string, libsumo::TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:278