59 if (oc.
isSet(
"tls.half-offset")) {
65 if (oc.
isSet(
"tls.quarter-offset")) {
66 std::vector<std::string> ids = oc.
getStringVector(
"tls.quarter-offset");
77 for (
auto item : programs) {
78 idS.
avoid(item.first);
163 for (Logics::iterator it = logics.begin(); it != logics.end(); it++) {
167 if (oc.
getBool(
"tls.rebuild")) {
170 if (lDef !=
nullptr) {
179 e->clearControllingTLInformation();
183 node->removeTrafficLight(def);
184 for (
auto c : node->getCrossings()) {
185 c->customTLIndex = -1;
186 c->customTLIndex2 = -1;
187 c->tlLinkIndex2 = -1;
195 if (oc.
getBool(
"tls.group-signals")) {
199 if (lDef ==
nullptr) {
201 if (logic !=
nullptr) {
205 node->removeTrafficLight(def);
206 node->addTrafficLight(lDef);
213 if (lDef !=
nullptr) {
217 }
else if (oc.
getBool(
"tls.ungroup-signals")) {
221 if (lDef !=
nullptr) {
234 return std::pair<int, int>((
int)
myComputed.size(), numPrograms);
243 const std::string&
id = def->
getID();
247 if (built ==
nullptr) {
248 WRITE_WARNINGF(
TL(
"Could not build program '%' for traffic light '%'"), programID,
id);
272 for (Definitions::iterator it = definitions.begin(); it != definitions.end(); it++) {
277 for (Logics::iterator it = logics.begin(); it != logics.end(); it++) {
281 for (std::set<NBTrafficLightDefinition*>::iterator it =
myExtracted.begin(); it !=
myExtracted.end(); it++) {
292 for (Definitions::iterator it = definitions.begin(); it != definitions.end(); it++) {
293 (*it)->remapRemoved(removed, incoming, outgoing);
300 NBEdge* by,
int byLane,
bool incoming) {
302 for (Definitions::iterator it = definitions.begin(); it != definitions.end(); it++) {
303 (*it)->replaceRemoved(removed, removedLane, by, byLane, incoming);
313 Program2Def::const_iterator i2 = programs.find(programID);
314 if (i2 != programs.end()) {
334 Id2Logics::const_iterator i =
myComputed.find(
id);
337 Program2Logic::const_iterator i2 = programs.find(programID);
338 if (i2 != programs.end()) {
350 for (Definitions::iterator it = definitions.begin(); it != definitions.end(); it++) {
351 (*it)->setParticipantsInformation();
356 for (Definitions::iterator it = definitions.begin(); it != definitions.end(); it++) {
357 (*it)->setTLControllingInformation();
360 for (std::map<std::string, NBNode*>::const_iterator it = nc.
begin(); it != nc.
end(); it ++) {
377 std::map<NBEdge*, std::string> defaultSignalIDs;
378 for (
const NBConnection& con : def->getControlledLinks()) {
379 const NBEdge::Connection& c = con.getFrom()->getConnection(con.getFromLane(), con.getTo(), con.getToLane());
381 defaultSignalIDs[con.getFrom()] = c.
getParameter(
"signalID");
386 for (
const NBConnection& con : def->getControlledLinks()) {
387 const NBEdge::Connection& c = con.getFrom()->getConnection(con.getFromLane(), con.getTo(), con.getToLane());
388 if (!c.
hasParameter(
"signalID") && defaultSignalIDs.count(con.getFrom()) != 0) {
389 WRITE_WARNINGF(
TL(
"Guessing signalID for link index % at traffic light '%'."), con.getTLIndex(), def->getID());
390 def->setParameter(
"linkSignalID:" +
toString(con.getTLIndex()), defaultSignalIDs[con.getFrom()]);
401 std::map<std::string, NBTrafficLightDefinition*> defsToGroup;
402 std::map<std::string, std::map<std::string, std::set<int>>> controllerID2tlIndex;
404 bool makeGroups =
false;
406 std::string defID = def->getID();
409 std::string controllerID = conn.getFrom()->getConnection(conn.getFromLane(), conn.getTo(), conn.getToLane()).getParameter(
"controllerID");
410 if (controllerID !=
"") {
411 if (controllerID2tlIndex.find(defID) == controllerID2tlIndex.end()) {
412 controllerID2tlIndex[defID][controllerID] = std::set<int>({ conn.getTLIndex() });
413 }
else if (controllerID2tlIndex[defID].find(controllerID) != controllerID2tlIndex[defID].end()) {
414 controllerID2tlIndex[defID][controllerID].insert(conn.getTLIndex());
416 controllerID2tlIndex[defID][controllerID] = std::set<int>({ conn.getTLIndex() });
418 makeGroups = controllerID2tlIndex[defID][controllerID].size() > 1 || makeGroups;
422 defsToGroup[def->getID()] = def;
427 const std::string computedID = computed->getID();
428 if (defsToGroup.find(computedID) != defsToGroup.end()) {
431 const std::vector<NBTrafficLightLogic::PhaseDefinition> phases = computed->getPhases();
432 std::vector<int> major2minor;
433 for (
const auto& indexSet : controllerID2tlIndex[computedID]) {
434 if (indexSet.second.size() < 2) {
437 bool toMinor =
false;
439 std::set<int>::iterator it = indexSet.second.begin();
440 char firstChar = phase.state[*it];
445 for (; it != indexSet.second.end(); it++) {
447 if (compareChar != firstChar) {
459 major2minor.push_back(*indexSet.second.begin());
464 if (lDef ==
nullptr) {
467 for (
int index : major2minor) {
468 for (
int i = 0; i < (int)phases.size(); i++) {
475 std::vector<int> indexToRemove;
476 for (
const auto& indexSet : controllerID2tlIndex[computedID]) {
477 int minIndex = *indexSet.second.begin();
478 for (
int index : indexSet.second) {
479 if (index != minIndex) {
481 indexToRemove.push_back(index);
488 node->removeTrafficLight(defsToGroup[computedID]);
489 node->addTrafficLight(lDef);
491 removeProgram(defsToGroup[computedID]->getID(), defsToGroup[computedID]->getProgramID());
496 WRITE_WARNINGF(
TL(
"Was not able to apply the OpenDRIVE signal group information onto the signal program of traffic light % generated by SUMO."), computed->getID());
507 for (Id2Logics::const_iterator it_id =
myComputed.begin(); it_id !=
myComputed.end(); it_id++) {
509 for (Program2Logic::const_iterator it_prog = programs.begin(); it_prog != programs.end(); it_prog++) {
510 result.push_back(it_prog->second);
522 for (Program2Def::const_iterator it_prog = programs.begin(); it_prog != programs.end(); it_prog++) {
523 result.push_back(it_prog->second);
534 for (
auto item : it->second) {
535 item.second->setID(newID);
542 for (
auto item : it2->second) {
543 item.second->setID(newID);
#define WRITE_WARNINGF(...)
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
@ LINKSTATE_TL_GREEN_MAJOR
The link has green light, may pass.
@ LINKSTATE_TL_GREEN_MINOR
The link has green light, has to brake.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
std::string getNext()
Returns the next id.
void avoid(const std::string &id)
make sure that the given id is never supplied
Storage for edges, including some functionality operating on multiple edges.
void clearControllingTLInformation() const
Clears information about controlling traffic lights for all connenections of all edges.
The representation of a single edge during network building.
A loaded (complete) traffic light logic.
bool usingSignalGroups() const
whether this definition uses signal group (multiple connections with the same link index)
void ungroupSignals()
let all connections use a distinct link index
NBTrafficLightLogic * getLogic()
Returns the internal logic.
void groupSignals()
let connections with the same state use the same link index
void replaceIndex(int oldIndex, int newIndex)
replace the given link index in all connections
Container for nodes during the netbuilding process.
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Represents a single node (junction) during network building.
SumoXMLNodeType getType() const
Returns the type of this node.
void removeTrafficLight(NBTrafficLightDefinition *tlDef)
Removes the given traffic light from this node.
bool setCrossingTLIndices(const std::string &tlID, int startIndex, bool ignoreCustom=false)
A traffic light logics which must be computed (only nodes/edges are given)
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
The base class for traffic light logic definitions.
const std::vector< NBNode * > & getNodes() const
Returns the list of controlled nodes.
const std::string & getProgramID() const
Returns the ProgramID.
const EdgeVector & getIncomingEdges() const
Returns the list of incoming edges (must be build first)
TrafficLightType getType() const
get the algorithm type (static etc..)
virtual void setProgramID(const std::string &programID)
Sets the programID.
NBTrafficLightLogic * compute(const OptionsCont &oc)
Computes the traffic light logic.
const NBConnectionVector & getControlledLinks() const
returns the controlled links (depends on previous call to collectLinks)
virtual void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
The definition of a single phase of the logic.
bool exist(const std::string &newID, bool requireComputed=true) const
check if exists a definition with the given ID
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane, bool incoming)
Replaces occurrences of the removed edge/lane in all definitions by the given edge.
void applyOptions(OptionsCont &oc)
Initialises the storage by applying given options.
void setOpenDriveSignalParameters()
set OpenDRIVE signal reference parameters after all link indices are known
std::vector< NBTrafficLightLogic * > getComputed() const
Returns a list of all computed logics.
void rename(NBTrafficLightDefinition *tlDef, const std::string &newID)
rename traffic light
std::map< std::string, NBTrafficLightDefinition * > Program2Def
std::set< std::string > myHalfOffsetTLS
List of tls which shall have an offset of T/2.
static const Program2Def EmptyDefinitions
empty definition
std::vector< NBTrafficLightLogic * > Logics
std::vector< NBTrafficLightDefinition * > Definitions
Returns a list of all definitions (convenience for easier iteration)
bool removeProgram(const std::string id, const std::string programID, bool del=true)
Removes a program of a logic definition from the dictionary.
bool computeSingleLogic(OptionsCont &oc, NBTrafficLightDefinition *def)
Computes a specific traffic light logic (using by netedit)
int getNumExtracted() const
return the number of extracted traffic light definitions
void clear()
Destroys all stored definitions and logics.
const std::map< std::string, NBTrafficLightDefinition * > & getPrograms(const std::string &id) const
Returns all programs for the given tl-id.
void remapRemoved(NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing)
Replaces occurrences of the removed edge in incoming/outgoing edges of all definitions.
Definitions getDefinitions() const
std::set< std::string > myQuarterOffsetTLS
List of tls which shall have an offset of T/2.
Id2Logics myComputed
The container for previously computed tl-logics.
NBTrafficLightLogic * getLogic(const std::string &id, const std::string &programID) const
Returns the computed logic for the given name.
void applyOpenDriveControllers(OptionsCont &oc)
post processing of signal programs to group tl indices according to OpenDrive controllers (signal gro...
Id2Defs myDefinitions
The container for tl-ids to their definitions.
std::pair< int, int > computeLogics(OptionsCont &oc)
Computes the traffic light logics using the stored definitions and stores the results.
bool removeFully(const std::string id)
Removes a logic definition (and all programs) from the dictionary.
NBTrafficLightLogicCont()
Constructor.
std::map< std::string, NBTrafficLightLogic * > Program2Logic
Definition of internal the container types.
std::string getNextProgramID(const std::string &id) const
Returns a new (unused) programID for the given traffic light.
~NBTrafficLightLogicCont()
Destructor.
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
NBTrafficLightDefinition * getDefinition(const std::string &id, const std::string &programID) const
Returns the named definition.
void extract(NBTrafficLightDefinition *definition)
Extracts a traffic light definition from myDefinitions but keeps it in myExtracted for eventual * del...
void setTLControllingInformation(const NBEdgeCont &ec, const NBNodeCont &nc)
Informs the edges about being controlled by a tls.
std::set< NBTrafficLightDefinition * > myExtracted
The container for extracted definitions.
A SUMO-compliant built logic for a traffic light.
SUMOTime getDuration() const
Returns the duration of the complete cycle.
void setPhaseState(int phaseIndex, int tlIndex, LinkState linkState)
Modifies the state for an existing phase (used by netedit)
void setOffset(SUMOTime offset)
Sets the offset of this tls.
const std::string & getID() const
Returns the id.
A storage for options typed value containers)
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
bool hasParameter(const std::string &key) const
Returns whether the parameter is set.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
T get(const std::string &str) const
get key
A structure which describes a connection between edges or lanes.