SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NBNode.h
Go to the documentation of this file.
1 /****************************************************************************/
10 // The representation of a single node
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
13 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 #ifndef NBNode_h
24 #define NBNode_h
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include <vector>
37 #include <deque>
38 #include <utility>
39 #include <string>
40 #include <set>
41 #include <utils/common/Named.h>
42 #include <utils/geom/Bresenham.h>
44 #include <utils/geom/Position.h>
45 #include <utils/geom/Line.h>
48 #include "NBEdge.h"
49 #include "NBConnection.h"
50 #include "NBConnectionDefs.h"
51 #include "NBContHelper.h"
52 
53 
54 // ===========================================================================
55 // class declarations
56 // ===========================================================================
57 class NBRequest;
58 class NBDistrict;
59 class OptionsCont;
61 class NBTypeCont;
63 class NBDistrictCont;
64 class OutputDevice;
65 
66 
67 // ===========================================================================
68 // class definitions
69 // ===========================================================================
74 class NBNode : public Named {
75  friend class NBNodeCont;
76  friend class GNEJunction; // < used for visualization (NETEDIT)
77  friend class NBNodesEdgesSorter; // < sorts the edges
78  friend class NBNodeTypeComputer; // < computes type
79  friend class NBEdgePriorityComputer; // < computes priorities of edges per intersection
80 
81 public:
94  private:
97 
100 
101  public:
106  ApproachingDivider(EdgeVector* approaching,
107  NBEdge* currentOutgoing);
108 
111 
113  void execute(const unsigned int src, const unsigned int dest);
114 
117  std::deque<int>* spread(const std::vector<int>& approachingLanes, int dest) const;
118 
119  };
120 
121 public:
127  NBNode(const std::string& id, const Position& position, SumoXMLNodeType type);
128 
129 
135  NBNode(const std::string& id, const Position& position, NBDistrict* district = 0);
136 
137 
139  ~NBNode();
140 
141 
148  void reinit(const Position& position, SumoXMLNodeType type,
149  bool updateEdgeGeometries = false);
150 
151 
154 
158  const Position& getPosition() const {
159  return myPosition;
160  }
161 
162 
164  Position getCenter() const;
165 
166 
170  const EdgeVector& getIncomingEdges() const {
171  return myIncomingEdges;
172  }
173 
174 
178  const EdgeVector& getOutgoingEdges() const {
179  return myOutgoingEdges;
180  }
181 
182 
186  const EdgeVector& getEdges() const {
187  return myAllEdges;
188  }
189 
190 
196  return myType;
197  }
199 
200 
201 
204 
209 
212 
215  void removeTrafficLights();
216 
217 
221  bool isTLControlled() const {
222  return myTrafficLights.size() != 0;
223  }
224 
225 
229  bool isJoinedTLSControlled() const;
230 
231 
235  const std::set<NBTrafficLightDefinition*>& getControllingTLS() const {
236  return myTrafficLights;
237  }
238 
239 
243 
244 
245 
248 
260 
261 
262 
265 
270  void reshiftPosition(SUMOReal xoff, SUMOReal yoff);
272 
273 
274 
276  void addIncomingEdge(NBEdge* edge);
277 
279  void addOutgoingEdge(NBEdge* edge);
280 
281 
282 
283 
285  void computeLanes2Lanes();
286 
288  void computeLogic(const NBEdgeCont& ec, OptionsCont& oc);
289 
292  bool writeLogic(OutputDevice& into, const bool checkLaneFoes) const;
293 
296  Position getEmptyDir() const;
297 
298 
303  bool hasIncoming(const NBEdge* const e) const;
304 
305 
310  bool hasOutgoing(const NBEdge* const e) const;
311 
312 
313  NBEdge* getOppositeIncoming(NBEdge* e) const;
316 
317  void removeDoubleEdges();
318  NBEdge* getConnectionTo(NBNode* n) const;
319 
320 
321  void addSortedLinkFoes(const NBConnection& mayDrive,
322  const NBConnection& mustStop);
323 
324  NBEdge* getPossiblySplittedIncoming(const std::string& edgeid);
325  NBEdge* getPossiblySplittedOutgoing(const std::string& edgeid);
326 
329  void removeEdge(NBEdge* edge, bool removeFromConnections = true);
330 
340  bool isLeftMover(const NBEdge* const from, const NBEdge* const to) const;
341 
342 
349  bool mustBrake(const NBEdge* const from, const NBEdge* const to, int toLane) const;
350 
351 
360  bool forbids(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
361  const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo,
362  bool regardNonSignalisedLowerPriority) const;
363 
364 
372  bool foes(const NBEdge* const from1, const NBEdge* const to1,
373  const NBEdge* const from2, const NBEdge* const to2) const;
374 
375 
381  LinkDirection getDirection(const NBEdge* const incoming, const NBEdge* const outgoing) const;
382 
383  LinkState getLinkState(const NBEdge* incoming, NBEdge* outgoing,
384  int fromLane, bool mayDefinitelyPass, const std::string& tlID) const;
385 
390  void computeNodeShape(bool leftHand, SUMOReal mismatchThreshold);
391 
392 
393  const PositionVector& getShape() const;
394 
395  bool checkIsRemovable() const;
396 
397 
398  std::vector<std::pair<NBEdge*, NBEdge*> > getEdgesToJoin() const;
399 
400 
401  friend class NBNodeShapeComputer;
402 
403  bool isNearDistrict() const;
404  bool isDistrict() const;
405 
406  bool needsCont(NBEdge* fromE, NBEdge* toE, NBEdge* otherFromE, NBEdge* otherToE, const NBEdge::Connection& c) const;
407 
417  NBEdge* fromE, int fromL, NBEdge* toE, int toL, int numPoints = 5) const;
418 
419 
422  void replaceIncoming(NBEdge* which, NBEdge* by, unsigned int laneOff);
423 
426  void replaceIncoming(const EdgeVector& which, NBEdge* by);
427 
430  void replaceOutgoing(NBEdge* which, NBEdge* by, unsigned int laneOff);
431 
434  void replaceOutgoing(const EdgeVector& which, NBEdge* by);
435 
436  void buildInnerEdges();
437 
439  return myBlockedConnections;
440  }
441 
444  bool geometryLike() const;
445 
447  void setRoundabout();
448 
454  public:
456  explicit nodes_by_id_sorter() { }
457 
460  int operator()(NBNode* n1, NBNode* n2) const {
461  return n1->getID() < n2->getID();
462  }
463 
464  };
465 
466 private:
467  bool isSimpleContinuation() const;
468 
471 
474  EdgeVector* getEdgesThatApproach(NBEdge* currentOutgoing);
475 
476 
477 
478 
480  unsigned int whichLaneOff, unsigned int byLaneOff);
481 
482 
484  NBEdge* removed, const EdgeVector& incoming, const EdgeVector& outgoing);
485 
486 
487 private:
490 
493 
496 
499 
502 
505 
508 
511 
513 
514  std::set<NBTrafficLightDefinition*> myTrafficLights;
515 
516 private:
518  NBNode(const NBNode& s);
519 
521  NBNode& operator=(const NBNode& s);
522 
523 
524 };
525 
526 
527 #endif
528 
529 /****************************************************************************/
530 
void replaceIncoming(NBEdge *which, NBEdge *by, unsigned int laneOff)
Replaces occurences of the first edge within the list of incoming by the second Connections are remap...
Definition: NBNode.cpp:791
const EdgeVector & getIncomingEdges() const
Returns this node's incoming edges.
Definition: NBNode.h:170
Position getEmptyDir() const
Returns something like the most unused direction Should only be used to add source or sink nodes...
Definition: NBNode.cpp:997
A structure which describes a connection between edges or lanes.
Definition: NBEdge.h:148
void setRoundabout()
update the type of this node as a roundabout
Definition: NBNode.cpp:1431
Position getCenter() const
Returns a position that is guaranteed to lie within the node shape.
Definition: NBNode.cpp:1439
ApproachingDivider(EdgeVector *approaching, NBEdge *currentOutgoing)
Constructor.
Definition: NBNode.cpp:83
bool isDistrict() const
Definition: NBNode.cpp:1380
PositionVector myPoly
the (outer) shape of the junction
Definition: NBNode.h:510
NBEdge * getOppositeIncoming(NBEdge *e) const
Definition: NBNode.cpp:910
const NBConnectionProhibits & getProhibitions()
Definition: NBNode.h:438
void execute(const unsigned int src, const unsigned int dest)
Definition: NBNode.cpp:95
SumoXMLNodeType myType
The type of the junction.
Definition: NBNode.h:501
A container for traffic light definitions and built programs.
void reinit(const Position &position, SumoXMLNodeType type, bool updateEdgeGeometries=false)
Resets initial values.
Definition: NBNode.cpp:216
bool isTLControlled() const
Returns whether this node is controlled by any tls.
Definition: NBNode.h:221
~NBNode()
Destructor.
Definition: NBNode.cpp:210
PositionVector computeInternalLaneShape(NBEdge *fromE, int fromL, NBEdge *toE, int toL, int numPoints=5) const
Compute the shape for an internal lane.
Definition: NBNode.cpp:403
This class computes shapes of junctions.
void removeEdge(NBEdge *edge, bool removeFromConnections=true)
Removes edge from this node and optionally removes connections as well.
Definition: NBNode.cpp:971
void addIncomingEdge(NBEdge *edge)
adds an incoming edge
Definition: NBNode.cpp:354
The representation of a single edge during network building.
Definition: NBEdge.h:71
bool mustBrake(const NBEdge *const from, const NBEdge *const to, int toLane) const
Returns the information whether the described flow must let any other flow pass.
Definition: NBNode.cpp:1041
Used for sorting the cells by the begin time they describe.
Definition: NBNode.h:453
bool hasOutgoing(const NBEdge *const e) const
Returns whether the given edge starts at this node.
Definition: NBNode.cpp:904
A container for districts.
The base class for traffic light logic definitions.
bool isJoinedTLSControlled() const
Returns whether this node is controlled by a tls that spans over more than one node.
Definition: NBNode.cpp:275
void removeDoubleEdges()
Definition: NBNode.cpp:859
friend class GNEJunction
Definition: NBNode.h:76
bool checkIsRemovable() const
Definition: NBNode.cpp:1251
void removeTrafficLight(NBTrafficLightDefinition *tlDef)
Removes the given traffic light from this node.
Definition: NBNode.cpp:259
NBConnectionProhibits myBlockedConnections
Definition: NBNode.h:504
bool hasIncoming(const NBEdge *const e) const
Returns whether the given edge ends at this node.
Definition: NBNode.cpp:898
void addOutgoingEdge(NBEdge *edge)
adds an outgoing edge
Definition: NBNode.cpp:364
NBRequest * myRequest
Definition: NBNode.h:512
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)...
NBDistrict * myDistrict
The district the node is the centre of.
Definition: NBNode.h:507
A class representing a single district.
Definition: NBDistrict.h:72
const EdgeVector & getOutgoingEdges() const
Returns this node's outgoing edges.
Definition: NBNode.h:178
const std::string & getID() const
Returns the id.
Definition: Named.h:60
EdgeVector myAllEdges
Vector of incoming and outgoing edges.
Definition: NBNode.h:498
void computeLanes2Lanes()
computes the connections of lanes to edges
Definition: NBNode.cpp:631
void invalidateIncomingConnections()
Definition: NBNode.cpp:1025
void setPriorityJunctionPriorities()
sets the priorites in case of a priority junction
const Position & getPosition() const
Returns the position of this node.
Definition: NBNode.h:158
NBEdge * getPossiblySplittedIncoming(const std::string &edgeid)
Definition: NBNode.cpp:945
void computeNodeShape(bool leftHand, SUMOReal mismatchThreshold)
Compute the junction shape for this node.
Definition: NBNode.cpp:605
const std::set< NBTrafficLightDefinition * > & getControllingTLS() const
Returns the traffic lights that were assigned to this node.
Definition: NBNode.h:235
bool isSimpleContinuation() const
Definition: NBNode.cpp:374
int operator()(NBNode *n1, NBNode *n2) const
Comparing operator.
Definition: NBNode.h:460
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
bool needsCont(NBEdge *fromE, NBEdge *toE, NBEdge *otherFromE, NBEdge *otherToE, const NBEdge::Connection &c) const
Definition: NBNode.cpp:527
SumoXMLNodeType getType() const
Returns the type of this node.
Definition: NBNode.h:195
bool geometryLike() const
whether this is structurally similar to a geometry node
Definition: NBNode.cpp:1406
void invalidateOutgoingConnections()
Definition: NBNode.cpp:1033
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic, in MSLink and GNEInternalLane.
void removeTrafficLights()
Removes all references to traffic lights that control this tls.
Definition: NBNode.cpp:266
EdgeVector * getEdgesThatApproach(NBEdge *currentOutgoing)
Definition: NBNode.cpp:732
const EdgeVector & getEdges() const
Returns all edges which participate in this node.
Definition: NBNode.h:186
std::set< NBTrafficLightDefinition * > myTrafficLights
Definition: NBNode.h:514
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
const PositionVector & getShape() const
Definition: NBNode.cpp:1332
NBEdge * getConnectionTo(NBNode *n) const
Definition: NBNode.cpp:1338
EdgeVector myIncomingEdges
Vector of incoming edges.
Definition: NBNode.h:492
bool isLeftMover(const NBEdge *const from, const NBEdge *const to) const
Computes whether the given connection is a left mover across the junction.
Definition: NBNode.cpp:1065
Base class for objects which have an id.
Definition: Named.h:45
std::vector< std::pair< NBEdge *, NBEdge * > > getEdgesToJoin() const
Definition: NBNode.cpp:1308
NBEdge * getPossiblySplittedOutgoing(const std::string &edgeid)
Definition: NBNode.cpp:958
unsigned int removeSelfLoops(NBDistrictCont &dc, NBEdgeCont &ec, NBTrafficLightLogicCont &tc)
Removes edges which are both incoming and outgoing into this node.
Definition: NBNode.cpp:311
EdgeVector myOutgoingEdges
Vector of outgoing edges.
Definition: NBNode.h:495
NBEdge * myCurrentOutgoing
The approached current edge.
Definition: NBNode.h:99
nodes_by_id_sorter()
Constructor.
Definition: NBNode.h:456
void addTrafficLight(NBTrafficLightDefinition *tlDef)
Adds a traffic light to the list of traffic lights that control this node.
Definition: NBNode.cpp:250
bool isNearDistrict() const
Definition: NBNode.cpp:1349
Position myPosition
The position the node lies at.
Definition: NBNode.h:489
std::map< NBConnection, NBConnectionVector > NBConnectionProhibits
Definition of a container for connection block dependencies Includes a list of all connections which ...
void replaceOutgoing(NBEdge *which, NBEdge *by, unsigned int laneOff)
Replaces occurences of the first edge within the list of outgoing by the second Connections are remap...
Definition: NBNode.cpp:755
~ApproachingDivider()
Destructor.
Definition: NBNode.cpp:91
LinkState getLinkState(const NBEdge *incoming, NBEdge *outgoing, int fromLane, bool mayDefinitelyPass, const std::string &tlID) const
Definition: NBNode.cpp:1228
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
void replaceInConnectionProhibitions(NBEdge *which, NBEdge *by, unsigned int whichLaneOff, unsigned int byLaneOff)
Definition: NBNode.cpp:824
std::vector< NBEdge * > EdgeVector
Definition: NBCont.h:38
void buildInnerEdges()
Definition: NBNode.cpp:1386
NBNode & operator=(const NBNode &s)
invalidated assignment operator
EdgeVector * myApproaching
The list of edges that approach the current edge.
Definition: NBNode.h:96
A storage for options typed value containers)
Definition: OptionsCont.h:108
std::deque< int > * spread(const std::vector< int > &approachingLanes, int dest) const
Definition: NBNode.cpp:120
Represents a single node (junction) during network building.
Definition: NBNode.h:74
void addSortedLinkFoes(const NBConnection &mayDrive, const NBConnection &mustStop)
Definition: NBNode.cpp:928
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
#define SUMOReal
Definition: config.h:215
Computes lane-2-lane connections.
Definition: NBNode.h:93
bool writeLogic(OutputDevice &into, const bool checkLaneFoes) const
Definition: NBNode.cpp:595
void computeLogic(const NBEdgeCont &ec, OptionsCont &oc)
computes the node's type, logic and traffic light
Definition: NBNode.cpp:556
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:64
bool foes(const NBEdge *const from1, const NBEdge *const to1, const NBEdge *const from2, const NBEdge *const to2) const
Returns the information whether the given flows cross.
Definition: NBNode.cpp:1094
void invalidateTLS(NBTrafficLightLogicCont &tlCont)
causes the traffic light to be computed anew
Definition: NBNode.cpp:289
NBNode(const std::string &id, const Position &position, SumoXMLNodeType type)
Constructor.
Definition: NBNode.cpp:195
void reshiftPosition(SUMOReal xoff, SUMOReal yoff)
Applies an offset to the node.
Definition: NBNode.cpp:242
void remapRemoved(NBTrafficLightLogicCont &tc, NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing)
Definition: NBNode.cpp:1101
A storage for available types of edges.
Definition: NBTypeCont.h:56
bool forbids(const NBEdge *const possProhibitorFrom, const NBEdge *const possProhibitorTo, const NBEdge *const possProhibitedFrom, const NBEdge *const possProhibitedTo, bool regardNonSignalisedLowerPriority) const
Returns the information whether "prohibited" flow must let "prohibitor" flow pass.
Definition: NBNode.cpp:1084
LinkDirection getDirection(const NBEdge *const incoming, const NBEdge *const outgoing) const
Returns the representation of the described stream's direction.
Definition: NBNode.cpp:1182