Eclipse SUMO - Simulation of Urban MObility
NIImporter_SUMO.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2020 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 // Importer for networks stored in SUMO format
21 /****************************************************************************/
22 #pragma once
23 #include <config.h>
24 
25 #include <string>
26 #include <map>
31 #include "NIXMLTypesHandler.h"
32 
33 
34 // ===========================================================================
35 // class declarations
36 // ===========================================================================
37 class NBNetBuilder;
38 class NBEdge;
39 class OptionsCont;
40 
41 
42 // ===========================================================================
43 // class definitions
44 // ===========================================================================
51 public:
67  static void loadNetwork(OptionsCont& oc, NBNetBuilder& nb);
68 
71 
73  static void addPhase(const SUMOSAXAttributes& attrs, NBLoadedSUMOTLDef* currentTL);
74 
76  static GeoConvHelper* loadLocation(const SUMOSAXAttributes& attrs);
77 
78 protected:
83 
86 
88 
89 
100  void myStartElement(int element,
101  const SUMOSAXAttributes& attrs);
102 
103 
110  void myEndElement(int element);
112 
113 
114 private:
116  void _loadNetwork(OptionsCont& oc);
117 
119 
120 
124  void addEdge(const SUMOSAXAttributes& attrs);
125 
126 
130  void addLane(const SUMOSAXAttributes& attrs);
131 
135  void addStopOffsets(const SUMOSAXAttributes& attrs, bool& ok);
136 
140  void addJunction(const SUMOSAXAttributes& attrs);
141 
142 
146  void addRequest(const SUMOSAXAttributes& attrs);
147 
148 
153  void addConnection(const SUMOSAXAttributes& attrs);
154 
158  void addProhibition(const SUMOSAXAttributes& attrs);
159 
163  void addRoundabout(const SUMOSAXAttributes& attrs);
164 
166 
167 
168 
169 private:
174  class Connection final : public Parameterised {
175  public:
177  std::string toEdgeID;
181  std::string tlID;
187  /* @brief Whether the junction must be kept clear coming from this connection
188  * @note: The enum NBEdge::KeepClear is not needed here because data
189  * from a .net.xml is fully specified */
190  bool keepClear;
192  double contPos;
194  double visibility;
198  double speed;
200  double customLength;
205  };
206 
207 
211  class LaneAttrs final : public Parameterised {
212  public:
214  double maxSpeed;
218  std::vector<Connection> connections;
220  std::string allow;
222  std::string disallow;
224  double width;
226  double endOffset;
228  std::map<SVCPermissions, double> stopOffsets;
230  bool accelRamp;
232  std::string oppositeID;
236  std::string type;
237  };
238 
239 
243  class EdgeAttrs final : public Parameterised {
244  public:
246  std::string id;
248  std::string streetName;
250  std::string type;
254  std::string fromNode;
256  std::string toNode;
260  double length;
262  int priority;
264  double maxSpeed;
266  std::vector<LaneAttrs*> lanes;
272  std::map<SVCPermissions, double> stopOffsets;
274  double distance;
275  };
276 
277 
281  struct Prohibition {
282  std::string prohibitorFrom;
283  std::string prohibitorTo;
284  std::string prohibitedFrom;
285  std::string prohibitedTo;
286  };
287 
291  struct Crossing {
292  Crossing(const std::string& _edgeID) :
293  edgeID(_edgeID), customTLIndex(-1), customTLIndex2(-1) {}
294 
295  std::string edgeID;
296  std::vector<std::string> crossingEdges;
297  double width;
298  bool priority;
302  };
303 
309  std::vector<std::string> fromEdges;
310  std::vector<std::string> toEdges;
311  std::vector<std::string> fromCrossed;
312  std::vector<std::string> toCrossed;
313  };
314 
318  struct JunctionAttrs {
320  // @the list of internal lanes corresponding to each link
321  std::vector<std::string> intLanes;
322  // @brief the complete response definition for all links
323  std::vector<std::string> response;
324  };
325 
327  std::map<std::string, EdgeAttrs*> myEdges;
328 
330  std::vector<Prohibition> myProhibitions;
331 
334 
337 
340 
343 
346 
349 
352 
355 
358 
360  std::map<std::string, std::vector<Crossing> > myPedestrianCrossings;
361 
363  std::map<std::string, WalkingAreaParsedCustomShape> myWACustomShapes;
364 
366  std::vector<Parameterised*> myLastParameterised;
367 
370 
373 
376 
379 
382 
385 
388 
391 
398  std::string myDefaultSpreadType;
401 
403  std::vector<std::vector<std::string> > myRoundabouts;
404 
406  std::set<std::string> myRailSignals;
407 
409  std::set<std::string> myDiscardableParams;
410 
411 private:
416  LaneAttrs* getLaneAttrsFromID(EdgeAttrs* edge, std::string lane_id);
417 
419  static Position readPosition(const SUMOSAXAttributes& attrs, const std::string& id, bool& ok);
420 
427  void parseProhibitionConnection(const std::string& attr, std::string& from, std::string& to, bool& ok);
428 };
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
LaneSpreadFunction
Numbers representing special SUMO-XML-attribute values Information how the edge's lateral offset shal...
SumoXMLEdgeFunc
Numbers representing special SUMO-XML-attribute values for representing edge functions used in netbui...
static methods for processing the coordinates conversion for the current net
Definition: GeoConvHelper.h:53
The representation of a single edge during network building.
Definition: NBEdge.h:91
A loaded (complete) traffic light logic.
Instance responsible for building networks.
Definition: NBNetBuilder.h:107
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:58
Represents a single node (junction) during network building.
Definition: NBNode.h:66
A container for traffic light definitions and built programs.
A connection description.
PositionVector customShape
custom shape connection
std::string tlID
The id of the traffic light that controls this connection.
double speed
custom speed for connection
std::string toEdgeID
The id of the target edge.
double customLength
custom length for connection
double contPos
custom position for internal junction on this connection
int toLaneIdx
The index of the target lane.
int tlLinkIndex
The index of this connection within the controlling traffic light.
double visibility
custom foe visibility for connection
bool mayDefinitelyPass
Information about being definitely free to drive (on-ramps)
bool uncontrolled
if set to true, This connection will not be TLS-controlled despite its node being controlled.
SVCPermissions permissions
custom permissions for connection
Describes the values found in an edge's definition and this edge's lanes.
LaneSpreadFunction lsf
The lane spread function.
std::vector< LaneAttrs * > lanes
This edge's lanes.
std::map< SVCPermissions, double > stopOffsets
This edge's vehicle specific stop offsets (used for lanes, that do not have a specified stopOffset)
PositionVector shape
This edges's shape.
int priority
This edge's priority.
std::string toNode
The node this edge ends at.
std::string type
This edge's type.
double maxSpeed
The maximum velocity allowed on this edge (!!!)
NBEdge * builtEdge
The built edge.
SumoXMLEdgeFunc func
This edge's function.
std::string streetName
This edge's street name.
std::string fromNode
The node this edge starts at.
double length
The length of the edge if set explicitly.
std::string id
This edge's id.
double distance
The position at the start of this edge (kilometrage/mileage)
Describes the values found in a lane's definition.
double maxSpeed
The maximum velocity allowed on this lane.
double endOffset
This lane's offset from the intersection.
bool accelRamp
Whether this lane is an acceleration lane.
std::string oppositeID
This lane's opposite lane.
std::string type
the type of this lane
std::vector< Connection > connections
This lane's connections.
bool customShape
Whether this lane has a custom shape.
PositionVector shape
This lane's shape (may be custom)
double width
The width of this lane.
std::string disallow
This lane's disallowed vehicle classes.
std::map< SVCPermissions, double > stopOffsets
This lane's vehicle specific stop offsets.
std::string allow
This lane's allowed vehicle classes.
Importer for networks stored in SUMO format.
GeoConvHelper * myLocation
The coordinate transformation which was used to build the loaded network.
static NBLoadedSUMOTLDef * initTrafficLightLogic(const SUMOSAXAttributes &attrs, NBLoadedSUMOTLDef *currentTL)
begins the reading of a traffic lights logic
void parseProhibitionConnection(const std::string &attr, std::string &from, std::string &to, bool &ok)
parses connection string of a prohibition (very old school)
~NIImporter_SUMO()
Destructor.
NIXMLTypesHandler myTypesHandler
The handler for parsing edge types and restrictions.
int myCornerDetail
the level of corner detail in the loaded network
bool myCheckLaneFoesAll
whether foe-relationships where checked at lane-level
double myLimitTurnSpeed
whether turning speed was limited in the network
std::set< std::string > myRailSignals
list of node id with rail signals (no NBTrafficLightDefinition exists)
bool myGeomAvoidOverlap
overlap option for loaded network
std::map< std::string, std::vector< Crossing > > myPedestrianCrossings
The pedestrian crossings found in the network.
bool myCheckLaneFoesRoundabout
JunctionAttrs myCurrentJunction
The currently parsed junction definition to help in reconstructing crossings.
void addJunction(const SUMOSAXAttributes &attrs)
Parses a junction and saves it in the node control.
bool myAmLefthand
whether the loaded network was built for lefthand traffic
bool myRectLaneCut
whether all lanes of an edge should have the same stop line
std::vector< Parameterised * > myLastParameterised
element to receive parameters
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
std::string myDefaultSpreadType
default spreadType defined in the network
NBLoadedSUMOTLDef * myCurrentTL
The currently parsed traffic light.
static void loadNetwork(OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given SUMO file.
std::vector< std::vector< std::string > > myRoundabouts
loaded roundabout edges
LaneAttrs * getLaneAttrsFromID(EdgeAttrs *edge, std::string lane_id)
Parses lane index from lane ID an retrieve lane from EdgeAttrs.
void addConnection(const SUMOSAXAttributes &attrs)
Parses a connection and saves it into the lane's definition stored in "myCurrentLane".
void addEdge(const SUMOSAXAttributes &attrs)
Parses an edge and stores the values in "myCurrentEdge".
LaneAttrs * myCurrentLane
The currently parsed lanes's definition (to add the shape to)
void addLane(const SUMOSAXAttributes &attrs)
Parses a lane and stores the values in "myCurrentLane".
NBNodeCont & myNodeCont
The node container to fill.
EdgeAttrs * myCurrentEdge
The currently parsed edge's definition (to add loaded lanes to)
NBNetBuilder & myNetBuilder
The network builder to fill.
void addRoundabout(const SUMOSAXAttributes &attrs)
Parses a roundabout and stores it in myEdgeCont.
std::vector< Prohibition > myProhibitions
Loaded prohibitions.
double myNetworkVersion
the loaded network version
void _loadNetwork(OptionsCont &oc)
load the network
void myEndElement(int element)
Called when a closing tag occurs.
bool myTlsIgnoreInternalJunctionJam
whether some right-of-way checks at traffic light junctions should be disabled
void addStopOffsets(const SUMOSAXAttributes &attrs, bool &ok)
parses stop offsets for the current lane or edge
static Position readPosition(const SUMOSAXAttributes &attrs, const std::string &id, bool &ok)
read position from the given attributes, attribute errors to id
static void addPhase(const SUMOSAXAttributes &attrs, NBLoadedSUMOTLDef *currentTL)
adds a phase to the traffic lights logic currently build
int myLinkDetail
the level of geometry detail for internal lanes in the loaded network
std::map< std::string, WalkingAreaParsedCustomShape > myWACustomShapes
Map from walkingArea edge IDs to custom shapes.
bool myWalkingAreas
whether walkingareas must be built
NBTrafficLightLogicCont & myTLLCont
The node container to fill.
NIImporter_SUMO(NBNetBuilder &nb)
Constructor.
void addProhibition(const SUMOSAXAttributes &attrs)
Parses a prohibition and saves it.
void addRequest(const SUMOSAXAttributes &attrs)
Parses a reques and saves selected attributes in myCurrentJunction.
std::set< std::string > myDiscardableParams
list of parameter keys to discard
static GeoConvHelper * loadLocation(const SUMOSAXAttributes &attrs)
Parses network location description and registers it with GeoConveHelper::setLoaded.
std::map< std::string, EdgeAttrs * > myEdges
Loaded edge definitions.
bool myHaveSeenInternalEdge
whether the loaded network contains internal lanes
Importer for edge type information stored in XML.
A storage for options typed value containers)
Definition: OptionsCont.h:89
An upper class for objects with additional parameters.
Definition: Parameterised.h:39
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
A list of positions.
Encapsulated SAX-Attributes.
SAX-handler base for SUMO-files.
Describes a pedestrian crossing.
std::vector< std::string > crossingEdges
Crossing(const std::string &_edgeID)
Describes the values found in a junction.
std::vector< std::string > response
std::vector< std::string > intLanes
Describes the values found in a prohibition.
Describes custom shape for a walking area during parsing.