50 std::vector<std::string>
51 TrafficLight::getIDList() {
57 TrafficLight::getIDCount() {
58 return (
int)getIDList().size();
63 TrafficLight::getRedYellowGreenState(
const std::string& tlsID) {
64 return getTLS(tlsID).getActive()->getCurrentPhaseDef().getState();
68 std::vector<TraCILogic>
69 TrafficLight::getAllProgramLogics(
const std::string& tlsID) {
70 std::vector<TraCILogic> result;
71 const std::vector<MSTrafficLightLogic*> logics = getTLS(tlsID).getAllLogics();
73 TraCILogic l(logic->getProgramID(), (
int)logic->getLogicType(), logic->getCurrentPhaseIndex());
74 l.subParameter = logic->getParametersMap();
76 l.phases.emplace_back(
new TraCIPhase(
STEPS2TIME(phase->duration), phase->getState(),
78 phase->getNextPhases(), phase->getName()));
80 result.emplace_back(l);
86 std::vector<std::string>
87 TrafficLight::getControlledJunctions(
const std::string& tlsID) {
88 std::set<std::string> junctionIDs;
91 for (
const MSLink* l : llinks) {
92 junctionIDs.insert(l->getJunction()->getID());
95 return std::vector<std::string>(junctionIDs.begin(), junctionIDs.end());
99 std::vector<std::string>
100 TrafficLight::getControlledLanes(
const std::string& tlsID) {
101 std::vector<std::string> laneIDs;
104 for (
const MSLane* l : llanes) {
105 laneIDs.push_back(l->getID());
112 std::vector<std::vector<TraCILink> >
113 TrafficLight::getControlledLinks(
const std::string& tlsID) {
114 std::vector<std::vector<TraCILink> > result;
117 for (
int i = 0; i < (int)lanes.size(); ++i) {
118 std::vector<TraCILink> subList;
122 for (
int j = 0; j < (int)llanes.size(); ++j) {
128 subList.emplace_back(TraCILink(llanes[j]->getID(), via, to));
130 result.emplace_back(subList);
137 TrafficLight::getProgram(
const std::string& tlsID) {
138 return getTLS(tlsID).getActive()->getProgramID();
143 TrafficLight::getPhase(
const std::string& tlsID) {
144 return getTLS(tlsID).getActive()->getCurrentPhaseIndex();
149 TrafficLight::getPhaseName(
const std::string& tlsID) {
150 return getTLS(tlsID).getActive()->getCurrentPhaseDef().getName();
155 TrafficLight::getPhaseDuration(
const std::string& tlsID) {
156 return STEPS2TIME(getTLS(tlsID).getActive()->getCurrentPhaseDef().duration);
161 TrafficLight::getNextSwitch(
const std::string& tlsID) {
162 return STEPS2TIME(getTLS(tlsID).getActive()->getNextSwitchTime());
166 TrafficLight::getServedPersonCount(
const std::string& tlsID,
int index) {
168 if (index < 0 || active->getPhaseNumber() <= index) {
169 throw TraCIException(
"The phase index " +
toString(index) +
" is not in the allowed range [0,"
175 const std::string& state = active->
getPhases()[index]->getState();
176 for (
int i = 0; i < (int)state.size(); i++) {
178 if (link->getLane()->getEdge().isCrossing()) {
192 }
else if (link->getLaneBefore()->getEdge().isCrossing()) {
195 if (
static_cast<MSPerson*
>(person)->
getNextEdge() == link->getLaneBefore()->getEdge().getID()) {
205 std::vector<std::string>
206 TrafficLight::getBlockingVehicles(
const std::string& tlsID,
int linkIndex) {
207 std::vector<std::string> result;
210 if (linkIndex < 0 || linkIndex >= active->
getNumLinks()) {
211 throw TraCIException(
"The link index " +
toString(linkIndex) +
" is not in the allowed range [0,"
215 result.push_back(veh->getID());
220 std::vector<std::string>
221 TrafficLight::getRivalVehicles(
const std::string& tlsID,
int linkIndex) {
222 std::vector<std::string> result;
224 if (linkIndex < 0 || linkIndex >= active->
getNumLinks()) {
225 throw TraCIException(
"The link index " +
toString(linkIndex) +
" is not in the allowed range [0,"
229 result.push_back(veh->getID());
234 std::vector<std::string>
235 TrafficLight::getPriorityVehicles(
const std::string& tlsID,
int linkIndex) {
236 std::vector<std::string> result;
238 if (linkIndex < 0 || linkIndex >= active->
getNumLinks()) {
239 throw TraCIException(
"The link index " +
toString(linkIndex) +
" is not in the allowed range [0,"
243 result.push_back(veh->getID());
249 TrafficLight::getParameter(
const std::string& tlsID,
const std::string& paramName) {
250 return getTLS(tlsID).getActive()->getParameter(paramName,
"");
258 TrafficLight::setRedYellowGreenState(
const std::string& tlsID,
const std::string& state) {
259 getTLS(tlsID).setStateInstantiatingOnline(
MSNet::getInstance()->getTLSControl(), state);
264 TrafficLight::setPhase(
const std::string& tlsID,
const int index) {
266 if (index < 0 || active->getPhaseNumber() <= index) {
267 throw TraCIException(
"The phase index " +
toString(index) +
" is not in the allowed range [0,"
276 TrafficLight::setPhaseName(
const std::string& tlsID,
const std::string& name) {
283 TrafficLight::setProgram(
const std::string& tlsID,
const std::string& programID) {
287 throw TraCIException(e.what());
293 TrafficLight::setPhaseDuration(
const std::string& tlsID,
const double phaseDuration) {
302 TrafficLight::setProgramLogic(
const std::string& tlsID,
const TraCILogic& logic) {
305 if (logic.currentPhaseIndex >= (
int)logic.phases.size()) {
306 throw TraCIException(
"set program: parameter index must be less than parameter phase number.");
308 std::vector<MSPhaseDefinition*> phases;
309 for (TraCIPhase* phase : logic.phases) {
312 if (vars.
getLogic(logic.programID) ==
nullptr) {
314 int step = logic.currentPhaseIndex;
315 const std::string basePath =
"";
321 tlsID, logic.programID,
322 phases, step, nextSwitch,
323 logic.subParameter, basePath);
327 tlsID, logic.programID,
328 phases, step, nextSwitch,
329 logic.subParameter, basePath);
334 phases, step, nextSwitch,
338 throw TraCIException(
"Unsupported traffic light type '" +
toString(logic.type) +
"'");
340 vars.
addLogic(logic.programID, tlLogic,
true,
true);
351 TrafficLight::setParameter(
const std::string& tlsID,
const std::string& paramName,
const std::string& value) {
352 return getTLS(tlsID).getActive()->
setParameter(paramName, value);
360 TrafficLight::getTLS(
const std::string&
id) {
362 throw TraCIException(
"Traffic light '" +
id +
"' is not known");
368 std::shared_ptr<VariableWrapper>
369 TrafficLight::makeWrapper() {
370 return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
375 TrafficLight::handleVariable(
const std::string& objID,
const int variable, VariableWrapper* wrapper) {
378 return wrapper->wrapStringList(objID, variable, getIDList());
380 return wrapper->wrapInt(objID, variable, getIDCount());
382 return wrapper->wrapString(objID, variable, getRedYellowGreenState(objID));
384 return wrapper->wrapStringList(objID, variable, getControlledLanes(objID));
386 return wrapper->wrapInt(objID, variable, getPhase(objID));
388 return wrapper->wrapString(objID, variable, getPhaseName(objID));
390 return wrapper->wrapString(objID, variable, getProgram(objID));
392 return wrapper->wrapDouble(objID, variable, getPhaseDuration(objID));
394 return wrapper->wrapDouble(objID, variable, getNextSwitch(objID));
396 return wrapper->wrapStringList(objID, variable, getControlledJunctions(objID));
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN)
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS)
An actuated (adaptive) traffic light logic.
An actuated traffic light logic based on time delay of approaching vehicles.
const std::set< MSTransportable * > & getPersons() const
Returns this edge's persons set.
Representation of a lane in the micro simulation.
const std::vector< MSLink * > & getLinkCont() const
returns the container with all links !!!
MSEdge & getEdge() const
Returns the lane's edge.
MSLane * getViaLane() const
Returns the following inner lane.
MSLane * getLane() const
Returns the connected lane.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
const std::string & getNextEdge() const
return the list of internal edges if this person is walking and the pedestrian model allows it
The definition of a single phase of a tls logic.
SUMOTime duration
The duration of the phase.
A fixed traffic light logic.
Storage for all programs of a single tls.
MSTrafficLightLogic * getLogic(const std::string &programID) const
bool addLogic(const std::string &programID, MSTrafficLightLogic *logic, bool netWasLoaded, bool isNewDefault=true)
Adds a logic (program)
A class that stores and controls tls and switching of their programs.
std::vector< std::string > getAllTLIds() const
TLSLogicVariants & get(const std::string &id) const
Returns the variants of a named tls.
The parent class for traffic light logics.
int getNumLinks()
return the number of controlled link indices
const LinkVector & getLinksAt(int i) const
Returns the list of links that are controlled by the signals at the given position.
virtual const MSPhaseDefinition & getCurrentPhaseDef() const =0
Returns the definition of the current phase.
std::vector< LaneVector > LaneVectorVector
Definition of a list that holds lists of lanes that do have the same attribute.
virtual int getPhaseNumber() const =0
Returns the number of phases.
virtual int getCurrentPhaseIndex() const =0
Returns the current index within the program.
std::vector< MSLane * > LaneVector
Definition of the list of arrival lanes subjected to this tls.
virtual const MSPhaseDefinition & getPhase(int givenstep) const =0
Returns the definition of the phase from the given position within the plan.
virtual VehicleVector getPriorityVehicles(int linkIndex)
return vehicles that approach the intersection/rail signal and have priority over vehicles that wish ...
virtual void changeStepAndDuration(MSTLLogicControl &tlcontrol, SUMOTime simStep, int step, SUMOTime stepDuration)=0
Changes the current phase and her duration.
virtual VehicleVector getBlockingVehicles(int linkIndex)
return vehicles that block the intersection/rail signal for vehicles that wish to pass the given link...
virtual VehicleVector getRivalVehicles(int linkIndex)
return vehicles that approach the intersection/rail signal and are in conflict with vehicles that wis...
std::vector< LinkVector > LinkVectorVector
Definition of a list that holds lists of links that do have the same attribute.
std::vector< MSLink * > LinkVector
Definition of the list of links that are subjected to this tls.
virtual const Phases & getPhases() const =0
Returns the phases of this tls program.
virtual void init(NLDetectorBuilder &nb)
Initialises the tls with information about incoming lanes.
const MSEdge * getEdge() const
Returns the current edge.
const MSLane * getLane() const
Returns the current lane (may be nullptr)
Builds detectors for microsim.
const std::string & getID() const
Returns the id.
virtual void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
Representation of a vehicle.
C++ TraCI client API implementation.
TRACI_CONST int TRACI_ID_LIST
TRACI_CONST int TL_CONTROLLED_LANES
TRACI_CONST int TL_CONTROLLED_JUNCTIONS
std::map< std::string, TraCIResults > SubscriptionResults
{object->{variable->value}}
TRACI_CONST int TL_NEXT_SWITCH
TRACI_CONST int TL_PHASE_DURATION
TRACI_CONST int TL_CURRENT_PHASE
TRACI_CONST int TL_RED_YELLOW_GREEN_STATE
std::map< std::string, SubscriptionResults > ContextSubscriptionResults
TRACI_CONST int TL_CURRENT_PROGRAM