Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
TrafficLight.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2012-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/****************************************************************************/
20// C++ TraCI client API implementation
21/****************************************************************************/
22#pragma once
23#include <vector>
24#include <libsumo/TraCIDefs.h>
26
27// ===========================================================================
28// class declarations
29// ===========================================================================
30#ifndef LIBTRACI
32class SUMOVehicle;
33#endif
34
35// ===========================================================================
36// class definitions
37// ===========================================================================
42namespace LIBSUMO_NAMESPACE {
44public:
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 double getSpentDuration(const std::string& tlsID);
57 static int getServedPersonCount(const std::string& tlsID, int index);
58 static std::vector<std::string> getBlockingVehicles(const std::string& tlsID, int linkIndex);
59 static std::vector<std::string> getRivalVehicles(const std::string& tlsID, int linkIndex);
60 static std::vector<std::string> getPriorityVehicles(const std::string& tlsID, int linkIndex);
61 static std::vector<libsumo::TraCISignalConstraint> getConstraints(const std::string& tlsID, const std::string& tripId = "");
62 static std::vector<libsumo::TraCISignalConstraint> getConstraintsByFoe(const std::string& foeSignal, const std::string& foeId = "");
63
66
67
68 static void setRedYellowGreenState(const std::string& tlsID, const std::string& state);
69 static void setPhase(const std::string& tlsID, const int index);
70 static void setPhaseName(const std::string& tlsID, const std::string& name);
71 static void setProgram(const std::string& tlsID, const std::string& programID);
72 static void setPhaseDuration(const std::string& tlsID, const double phaseDuration);
73 static void setProgramLogic(const std::string& tlsID, const libsumo::TraCILogic& logic);
74
75 static void addConstraint(const std::string& tlsID, const std::string& tripId, const std::string& foeSignal, const std::string& foeId, const int type = 0, const int limit = 0);
76 static std::vector<libsumo::TraCISignalConstraint> swapConstraints(const std::string& tlsID, const std::string& tripId, const std::string& foeSignal, const std::string& foeId);
77 static void removeConstraints(const std::string& tlsID, const std::string& tripId, const std::string& foeSignal, const std::string& foeId);
78 static void updateConstraints(const std::string& vehID, std::string tripId = "");
79
80 // aliases for backward compatibility
81 inline static std::vector<libsumo::TraCILogic> getCompleteRedYellowGreenDefinition(const std::string& tlsID) {
82 return getAllProgramLogics(tlsID);
83 }
84 inline static void setCompleteRedYellowGreenDefinition(const std::string& tlsID, const libsumo::TraCILogic& logic) {
85 setProgramLogic(tlsID, logic);
86 }
87
88 static void setNemaSplits(const std::string& tlsID, const std::vector<double>& splits);
89 static void setNemaMaxGreens(const std::string& tlsID, const std::vector<double>& maxGreens);
90 static void setNemaCycleLength(const std::string& tlsID, double cycleLength);
91 static void setNemaOffset(const std::string& tlsID, double offset);
92
93#ifndef LIBTRACI
94#ifndef SWIG
95 static std::shared_ptr<VariableWrapper> makeWrapper();
96
97 static bool handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData);
98
99private:
100 static libsumo::TraCISignalConstraint buildConstraint(const std::string& tlsID, const std::string& tripId, MSRailSignalConstraint* constraint);
102 static std::vector<libsumo::TraCISignalConstraint> findConstraintsDeadLocks(const std::string& foeId, const std::string& tripId, const std::string& foeSignal, const std::string& tlsID);
103 static SUMOVehicle* getVehicleByTripId(const std::string tripOrVehID);
104 static std::vector<std::string> getFutureTripIds(const std::string vehID);
105 static void swapParameters(MSRailSignalConstraint* c);
106 static void swapParameters(MSRailSignalConstraint* c, const std::string& key1, const std::string& key2);
107 static void swapParameters(TraCISignalConstraint& c);
108 static void swapParameters(TraCISignalConstraint& c, const std::string& key1, const std::string& key2);
109 static std::vector<std::pair<std::string, std::string> > getSwapParams(int constraintType);
110
111private:
112 static SubscriptionResults mySubscriptionResults;
113 static ContextSubscriptionResults myContextSubscriptionResults;
114#endif
115#endif
117 TrafficLight() = delete;
118};
119
120
121}
#define LIBSUMO_ID_PARAMETER_API
Definition TraCIDefs.h:116
#define LIBSUMO_SUBSCRIPTION_API
Definition TraCIDefs.h:62
static double getSpentDuration(const std::string &tlsID)
static std::string getProgram(const std::string &tlsID)
static std::vector< std::string > getRivalVehicles(const std::string &tlsID, int linkIndex)
static void setProgramLogic(const std::string &tlsID, const libsumo::TraCILogic &logic)
static ContextSubscriptionResults myContextSubscriptionResults
static void setProgram(const std::string &tlsID, const std::string &programID)
static void setCompleteRedYellowGreenDefinition(const std::string &tlsID, const libsumo::TraCILogic &logic)
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 std::vector< libsumo::TraCILogic > getCompleteRedYellowGreenDefinition(const std::string &tlsID)
static void addConstraint(const std::string &tlsID, const std::string &tripId, const std::string &foeSignal, const std::string &foeId, const int type=0, const int limit=0)
static int getServedPersonCount(const std::string &tlsID, int index)
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
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 void setPhaseDuration(const std::string &tlsID, const double phaseDuration)
static std::vector< libsumo::TraCILogic > getAllProgramLogics(const std::string &tlsID)
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 void updateConstraints(const std::string &vehID, std::string tripId="")
static double getNextSwitch(const std::string &tlsID)
A base class for constraints.
Representation of a vehicle.
Definition SUMOVehicle.h:62