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.dev/sumo
3 // Copyright (C) 2001-2024 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, bool setLoaded = true);
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 friction;
206  double customLength;
214  std::string edgeType;
215  };
216 
217 
221  class LaneAttrs final : public Parameterised {
222  public:
224  double maxSpeed;
226  double friction;
230  std::vector<Connection> connections;
232  std::string allow;
234  std::string disallow;
236  std::string changeLeft;
238  std::string changeRight;
240  double width;
242  double endOffset;
246  bool accelRamp;
248  std::string oppositeID;
252  std::string type;
253  };
254 
255 
259  class EdgeAttrs final : public Parameterised {
260  public:
262  std::string id;
264  std::string streetName;
266  std::string type;
270  std::string fromNode;
272  std::string toNode;
276  double length;
278  int priority;
280  double maxSpeed;
282  //double friction;
284  std::vector<LaneAttrs*> lanes;
292  double distance;
294  std::string bidi;
295  };
296 
297 
301  struct Prohibition {
302  std::string prohibitorFrom;
303  std::string prohibitorTo;
304  std::string prohibitedFrom;
305  std::string prohibitedTo;
306  };
307 
311  struct Crossing : public Parameterised {
312  Crossing(const std::string& _edgeID) :
313  edgeID(_edgeID), customTLIndex(-1), customTLIndex2(-1) {}
314 
315  std::string edgeID;
316  std::vector<std::string> crossingEdges;
317  double width;
318  bool priority;
322  };
323 
329  std::vector<std::string> fromEdges;
330  std::vector<std::string> toEdges;
331  std::vector<std::string> fromCrossed;
332  std::vector<std::string> toCrossed;
333  double width;
334  };
335 
339  struct JunctionAttrs {
341  // @the list of internal lanes corresponding to each link
342  std::vector<std::string> intLanes;
343  // @brief the complete response definition for all links
344  std::vector<std::string> response;
345  };
346 
348  std::map<std::string, EdgeAttrs*> myEdges;
349 
351  std::vector<Prohibition> myProhibitions;
352 
355 
358 
361 
364 
367 
370 
373 
376 
379 
381  std::map<std::string, std::vector<Crossing> > myPedestrianCrossings;
382 
384  std::map<std::string, WalkingAreaParsedCustomShape> myWACustomShapes;
385 
387  std::vector<Parameterised*> myLastParameterised;
388 
391 
394 
397 
400 
403 
406 
409 
412 
415 
422  std::string myDefaultSpreadType;
432 
434  std::vector<std::vector<std::string> > myRoundabouts;
435 
437  std::set<std::string> myRailSignals;
438 
440  std::set<std::string> myDiscardableParams;
441 
442 private:
443 
445  static Position readPosition(const SUMOSAXAttributes& attrs, const std::string& id, bool& ok);
446 
453  void parseProhibitionConnection(const std::string& attr, std::string& from, std::string& to, bool& ok);
454 };
long long 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...
std::pair< int, double > MMVersion
(M)ajor/(M)inor version for written networks and default version for loading
Definition: StdDefs.h:67
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:92
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:57
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.
double friction
custom friction for connection
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.
std::string bidi
the bidi edge
LaneSpreadFunction lsf
The lane spread function.
std::vector< LaneAttrs * > lanes
The friction on this edge.
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.
double friction
The friction 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.
static GeoConvHelper * loadLocation(const SUMOSAXAttributes &attrs, bool setLoaded=true)
Parses network location description and registers it with GeoConveHelper::setLoaded.
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.
MMVersion 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
bool myJunctionsMinimalShape
custom settings for junction shape computation
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
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.