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/StdDefs.h>
42 #include <utils/common/Named.h>
43 #include <utils/geom/Bresenham.h>
45 #include <utils/geom/Position.h>
46 #include <utils/geom/Line.h>
49 #include "NBEdge.h"
50 #include "NBConnection.h"
51 #include "NBConnectionDefs.h"
52 #include "NBContHelper.h"
53 
54 
55 // ===========================================================================
56 // class declarations
57 // ===========================================================================
58 class NBRequest;
59 class NBDistrict;
60 class OptionsCont;
62 class NBTypeCont;
64 class NBDistrictCont;
65 class OutputDevice;
66 
67 
68 // ===========================================================================
69 // class definitions
70 // ===========================================================================
75 class NBNode : public Named {
76  friend class NBNodeCont;
77  friend class GNEJunction; // < used for visualization (NETEDIT)
78  friend class NBNodesEdgesSorter; // < sorts the edges
79  friend class NBNodeTypeComputer; // < computes type
80  friend class NBEdgePriorityComputer; // < computes priorities of edges per intersection
81 
82 public:
95  private:
98 
101 
103  std::vector<unsigned int> myAvailableLanes;
104 
105  public:
110  ApproachingDivider(EdgeVector* approaching,
111  NBEdge* currentOutgoing, const bool buildCrossingsAndWalkingAreas);
112 
115 
116  unsigned int numAvailableLanes() const {
117  return (unsigned int)myAvailableLanes.size();
118  }
119 
121  void execute(const unsigned int src, const unsigned int dest);
122 
125  std::deque<int>* spread(const std::vector<int>& approachingLanes, int dest) const;
126 
127  };
128 
132  struct Crossing {
133  Crossing(const NBNode* _node, const EdgeVector& _edges, SUMOReal _width, bool _priority) :
134  node(_node), edges(_edges), width(_width), priority(_priority), tlLinkNo(-1)
135  {}
137  const NBNode* node;
145  std::string id;
147  std::string prevWalkingArea;
149  std::string nextWalkingArea;
151  bool priority;
153  int tlLinkNo;
154  };
155 
156 
160  struct WalkingArea {
161  WalkingArea(const std::string& _id, SUMOReal _width) :
162  id(_id),
163  width(_width),
164  nextCrossing(""),
165  tlID("")
166  {}
168  std::string id;
176  std::string nextCrossing;
178  std::string tlID;
180  std::vector<std::string> nextSidewalks;
182  std::vector<std::string> prevSidewalks;
183  };
184 
186  static const int FORWARD;
187  static const int BACKWARD;
190 
191 
192 public:
194  static const int MAX_CONNECTIONS;
195 
201  NBNode(const std::string& id, const Position& position, SumoXMLNodeType type);
202 
203 
209  NBNode(const std::string& id, const Position& position, NBDistrict* district = 0);
210 
211 
213  ~NBNode();
214 
215 
222  void reinit(const Position& position, SumoXMLNodeType type,
223  bool updateEdgeGeometries = false);
224 
225 
228 
232  const Position& getPosition() const {
233  return myPosition;
234  }
235 
236 
238  Position getCenter() const;
239 
240 
244  const EdgeVector& getIncomingEdges() const {
245  return myIncomingEdges;
246  }
247 
248 
252  const EdgeVector& getOutgoingEdges() const {
253  return myOutgoingEdges;
254  }
255 
256 
260  const EdgeVector& getEdges() const {
261  return myAllEdges;
262  }
263 
264 
270  return myType;
271  }
273 
274 
275 
278 
283 
286 
289  void removeTrafficLights();
290 
291 
295  bool isTLControlled() const {
296  return myTrafficLights.size() != 0;
297  }
298 
299 
303  bool isJoinedTLSControlled() const;
304 
305 
309  const std::set<NBTrafficLightDefinition*>& getControllingTLS() const {
310  return myTrafficLights;
311  }
312 
313 
316 
318  void shiftTLConnectionLaneIndex(NBEdge* edge, int offset);
320 
321 
322 
325 
337 
338 
339 
342 
347  void reshiftPosition(SUMOReal xoff, SUMOReal yoff);
349 
350 
351 
353  void addIncomingEdge(NBEdge* edge);
354 
356  void addOutgoingEdge(NBEdge* edge);
357 
358 
359 
360 
362  void computeLanes2Lanes(const bool buildCrossingsAndWalkingAreas);
363 
365  void computeLogic(const NBEdgeCont& ec, OptionsCont& oc);
366 
369  bool writeLogic(OutputDevice& into, const bool checkLaneFoes) const;
370 
373  Position getEmptyDir() const;
374 
375 
380  bool hasIncoming(const NBEdge* const e) const;
381 
382 
387  bool hasOutgoing(const NBEdge* const e) const;
388 
389 
390  NBEdge* getOppositeIncoming(NBEdge* e) const;
393 
394  void removeDoubleEdges();
395  NBEdge* getConnectionTo(NBNode* n) const;
396 
397 
398  void addSortedLinkFoes(const NBConnection& mayDrive,
399  const NBConnection& mustStop);
400 
401  NBEdge* getPossiblySplittedIncoming(const std::string& edgeid);
402  NBEdge* getPossiblySplittedOutgoing(const std::string& edgeid);
403 
406  void removeEdge(NBEdge* edge, bool removeFromConnections = true);
407 
417  bool isLeftMover(const NBEdge* const from, const NBEdge* const to) const;
418 
419 
426  bool mustBrake(const NBEdge* const from, const NBEdge* const to, int toLane) const;
427 
434  bool mustBrakeForCrossing(const NBEdge* const from, const NBEdge* const to, const Crossing& crossing) const;
435 
444  bool forbids(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
445  const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo,
446  bool regardNonSignalisedLowerPriority) const;
447 
448 
456  bool foes(const NBEdge* const from1, const NBEdge* const to1,
457  const NBEdge* const from2, const NBEdge* const to2) const;
458 
459 
465  LinkDirection getDirection(const NBEdge* const incoming, const NBEdge* const outgoing) const;
466 
467  LinkState getLinkState(const NBEdge* incoming, NBEdge* outgoing,
468  int fromLane, bool mayDefinitelyPass, const std::string& tlID) const;
469 
474  void computeNodeShape(bool leftHand, SUMOReal mismatchThreshold);
475 
477  const PositionVector& getShape() const;
478 
480  void setCustomShape(const PositionVector& shape);
481 
483  bool hasCustomShape() {
484  return myHaveCustomPoly;
485  }
486 
487  bool checkIsRemovable() const;
488 
489 
490  std::vector<std::pair<NBEdge*, NBEdge*> > getEdgesToJoin() const;
491 
492 
493  friend class NBNodeShapeComputer;
494 
495  bool isNearDistrict() const;
496  bool isDistrict() const;
497 
498  bool needsCont(NBEdge* fromE, NBEdge* toE, NBEdge* otherFromE, NBEdge* otherToE, const NBEdge::Connection& c) const;
499 
509  NBEdge* fromE, int fromL, NBEdge* toE, int toL, int numPoints = 5) const;
510 
511 
514  void replaceIncoming(NBEdge* which, NBEdge* by, unsigned int laneOff);
515 
518  void replaceIncoming(const EdgeVector& which, NBEdge* by);
519 
522  void replaceOutgoing(NBEdge* which, NBEdge* by, unsigned int laneOff);
523 
526  void replaceOutgoing(const EdgeVector& which, NBEdge* by);
527 
529  int guessCrossings();
530 
531  /* @brief check whether a crossing should be build for the candiate edges and build 0 to n crossings
532  * @param[in] candidates The candidate vector of edges to be crossed
533  * @return The number of crossings built
534  * */
535  int checkCrossing(EdgeVector candidates);
536 
538  void buildInnerEdges(bool buildCrossingsAndWalkingAreas);
539 
540  /* @brief build pedestrian crossings
541  * @return The next index for creating internal lanes
542  * */
543  unsigned int buildCrossings();
544 
545  /* @brief build pedestrian walking areas and set connections from/to walkingAreas
546  * @param[in] index The starting index for naming the created internal lanes
547  * @param[in] tlIndex The starting traffic light index to assign to connections to controlled crossings
548  * */
549  void buildWalkingAreas();
550 
552  EdgeVector edgesBetween(const NBEdge* e1, const NBEdge* e2) const;
553 
555  bool crossingBetween(const NBEdge* e1, const NBEdge* e2) const;
556 
558  return myBlockedConnections;
559  }
560 
563  bool geometryLike() const;
564 
566  void setRoundabout();
567 
569  void addCrossing(EdgeVector edges, SUMOReal width, bool priority);
570 
572  inline const std::vector<Crossing>& getCrossings() const {
573  return myCrossings;
574  }
575 
577  inline const std::vector<WalkingArea>& getWalkingAreas() const {
578  return myWalkingAreas;
579  }
580 
582  const Crossing& getCrossing(const std::string& id) const;
583 
585  void setCrossingTLIndices(unsigned int startIndex);
586 
588  int numNormalConnections() const;
589 
595  public:
597  explicit nodes_by_id_sorter() { }
598 
601  int operator()(NBNode* n1, NBNode* n2) const {
602  return n1->getID() < n2->getID();
603  }
604 
605  };
606 
607 
612  public:
614  int operator()(NBEdge* e1, NBEdge* e2) const {
615  UNUSED_PARAMETER(e2);
616  return e1->getFromNode() == myNode;
617  }
618 
619  private:
622 
623  };
624 
625 private:
626  bool isSimpleContinuation() const;
627 
630 
633  EdgeVector* getEdgesThatApproach(NBEdge* currentOutgoing);
634 
635 
636 
637 
639  unsigned int whichLaneOff, unsigned int byLaneOff);
640 
641 
643  NBEdge* removed, const EdgeVector& incoming, const EdgeVector& outgoing);
644 
645 
646 private:
649 
652 
655 
658 
660  std::vector<Crossing> myCrossings;
661 
663  std::vector<WalkingArea> myWalkingAreas;
664 
667 
670 
673 
676 
679 
681 
682  std::set<NBTrafficLightDefinition*> myTrafficLights;
683 
684 private:
686  NBNode(const NBNode& s);
687 
689  NBNode& operator=(const NBNode& s);
690 
691 
692 };
693 
694 
695 #endif
696 
697 /****************************************************************************/
698