34 #include <xercesc/sax/HandlerBase.hpp> 35 #include <xercesc/sax/AttributeList.hpp> 36 #include <xercesc/sax/SAXParseException.hpp> 37 #include <xercesc/sax/SAXException.hpp> 65 myResetPhases(false) {
128 WRITE_ERROR(
"Definition of tlLogic '" + currentTL->
getID() +
"' was not finished.");
141 WRITE_ERROR(
"Unknown traffic light type '" + typeS +
"' for tlLogic '" +
id +
"'.");
152 if (programs.size() == 0) {
153 WRITE_ERROR(
"Cannot load traffic light program for unknown id '" +
id +
"', programID '" + programID +
"'.");
156 const std::string existingProgram = programs.begin()->first;
158 if (loadedDef == 0) {
169 WRITE_ERROR(
"Cannot load traffic light program for unknown id '" +
id +
"', programID '" + programID +
"'.");
176 std::vector<NBNode*> nodes = newDef->
getNodes();
177 for (std::vector<NBNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) {
183 std::vector<NBNode*> nodes = newDef->
getNodes();
184 for (std::vector<NBNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) {
185 (*it)->removeTrafficLight(newDef);
197 std::vector<NBNode*> nodes = oldDef->
getNodes();
198 for (std::vector<NBNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) {
199 loadedDef->addNode(*it);
232 const std::vector<NBEdge::Connection>& connections = from->
getConnections();
233 std::vector<NBEdge::Connection>::const_iterator con_it;
234 con_it = find_if(connections.begin(), connections.end(),
236 if (con_it == connections.end()) {
238 " fromLane=" +
toString(fromLane) +
" toLane=" +
toString(toLane) +
" not found");
257 if (programs.size() > 0) {
258 std::map<std::string, NBTrafficLightDefinition*>::const_iterator it;
259 for (it = programs.begin(); it != programs.end(); it++) {
265 + tlID +
"' (program '" + it->first +
"')");
271 WRITE_ERROR(
"The traffic light '" + tlID +
"' is not known.");
283 if (programs.size() > 0) {
299 std::map<std::string, NBTrafficLightDefinition*>::const_iterator it;
300 for (it = programs.begin(); it != programs.end(); it++) {
306 + tlID +
"' (program '" + it->first +
"')");
316 std::string edgeID = attrs.
get<std::string>(attr, 0, ok);
319 WRITE_ERROR(
"Unknown edge '" + edgeID +
"' given in connection.");
329 int laneIndex = attrs.
get<
int>(attr, 0, ok);
int tlLinkNo
The index of this connection within the controlling traffic light.
const std::map< std::string, NBTrafficLightDefinition * > & getPrograms(const std::string &id) const
Returns all programs for the given tl-id.
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 myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
A structure which describes a connection between edges or lanes.
int toLane
The lane the connections yields in.
static void addPhase(const SUMOSAXAttributes &attrs, NBLoadedSUMOTLDef *currentTL)
adds a phase to the traffic lights logic currently build
bool removeProgram(const std::string id, const std::string programID, bool del=true)
Removes a program of a logic definition from the dictionary.
virtual void addNode(NBNode *node)
Adds a node to the traffic light logic.
NBEdge * toEdge
The edge the connections yields in.
void setOffset(SUMOTime offset)
Sets the offset of this tls.
int getNumLinks()
Returns the number of participating links.
A loaded (complete) traffic light logic.
NBEdgeCont & myEdgeCont
The edge container for retrieving edges.
A container for traffic light definitions and built programs.
A SUMO-compliant built logic for a traffic light.
NBEdge * retrieveEdge(const SUMOSAXAttributes &attrs, SumoXMLAttr attr, bool &ok)
parses and edge id an returns an existing edge
connectio between two lanes
The representation of a single edge during network building.
void phasesLoaded()
mark phases as load
The base class for traffic light logic definitions.
link,node: the traffic light id responsible for this link
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
const std::string & getID() const
Returns the id.
NBLoadedSUMOTLDef * initTrafficLightLogic(const SUMOSAXAttributes &attrs, NBLoadedSUMOTLDef *currentTL)
SAX-handler base for SUMO-files.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
static OptionsCont & getOptions()
Retrieves the options.
virtual std::string getString(int id) const =0
Returns the string-value of the named (by its enum-value) attribute.
NBTrafficLightLogicCont & myTLLCont
The traffic light container to fill.
int retrieveLaneIndex(const SUMOSAXAttributes &attrs, SumoXMLAttr attr, NBEdge *edge, bool &ok)
parses a lane index and verifies its correctness
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
NBTrafficLightDefinition * getDefinition(const std::string &id, const std::string &programID) const
Returns the named definition.
Encapsulated SAX-Attributes.
std::string tlID
The id of the traffic light that controls this connection.
void addTlConnection(const SUMOSAXAttributes &attrs)
reads and adds tl-controlled connection
static StringBijection< TrafficLightType > TrafficLightTypes
traffic light types
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
int getNumLanes() const
Returns the number of lanes.
int fromLane
The lane the connections starts at.
parameter associated to a certain key
void addConnection(NBEdge *from, NBEdge *to, int fromLane, int toLane, int linkIndex, bool reconstruct=true)
Adds a connection and immediately informs the edges.
T get(const std::string &str) const
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
NBLoadedSUMOTLDef * myCurrentTL
The currently parsed traffic light.
Storage for edges, including some functionality operating on multiple edges.
void removeTlConnection(const SUMOSAXAttributes &attrs)
reads and removes tl-controlled connection
NBTrafficLightLogic * getLogic()
Returns the internal logic.
void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
static const std::string DefaultProgramID
void addControlledInnerEdges(const std::vector< std::string > &edges)
Adds the given ids into the list of inner edges controlled by the tls.
bool myResetPhases
whether phases of a previously loaded traffic light must be reset
~NIXMLTrafficLightsHandler()
Destructor.
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.
void myEndElement(int element)
Called when a closing tag occurs.
const std::vector< Connection > & getConnections() const
Returns the connections.
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
const std::vector< NBNode * > & getNodes() const
Returns the list of controlled nodes.
SumoXMLNodeType getType() const
Returns the type of this node.
NIXMLTrafficLightsHandler(NBTrafficLightLogicCont &tlCont, NBEdgeCont &ec)
Constructor.
bool insert(NBTrafficLightDefinition *logic, bool forceInsert=false)
Adds a logic definition to the dictionary.
link: the index of the link within the traffic light
void setType(TrafficLightType type)
Sets the algorithm type of this tls.
A traffic light logics which must be computed (only nodes/edges are given)
std::vector< std::string > getControlledInnerEdges() const
Retrieve the ids of edges explicitly controlled by the tls.
NBNode * getToNode() const
Returns the destination node of the edge.
a single phase description