26 #include <xercesc/sax/HandlerBase.hpp>
27 #include <xercesc/sax/AttributeList.hpp>
28 #include <xercesc/sax/SAXParseException.hpp>
29 #include <xercesc/sax/SAXException.hpp>
58 myIgnoreUnknown(ignoreUnknown)
117 WRITE_ERROR(
"Definition of tlLogic '" + currentTL->
getID() +
"' was not finished.");
130 WRITE_ERROR(
"Unknown traffic light type '" + typeS +
"' for tlLogic '" +
id +
"'.");
141 if (programs.size() == 0) {
143 WRITE_ERROR(
"Cannot load traffic light program for unknown id '" +
id +
"', programID '" + programID +
"'.");
147 const std::string existingProgram = programs.begin()->first;
149 if (loadedDef ==
nullptr) {
151 if (oldDef ==
nullptr) {
155 bool deleteDefault =
false;
156 if (newDef ==
nullptr) {
160 if (newDef ==
nullptr) {
161 WRITE_ERROR(
"Cannot load traffic light program for unknown id '" +
id +
"', programID '" + programID +
"'.");
165 deleteDefault =
true;
170 std::vector<NBNode*> nodes = newDef->
getNodes();
171 for (std::vector<NBNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) {
177 const std::vector<NBNode*> nodes = newDef->
getNodes();
179 for (
NBNode*
const n : nodes) {
180 n->removeTrafficLight(newDef);
191 std::vector<NBNode*> nodes = oldDef->
getNodes();
192 for (std::vector<NBNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) {
231 const std::vector<NBEdge::Connection>& connections = from->
getConnections();
232 std::vector<NBEdge::Connection>::const_iterator con_it;
233 con_it = find_if(connections.begin(), connections.end(),
235 if (con_it == connections.end()) {
237 " fromLane=" +
toString(fromLane) +
" toLane=" +
toString(toLane) +
" not found");
254 if (tlIndex2 == -1) {
261 if (programs.size() > 0) {
262 std::map<std::string, NBTrafficLightDefinition*>::const_iterator it;
263 for (it = programs.begin(); it != programs.end(); it++) {
269 + tlID +
"' (program '" + it->first +
"')");
275 WRITE_ERROR(
"The traffic light '" + tlID +
"' is not known.");
287 if (programs.size() > 0) {
301 std::map<std::string, NBTrafficLightDefinition*>::const_iterator it;
302 for (it = programs.begin(); it != programs.end(); it++) {
308 + tlID +
"' (program '" + it->first +
"')");
318 std::string edgeID = attrs.
get<std::string>(attr,
nullptr, ok);
320 if (edge ==
nullptr) {
321 WRITE_ERROR(
"Unknown edge '" + edgeID +
"' given in connection.");
331 int laneIndex = attrs.
get<
int>(attr,
nullptr, ok);
@ SUMO_TAG_PHASE
a single phase description
@ SUMO_TAG_CONNECTION
connectio between two lanes
@ SUMO_TAG_TLLOGIC
a traffic light logic
@ SUMO_TAG_PARAM
parameter associated to a certain key
@ SUMO_TAG_DEL
delete certain element (note: DELETE is a macro)
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_TLLINKINDEX2
link: the index of the opposite direction link of a pedestrian crossing
@ SUMO_ATTR_TLID
link,node: the traffic light id responsible for this link
@ SUMO_ATTR_TLLINKINDEX
link: the index of the link within the traffic light
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Storage for edges, including some functionality operating on multiple edges.
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
The representation of a single edge during network building.
const std::string & getID() const
NBNode * getToNode() const
Returns the destination node of the edge.
int getNumLanes() const
Returns the number of lanes.
const std::vector< Connection > & getConnections() const
Returns the connections.
A loaded (complete) traffic light logic.
void phasesLoaded()
mark phases as load
void removeConnection(const NBConnection &conn, bool reconstruct=true)
removes the given connection from the traffic light if recontruct=true, reconstructs the logic and in...
void setType(TrafficLightType type)
Sets the algorithm type of this tls.
void addConnection(NBEdge *from, NBEdge *to, int fromLane, int toLane, int linkIndex, int linkIndex2, bool reconstruct=true)
Adds a connection and immediately informs the edges.
NBTrafficLightLogic * getLogic()
Returns the internal logic.
void setOffset(SUMOTime offset)
Sets the offset of this tls.
Represents a single node (junction) during network building.
SumoXMLNodeType getType() const
Returns the type of this node.
const std::set< NBTrafficLightDefinition * > & getControllingTLS() const
Returns the traffic lights that were assigned to this node (The set of tls that control this node)
A traffic light logics which must be computed (only nodes/edges are given)
The base class for traffic light logic definitions.
void addControlledInnerEdges(const std::vector< std::string > &edges)
Adds the given ids into the list of inner edges controlled by the tls.
virtual void addNode(NBNode *node)
Adds a node to the traffic light logic.
const std::vector< NBNode * > & getNodes() const
Returns the list of controlled nodes.
std::vector< std::string > getControlledInnerEdges() const
Retrieve the ids of edges explicitly controlled by the tls.
static const std::string DefaultProgramID
A container for traffic light definitions and built programs.
bool removeProgram(const std::string id, const std::string programID, bool del=true)
Removes a program of a logic definition from the dictionary.
const std::map< std::string, NBTrafficLightDefinition * > & getPrograms(const std::string &id) const
Returns all programs for the given tl-id.
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.
A SUMO-compliant built logic for a traffic light.
int getNumLinks()
Returns the number of participating links.
static void addPhase(const SUMOSAXAttributes &attrs, NBLoadedSUMOTLDef *currentTL)
adds a phase to the traffic lights logic currently build
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
NBEdgeCont & myEdgeCont
The edge container for retrieving edges.
~NIXMLTrafficLightsHandler()
Destructor.
bool myResetPhases
whether phases of a previously loaded traffic light must be reset
NBLoadedSUMOTLDef * myCurrentTL
The currently parsed traffic light.
int retrieveLaneIndex(const SUMOSAXAttributes &attrs, SumoXMLAttr attr, NBEdge *edge, bool &ok, bool isDelete=false)
parses a lane index and verifies its correctness
NBTrafficLightLogicCont & myTLLCont
The traffic light container to fill.
bool myIgnoreUnknown
whether definitions for unknown traffic lights shall be silently ignored
void myEndElement(int element)
Called when a closing tag occurs.
NBEdge * retrieveEdge(const SUMOSAXAttributes &attrs, SumoXMLAttr attr, bool &ok)
parses and edge id an returns an existing edge
void addTlConnection(const SUMOSAXAttributes &attrs)
reads and adds tl-controlled connection
void removeTlConnection(const SUMOSAXAttributes &attrs)
reads and removes tl-controlled connection
NBLoadedSUMOTLDef * initTrafficLightLogic(const SUMOSAXAttributes &attrs, NBLoadedSUMOTLDef *currentTL)
NIXMLTrafficLightsHandler(NBTrafficLightLogicCont &tlCont, NBEdgeCont &ec, bool ignoreUnknown=false)
Constructor.
const std::string & getID() const
Returns the id.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
static OptionsCont & getOptions()
Retrieves the options.
virtual void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
Encapsulated SAX-Attributes.
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue, bool report=true) const
Tries to read given attribute assuming it is an int.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
virtual std::string getString(int id) const =0
Returns the string-value of the named (by its enum-value) attribute.
SAX-handler base for SUMO-files.
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
T get(const std::string &str) const
A structure which describes a connection between edges or lanes.
int fromLane
The lane the connections starts at.
int toLane
The lane the connections yields in.
NBEdge * toEdge
The edge the connections yields in.
int tlLinkIndex2
The index of the internal junction within the controlling traffic light (optional)
int tlLinkIndex
The index of this connection within the controlling traffic light.