Eclipse SUMO - Simulation of Urban MObility
NBEdgeCont.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 // Storage for edges, including some functionality operating on multiple edges
21 /****************************************************************************/
22 #pragma once
23 #include <config.h>
24 
25 #include <map>
26 #include <iostream>
27 #include <string>
28 #include <vector>
29 #include <set>
30 #include "NBCont.h"
35 
36 
37 // ===========================================================================
38 // class declarations
39 // ===========================================================================
40 class OptionsCont;
41 class OutputDevice;
42 class NBNodeCont;
43 class NBTypeCont;
44 class NBEdge;
45 class NBNode;
46 class NBDistrictCont;
48 class NBPTStopCont;
49 class NBPTLineCont;
50 
51 
52 // ===========================================================================
53 // class definitions
54 // ===========================================================================
59 class NBEdgeCont {
60 public:
65 
66 
68  ~NBEdgeCont();
69 
70 
79  void applyOptions(OptionsCont& oc);
80 
81 
83  void clear();
84 
85 
86 
87 
90 
104  bool insert(NBEdge* edge, bool ignorePrunning = false);
105 
106 
115  NBEdge* retrieve(const std::string& id, bool retrieveExtracted = false) const;
116 
117 
128  NBEdge* retrievePossiblySplit(const std::string& id, bool downstream) const;
129 
130 
143  NBEdge* retrievePossiblySplit(const std::string& id, const std::string& hint, bool incoming) const;
144 
145 
156  NBEdge* retrievePossiblySplit(const std::string& id, double pos) const;
157 
158 
165  void erase(NBDistrictCont& dc, NBEdge* edge);
166 
167 
177  void extract(NBDistrictCont& dc, NBEdge* edge, bool remember = false);
178 
179 
183  std::map<std::string, NBEdge*>::const_iterator begin() const {
184  return myEdges.begin();
185  }
186 
187 
191  std::map<std::string, NBEdge*>::const_iterator end() const {
192  return myEdges.end();
193  }
195 
196 
197 
200 
204  struct Split {
206  std::vector<int> lanes;
208  double pos = INVALID_DOUBLE;
212  NBNode* node = nullptr;
214  std::string idBefore;
216  std::string idAfter;
218  std::string nameID;
220  double offset = 0.;
222  int offsetFactor = 1;
223  };
224 
225  void processSplits(NBEdge* e, std::vector<Split> splits,
227 
228 
242  bool splitAt(NBDistrictCont& dc, NBEdge* edge, NBNode* node);
243 
244 
268  bool splitAt(NBDistrictCont& dc, NBEdge* edge, NBNode* node,
269  const std::string& firstEdgeName, const std::string& secondEdgeName,
270  int noLanesFirstEdge, int noLanesSecondEdge,
271  const double speed = -1., const int changedLeft = 0);
272 
273 
289  bool splitAt(NBDistrictCont& dc, NBEdge* edge, double edgepos, NBNode* node,
290  const std::string& firstEdgeName, const std::string& secondEdgeName,
291  int noLanesFirstEdge, int noLanesSecondEdge,
292  const double speed = -1., const int changedLeft = 0);
294 
295 
296 
299 
303  int size() const {
304  return (int) myEdges.size();
305  }
306 
307 
312  std::vector<std::string> getAllNames() const;
313 
314 
318  int getNoEdgeSplits() const {
319  return myEdgesSplit;
320  }
322 
323 
324 
327 
333 
334 
343  void splitGeometry(NBDistrictCont& dc, NBNodeCont& nc);
344 
345 
350  void reduceGeometries(const double minDist);
351 
352 
359  void checkGeometries(const double maxAngle, const double minRadius, bool fix, bool fixRailways, bool silent = false);
361 
362 
363 
366 
375 
376 
385  void computeEdge2Edges(bool noLeftMovers);
386 
387 
395  void computeLanes2Edges();
396 
397 
405  void recheckLanes();
406 
407 
419  void appendTurnarounds(bool noTLSControlled, bool noFringe, bool onlyDeadends, bool onlyTurnlane, bool noGeometryLike);
420 
421 
428  void appendTurnarounds(const std::set<std::string>& ids, bool noTLSControlled);
429 
432  void appendRailwayTurnarounds(const NBPTStopCont& sc);
433 
434 
443  void computeEdgeShapes(double smoothElevationThreshold = -1);
444 
445 
454  void computeLaneShapes();
455 
456 
459  void clearControllingTLInformation() const;
460 
461 
470  NBTrafficLightLogicCont& tlc, EdgeVector edges);
471 
472 
475  void guessOpposites();
476 
477 
482  void recheckLaneSpread();
483 
485 
487  NBEdge* getOppositeByID(const std::string& edgeID) const;
488 
490  NBEdge* getByID(const std::string& edgeID) const;
491 
496  int guessRoundabouts();
497 
498 
502  bool wasIgnored(std::string id) const {
503  return myIgnoredEdges.count(id) != 0;
504  }
505 
507  void ignore(std::string id) {
508  myIgnoredEdges.insert(id);
509  }
510 
513  bool wasRemoved(std::string id) const {
514  return myExtractedEdges.count(id) != 0;
515  }
516 
519  void rename(NBEdge* edge, const std::string& newID);
520 
521 
522 
525 
539  void addPostProcessConnection(const std::string& from, int fromLane, const std::string& to, int toLane, bool mayDefinitelyPass,
540  KeepClear keepClear, double contPos, double visibility,
541  double speed, double length,
542  const PositionVector& customShape,
543  bool uncontrolled,
544  bool warnOnly,
545  SVCPermissions permissions = SVC_UNSPECIFIED);
546 
547  bool hasPostProcessConnection(const std::string& from, const std::string& to = "");
548 
549 
554 
556  void generateStreetSigns();
557 
559  int guessSpecialLanes(SUMOVehicleClass svc, double width, double minSpeed, double maxSpeed, bool fromPermissions, const std::string& excludeOpt);
560 
561 
565  const std::set<EdgeSet> getRoundabouts() const;
566 
568  void addRoundabout(const EdgeSet& roundabout);
569 
571  void removeRoundabout(const NBNode* node);
572 
574  void markRoundabouts();
575 
577  void patchRoundabouts(NBEdge* orig, NBEdge* part1, NBEdge* part2, std::set<EdgeSet>& roundabouts);
578 
580  bool ignoreFilterMatch(NBEdge* edge);
581 
583  int remapIDs(bool numericaIDs, bool reservedIDs, const std::string& prefix, NBPTStopCont& sc);
584 
586  void checkOverlap(double threshold, double zThreshold) const;
587 
589  void checkGrade(double threshold) const;
590 
591 
598  EdgeVector getGeneratedFrom(const std::string& id) const;
599 
601  int joinLanes(SVCPermissions perms);
602 
604  int joinTramEdges(NBDistrictCont& dc, NBPTLineCont& lc, double maxDist);
605 
607  EdgeVector getAllEdges() const;
609 
611  bool checkConsistency(const NBNodeCont& nc);
612 
613 private:
615  static double formFactor(const EdgeVector& loopEdges);
616 
617 private:
620 
625  public:
633  PostProcessConnection(const std::string& from_, int fromLane_, const std::string& to_, int toLane_,
634  bool mayDefinitelyPass_, KeepClear keepClear_, double contPos_, double visibility_, double speed_,
635  double length_,
636  const PositionVector& customShape_,
637  bool uncontrolled_,
638  bool warnOnly_, SVCPermissions permissions_) :
639  from(from_), fromLane(fromLane_), to(to_), toLane(toLane_), mayDefinitelyPass(mayDefinitelyPass_), keepClear(keepClear_), contPos(contPos_),
640  visibility(visibility_),
641  speed(speed_),
642  customLength(length_),
643  customShape(customShape_),
644  uncontrolled(uncontrolled_),
645  permissions(permissions_),
646  warnOnly(warnOnly_)
647  {}
649  std::string from;
651  int fromLane;
653  std::string to;
655  int toLane;
661  double contPos;
663  double visibility;
665  double speed;
667  double customLength;
675  bool warnOnly;
676  };
677 
679  std::map<std::string, std::vector<PostProcessConnection> > myConnections;
680 
681 
683  typedef std::map<std::string, NBEdge*> EdgeCont;
684 
687 
690 
692  std::set<std::string> myIgnoredEdges;
693 
696 
699 
702 
705 
707  std::set<std::string> myEdges2Keep;
708 
710  std::set<std::string> myEdges2Remove;
711 
714 
717 
719  std::set<std::string> myTypes2Keep;
720 
722  std::set<std::string> myTypes2Remove;
723 
726 
730 
732  std::set<EdgeSet> myRoundabouts;
734  std::set<EdgeSet> myGuessedRoundabouts;
735 
739  class split_sorter {
740  public:
742  explicit split_sorter() { }
743 
745  int operator()(const Split& e1, const Split& e2) const {
746  return e1.pos < e2.pos;
747  }
748  };
749 
750 
751 private:
754 
757 
758 };
std::set< NBEdge * > EdgeSet
container for unique edges
Definition: NBCont.h:49
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:34
KeepClear
keepClear status of connections
Definition: NBCont.h:57
std::vector< NBRouterEdge * > RouterEdgeVector
Definition: NBCont.h:42
const SVCPermissions SVC_UNSPECIFIED
permissions not specified
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
const double INVALID_DOUBLE
Definition: StdDefs.h:62
A container for districts.
Sorts splits by their position (increasing)
Definition: NBEdgeCont.h:739
int operator()(const Split &e1, const Split &e2) const
Comparing operator.
Definition: NBEdgeCont.h:745
split_sorter()
Constructor.
Definition: NBEdgeCont.h:742
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:59
std::map< std::string, NBEdge * >::const_iterator begin() const
Returns the pointer to the begin of the stored edges.
Definition: NBEdgeCont.h:183
void patchRoundabouts(NBEdge *orig, NBEdge *part1, NBEdge *part2, std::set< EdgeSet > &roundabouts)
fix roundabout information after splitting an edge
Definition: NBEdgeCont.cpp:700
void computeEdgeShapes(double smoothElevationThreshold=-1)
Computes the shapes of all edges stored in the container.
Definition: NBEdgeCont.cpp:924
void removeUnwishedEdges(NBDistrictCont &dc)
Removes unwished edges (not in keep-edges)
Definition: NBEdgeCont.cpp:729
NBEdge * getByID(const std::string &edgeID) const
Returns the edge with id if it exists.
const std::set< EdgeSet > getRoundabouts() const
Returns the determined roundabouts.
void computeEdge2Edges(bool noLeftMovers)
Computes for each edge the approached edges.
Definition: NBEdgeCont.cpp:811
int guessRoundabouts()
Determines which edges belong to roundabouts and increases their priority.
bool myNeedGeoTransformedPruningBoundary
whether a geo transform has been applied to the pruning boundary
Definition: NBEdgeCont.h:728
int size() const
Returns the number of edges.
Definition: NBEdgeCont.h:303
~NBEdgeCont()
Destructor.
Definition: NBEdgeCont.cpp:72
void sortOutgoingLanesConnections()
Sorts all lanes of all edges within the container by their direction.
Definition: NBEdgeCont.cpp:803
NBEdgeCont(const NBEdgeCont &s)
invalidated copy constructor
int getNoEdgeSplits() const
Returns the number of edge splits.
Definition: NBEdgeCont.h:318
void addRoundabout(const EdgeSet &roundabout)
add user specified roundabout
std::set< EdgeSet > myRoundabouts
Edges marked as belonging to a roundabout by the user (each EdgeVector is a roundabout)
Definition: NBEdgeCont.h:732
void appendRailwayTurnarounds(const NBPTStopCont &sc)
Appends turnarounds to all bidiRail edges with stops.
Definition: NBEdgeCont.cpp:902
std::set< std::string > myEdges2Remove
Set of ids of edges which shall explicitly be removed.
Definition: NBEdgeCont.h:710
std::set< std::string > myIgnoredEdges
The ids of ignored edges.
Definition: NBEdgeCont.h:692
std::map< std::string, NBEdge * >::const_iterator end() const
Returns the pointer to the end of the stored edges.
Definition: NBEdgeCont.h:191
double myEdgesMinSpeed
The minimum speed an edge may have in order to be kept (default: -1)
Definition: NBEdgeCont.h:701
int myEdgesSplit
the number of splits of edges during the building
Definition: NBEdgeCont.h:695
void recheckPostProcessConnections()
Try to set any stored connections.
void checkGeometries(const double maxAngle, const double minRadius, bool fix, bool fixRailways, bool silent=false)
Definition: NBEdgeCont.cpp:781
void extract(NBDistrictCont &dc, NBEdge *edge, bool remember=false)
Removes the given edge from the container like erase but does not delete it.
Definition: NBEdgeCont.cpp:416
void processSplits(NBEdge *e, std::vector< Split > splits, NBNodeCont &nc, NBDistrictCont &dc, NBTrafficLightLogicCont &tlc)
Definition: NBEdgeCont.cpp:441
EdgeVector getAllEdges() const
return all edges
void erase(NBDistrictCont &dc, NBEdge *edge)
Removes the given edge from the container (deleting it)
Definition: NBEdgeCont.cpp:409
NBEdge * retrieve(const std::string &id, bool retrieveExtracted=false) const
Returns the edge that has the given id.
Definition: NBEdgeCont.cpp:275
std::set< std::string > myTypes2Keep
Set of edges types which shall be kept.
Definition: NBEdgeCont.h:719
void recheckLanes()
Rechecks whether all lanes have a successor for each of the stored edges.
Definition: NBEdgeCont.cpp:827
NBEdge * getOppositeByID(const std::string &edgeID) const
Returns the edge with negated id if it exists.
EdgeCont myExtractedEdges
The extracted nodes which are kept for reference.
Definition: NBEdgeCont.h:689
void reduceGeometries(const double minDist)
Definition: NBEdgeCont.cpp:773
void recheckLaneSpread()
Rechecks whether the lane spread is proper.
bool ignoreFilterMatch(NBEdge *edge)
Returns true if this edge matches one of the removal criteria.
Definition: NBEdgeCont.cpp:199
void removeRoundabout(const NBNode *node)
remove roundabout that contains the given node
void splitGeometry(NBDistrictCont &dc, NBNodeCont &nc)
Splits edges into multiple if they have a complex geometry.
Definition: NBEdgeCont.cpp:746
void computeLanes2Edges()
Computes for each edge which lanes approach the next edges.
Definition: NBEdgeCont.cpp:819
NBEdge * retrievePossiblySplit(const std::string &id, bool downstream) const
Tries to retrieve an edge, even if it is splitted.
Definition: NBEdgeCont.cpp:311
RouterEdgeVector getAllRouterEdges() const
void rename(NBEdge *edge, const std::string &newID)
Renames the edge. Throws exception if newID already exists.
Definition: NBEdgeCont.cpp:428
void ignore(std::string id)
mark the given edge id as ignored
Definition: NBEdgeCont.h:507
bool hasPostProcessConnection(const std::string &from, const std::string &to="")
EdgeCont myEdges
The instance of the dictionary (id->edge)
Definition: NBEdgeCont.h:686
std::set< std::string > myEdges2Keep
Set of ids of edges which shall explicitly be kept.
Definition: NBEdgeCont.h:707
NBTypeCont & myTypeCont
The network builder; used to obtain type information.
Definition: NBEdgeCont.h:619
bool wasIgnored(std::string id) const
Returns whether the edge with the id was ignored during parsing.
Definition: NBEdgeCont.h:502
void generateStreetSigns()
assigns street signs to edges based on toNode types
void clearControllingTLInformation() const
Clears information about controlling traffic lights for all connenections of all edges.
Definition: NBEdgeCont.cpp:795
std::set< EdgeSet > myGuessedRoundabouts
Edges marked as belonging to a roundabout after guessing.
Definition: NBEdgeCont.h:734
void clear()
Deletes all edges.
Definition: NBEdgeCont.cpp:163
void guessOpposites()
Sets opposite lane information for geometrically close edges.
void markRoundabouts()
mark edge priorities and prohibit turn-arounds for all roundabout edges
std::set< std::string > myTypes2Remove
Set of edges types which shall be removed.
Definition: NBEdgeCont.h:722
void applyOptions(OptionsCont &oc)
Initialises the storage by applying given options.
Definition: NBEdgeCont.cpp:78
PositionVector myPruningBoundary
Boundary within which an edge must be located in order to be kept.
Definition: NBEdgeCont.h:725
int joinLanes(SVCPermissions perms)
join adjacent lanes with the given permissions
void checkOverlap(double threshold, double zThreshold) const
check whether edges overlap
SVCPermissions myVehicleClasses2Remove
Set of vehicle types which need not be supported (edges which allow ONLY these are removed)
Definition: NBEdgeCont.h:716
bool wasRemoved(std::string id) const
Returns whether the edge with the id was deleted explicitly.
Definition: NBEdgeCont.h:513
EdgeVector getGeneratedFrom(const std::string &id) const
Returns the edges which have been built by splitting the edge of the given id.
void appendTurnarounds(bool noTLSControlled, bool noFringe, bool onlyDeadends, bool onlyTurnlane, bool noGeometryLike)
Appends turnarounds to all edges stored in the container.
Definition: NBEdgeCont.cpp:886
NBEdgeCont & operator=(const NBEdgeCont &s)
invalidated assignment operator
SVCPermissions myVehicleClasses2Keep
Set of vehicle types which must be allowed on edges in order to keep them.
Definition: NBEdgeCont.h:713
void computeLaneShapes()
Computes the shapes of all lanes of all edges stored in the container.
Definition: NBEdgeCont.cpp:948
void joinSameNodeConnectingEdges(NBDistrictCont &dc, NBTrafficLightLogicCont &tlc, EdgeVector edges)
Joins the given edges because they connect the same nodes.
Definition: NBEdgeCont.cpp:956
bool myRemoveEdgesAfterJoining
Whether edges shall be joined first, then removed.
Definition: NBEdgeCont.h:704
std::map< std::string, NBEdge * > EdgeCont
The type of the dictionary where an edge may be found by its id.
Definition: NBEdgeCont.h:683
void addPostProcessConnection(const std::string &from, int fromLane, const std::string &to, int toLane, bool mayDefinitelyPass, KeepClear keepClear, double contPos, double visibility, double speed, double length, const PositionVector &customShape, bool uncontrolled, bool warnOnly, SVCPermissions permissions=SVC_UNSPECIFIED)
Adds a connection which could not be set during loading.
std::map< std::string, std::vector< PostProcessConnection > > myConnections
The list of connections to recheck.
Definition: NBEdgeCont.h:679
bool insert(NBEdge *edge, bool ignorePrunning=false)
Adds an edge to the dictionary.
Definition: NBEdgeCont.cpp:178
NBEdgeCont(NBTypeCont &tc)
Constructor.
Definition: NBEdgeCont.cpp:63
int joinTramEdges(NBDistrictCont &dc, NBPTLineCont &lc, double maxDist)
join tram edges into adjacent lanes
int guessSpecialLanes(SUMOVehicleClass svc, double width, double minSpeed, double maxSpeed, bool fromPermissions, const std::string &excludeOpt)
add sidwalks to edges within the given limits or permissions and return the number of edges affected
int remapIDs(bool numericaIDs, bool reservedIDs, const std::string &prefix, NBPTStopCont &sc)
remap node IDs accoring to options –numerical-ids and –reserved-ids
bool checkConsistency(const NBNodeCont &nc)
ensure that all edges have valid nodes
static double formFactor(const EdgeVector &loopEdges)
compute the form factor for a loop of edges
bool splitAt(NBDistrictCont &dc, NBEdge *edge, NBNode *node)
Splits the edge at the position nearest to the given node.
Definition: NBEdgeCont.cpp:586
std::vector< std::string > getAllNames() const
Returns all ids of known edges.
Definition: NBEdgeCont.cpp:718
void checkGrade(double threshold) const
check whether edges are to steep
The representation of a single edge during network building.
Definition: NBEdge.h:91
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 storage for available edgeTypes of edges.
Definition: NBTypeCont.h:52
A storage for options typed value containers)
Definition: OptionsCont.h:89
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
A list of positions.
A structure representing a connection between two lanes.
Definition: NBEdgeCont.h:624
double customLength
custom length for connection
Definition: NBEdgeCont.h:667
bool warnOnly
whether a failure to set this connection is a warning or an error
Definition: NBEdgeCont.h:675
bool uncontrolled
whether this connection shall not be controlled by a traffic light
Definition: NBEdgeCont.h:671
double visibility
custom foe visiblity for connection
Definition: NBEdgeCont.h:663
int toLane
The number of the lane the connection ends at.
Definition: NBEdgeCont.h:655
PositionVector customShape
custom shape for connection
Definition: NBEdgeCont.h:669
KeepClear keepClear
Whether the connection may be passed without braking.
Definition: NBEdgeCont.h:659
double speed
custom speed for connection
Definition: NBEdgeCont.h:665
bool mayDefinitelyPass
Whether the connection may be passed without braking.
Definition: NBEdgeCont.h:657
double contPos
custom position for internal junction on this connection
Definition: NBEdgeCont.h:661
std::string from
The id of the edge the connection starts at.
Definition: NBEdgeCont.h:649
SVCPermissions permissions
custom permissions for connection
Definition: NBEdgeCont.h:673
std::string to
The id of the edge the connection ends at.
Definition: NBEdgeCont.h:653
PostProcessConnection(const std::string &from_, int fromLane_, const std::string &to_, int toLane_, bool mayDefinitelyPass_, KeepClear keepClear_, double contPos_, double visibility_, double speed_, double length_, const PositionVector &customShape_, bool uncontrolled_, bool warnOnly_, SVCPermissions permissions_)
Constructor.
Definition: NBEdgeCont.h:633
int fromLane
The number of the lane the connection starts at.
Definition: NBEdgeCont.h:651
A structure which describes changes of lane number or speed along the road.
Definition: NBEdgeCont.h:204
int offsetFactor
direction in which to apply the offset (used by netgenerate for lefthand networks)
Definition: NBEdgeCont.h:222
double speed
The speed after this change.
Definition: NBEdgeCont.h:210
double offset
lateral offset to edge geometry
Definition: NBEdgeCont.h:220
std::string nameID
the default node id
Definition: NBEdgeCont.h:218
std::string idBefore
The id for the edge before the split.
Definition: NBEdgeCont.h:214
double pos
The position of this change.
Definition: NBEdgeCont.h:208
std::vector< int > lanes
The lanes after this change.
Definition: NBEdgeCont.h:206
std::string idAfter
The id for the edge after the split.
Definition: NBEdgeCont.h:216
NBNode * node
The new node that is created for this split.
Definition: NBEdgeCont.h:212