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-2022 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;
202  double speed;
204  double customLength;
212  std::string edgeType;
213  };
214 
215 
219  class LaneAttrs final : public Parameterised {
220  public:
222  double maxSpeed;
226  std::vector<Connection> connections;
228  std::string allow;
230  std::string disallow;
232  std::string changeLeft;
234  std::string changeRight;
236  double width;
238  double endOffset;
242  bool accelRamp;
244  std::string oppositeID;
248  std::string type;
249  };
250 
251 
255  class EdgeAttrs final : public Parameterised {
256  public:
258  std::string id;
260  std::string streetName;
262  std::string type;
266  std::string fromNode;
268  std::string toNode;
272  double length;
274  int priority;
276  double maxSpeed;
278  std::vector<LaneAttrs*> lanes;
286  double distance;
287  };
288 
289 
293  struct Prohibition {
294  std::string prohibitorFrom;
295  std::string prohibitorTo;
296  std::string prohibitedFrom;
297  std::string prohibitedTo;
298  };
299 
303  struct Crossing {
304  Crossing(const std::string& _edgeID) :
305  edgeID(_edgeID), customTLIndex(-1), customTLIndex2(-1) {}
306 
307  std::string edgeID;
308  std::vector<std::string> crossingEdges;
309  double width;
310  bool priority;
314  };
315 
321  std::vector<std::string> fromEdges;
322  std::vector<std::string> toEdges;
323  std::vector<std::string> fromCrossed;
324  std::vector<std::string> toCrossed;
325  double width;
326  };
327 
331  struct JunctionAttrs {
333  // @the list of internal lanes corresponding to each link
334  std::vector<std::string> intLanes;
335  // @brief the complete response definition for all links
336  std::vector<std::string> response;
337  };
338 
340  std::map<std::string, EdgeAttrs*> myEdges;
341 
343  std::vector<Prohibition> myProhibitions;
344 
347 
350 
353 
356 
359 
362 
365 
368 
371 
373  std::map<std::string, std::vector<Crossing> > myPedestrianCrossings;
374 
376  std::map<std::string, WalkingAreaParsedCustomShape> myWACustomShapes;
377 
379  std::vector<Parameterised*> myLastParameterised;
380 
383 
386 
389 
392 
395 
398 
401 
404 
407 
414  std::string myDefaultSpreadType;
421 
423  std::vector<std::vector<std::string> > myRoundabouts;
424 
426  std::set<std::string> myRailSignals;
427 
429  std::set<std::string> myDiscardableParams;
430 
431 private:
432 
434  static Position readPosition(const SUMOSAXAttributes& attrs, const std::string& id, bool& ok);
435 
442  void parseProhibitionConnection(const std::string& attr, std::string& from, std::string& to, bool& ok);
443 };
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 edgeType
optional edge type
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.
bool indirectLeft
Whether this connection is an indirect left turn.
double visibility
custom foe visibility for connection
bool mayDefinitelyPass
Information about being definitely free to drive (on-ramps)
SVCPermissions changeLeft
custom lane changing permissions for connection
SVCPermissions changeRight
custom lane changing permissions for connection
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.
StopOffset edgeStopOffset
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.
std::string changeRight
This lane's vehicle classes allowed to change right.
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.
StopOffset laneStopOffset
This lane's vehicle specific stop offsets.
PositionVector shape
This lane's shape (may be custom)
std::string changeLeft
This lane's vehicle classes allowed to change left.
double width
The width of this lane.
std::string disallow
This lane's disallowed vehicle classes.
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;.
double myInternalJunctionsVehicleWidth
custom settings for internal junction computation
std::string myDefaultSpreadType
default spreadType defined in the network
bool myJunctionsHigherSpeed
higherSpeed option for loaded 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
bool myChangeLefthand
whether the the written network should have a different "handedness" (LHT/RHT) than the loaded networ...
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:41
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
A list of positions.
Encapsulated SAX-Attributes.
SAX-handler base for SUMO-files.
stop offset
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.