SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NBEdge.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // The representation of a single edge during network building
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef NBEdge_h
23 #define NBEdge_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <map>
36 #include <vector>
37 #include <string>
38 #include <set>
39 #include <utils/common/Named.h>
43 #include <utils/geom/Bresenham.h>
45 #include <utils/geom/Line.h>
48 #include "NBCont.h"
49 #include "NBHelpers.h"
50 #include "NBSign.h"
51 
52 
53 // ===========================================================================
54 // class declarations
55 // ===========================================================================
56 class NBNode;
57 class NBConnection;
58 class NBNodeCont;
59 class NBEdgeCont;
60 class OutputDevice;
61 class GNELane;
62 
63 
64 // ===========================================================================
65 // class definitions
66 // ===========================================================================
71 class NBEdge : public Named, public Parameterised {
73  friend class NBEdgeSuccessorBuilder;
74  friend class NBEdgeCont;
75 
77  friend class GNELane;
78  friend class GNEEdge;
79 
80 public:
81 
104  };
105 
106 
117  };
118 
119 
123  struct Lane {
124  Lane(NBEdge* e) :
126  offset(e->getOffset()), width(e->getLaneWidth()) {}
140  std::string origID;
141 
142  };
143 
144 
148  struct Connection {
154  Connection(int fromLane_, NBEdge* toEdge_, int toLane_)
155  : fromLane(fromLane_), toEdge(toEdge_), toLane(toLane_),
156  mayDefinitelyPass(false), haveVia(false) { }
157 
159 
160 
162  int fromLane;
166  int toLane;
168  std::string tlID;
170  unsigned int tlLinkNo;
173 
174 
175  std::string origID;
176 
177  std::string id;
180 
181  bool haveVia;
182  std::string viaID;
185 
186  std::string foeInternalLanes;
187  std::string foeIncomingLanes;
188 
189  };
190 
192  static std::pair<SUMOReal, SUMOReal> laneOffset(const Position& from,
193  const Position& to, SUMOReal laneCenterOffset, bool leftHand);
194 
202  static const SUMOReal ANGLE_LOOKAHEAD;
203 
204 public:
223  NBEdge(const std::string& id,
224  NBNode* from, NBNode* to, std::string type,
225  SUMOReal speed, unsigned int nolanes, int priority,
226  SUMOReal width, SUMOReal offset,
227  const std::string& streetName = "",
229 
230 
251  NBEdge(const std::string& id,
252  NBNode* from, NBNode* to, std::string type,
253  SUMOReal speed, unsigned int nolanes, int priority,
254  SUMOReal width, SUMOReal offset,
255  PositionVector geom,
256  const std::string& streetName = "",
258  bool tryIgnoreNodePositions = false);
259 
269  NBEdge(const std::string& id,
270  NBNode* from, NBNode* to,
271  NBEdge* tpl);
272 
273 
276  ~NBEdge();
277 
278 
294  void reinit(NBNode* from, NBNode* to, const std::string& type,
295  SUMOReal speed, unsigned int nolanes, int priority,
296  PositionVector geom, SUMOReal width, SUMOReal offset,
297  const std::string& streetName,
299  bool tryIgnoreNodePositions = false);
300 
305  void reinitNodes(NBNode* from, NBNode* to);
306 
307 
310 
315  void reshiftPosition(SUMOReal xoff, SUMOReal yoff);
317 
318 
319 
322  void setLeftHanded() {
323  myAmLeftHand = true;
324  }
325 
326 
328 
329 
333  unsigned int getNumLanes() const {
334  return (unsigned int) myLanes.size();
335  }
336 
337 
341  int getPriority() const {
342  return myPriority;
343  }
344 
345 
349  NBNode* getFromNode() const {
350  return myFrom;
351  }
352 
353 
357  NBNode* getToNode() const {
358  return myTo;
359  }
360 
361 
366  inline SUMOReal getStartAngle() const {
367  return myStartAngle;
368  }
369 
370 
375  inline SUMOReal getEndAngle() const {
376  return myEndAngle;
377  }
378 
379 
381 
385  inline SUMOReal getTotalAngle() const {
386  return myTotalAngle;
387  }
388 
392  SUMOReal getLength() const {
393  return myLength;
394  }
395 
396 
402  return myLoadedLength > 0 ? myLoadedLength : myLength;
403  }
404 
405 
409  bool hasLoadedLength() const {
410  return myLoadedLength > 0;
411  }
412 
413 
417  SUMOReal getSpeed() const {
418  return mySpeed;
419  }
420 
421 
428  return myStep;
429  }
430 
431 
436  return myLaneWidth;
437  }
438 
442  SUMOReal getLaneWidth(int lane) const;
443 
444 
447  const std::string& getStreetName() const {
448  return myStreetName;
449  }
450 
453  void setStreetName(const std::string& name) {
454  myStreetName = name;
455  }
456 
460  SUMOReal getOffset() const {
461  return myOffset;
462  }
463 
467  SUMOReal getOffset(int lane) const;
468 
469 
473  const std::string& getTypeName() const {
474  return myType;
475  }
476 
477 
481  const std::vector<NBEdge::Lane>& getLanes() const {
482  return myLanes;
483  }
485 
486 
487 
489 
490 
494  const PositionVector& getGeometry() const {
495  return myGeom;
496  }
497 
498 
500  const PositionVector getInnerGeometry() const;
501 
502 
505  bool hasDefaultGeometry() const;
506 
507 
513  bool hasDefaultGeometryEndpoints() const;
514 
515 
526  void setGeometry(const PositionVector& g, bool inner = false);
527 
528 
538  void addGeometryPoint(int index, const Position& p);
539 
540 
550  void computeEdgeShape();
551 
552 
556  const PositionVector& getLaneShape(unsigned int i) const;
557 
558 
564 
565 
571  return myLaneSpreadFunction;
572  }
573 
574 
580  bool splitGeometry(NBEdgeCont& ec, NBNodeCont& nc);
581 
582 
586  void reduceGeometry(const SUMOReal minDist);
587 
588 
594  void checkGeometry(const SUMOReal maxAngle, const SUMOReal minRadius, bool fix);
596 
597 
598 
601 
616  bool addEdge2EdgeConnection(NBEdge* dest);
617 
618 
639  bool addLane2LaneConnection(unsigned int fromLane, NBEdge* dest,
640  unsigned int toLane, Lane2LaneInfoType type,
641  bool mayUseSameDestination = false,
642  bool mayDefinitelyPass = false);
643 
644 
662  bool addLane2LaneConnections(unsigned int fromLane,
663  NBEdge* dest, unsigned int toLane, unsigned int no,
664  Lane2LaneInfoType type, bool invalidatePrevious = false,
665  bool mayDefinitelyPass = false);
666 
667 
678  void setConnection(unsigned int lane, NBEdge* destEdge,
679  unsigned int destLane,
680  Lane2LaneInfoType type,
681  bool mayUseSameDestination = false,
682  bool mayDefinitelyPass = false);
683 
684 
685 
694  std::vector<Connection> getConnectionsFromLane(unsigned int lane) const;
695 
696 
704  bool hasConnectionTo(NBEdge* destEdge, unsigned int destLane) const;
705 
706 
713  bool isConnectedTo(NBEdge* e);
714 
715 
719  const std::vector<Connection>& getConnections() const {
720  return myConnections;
721  }
722 
723 
727  std::vector<Connection>& getConnections() {
728  return myConnections;
729  }
730 
731 
736 
737 
742 
743 
747  std::vector<int> getConnectionLanes(NBEdge* currentOutgoing) const;
748 
749 
753 
754 
758 
759 
765  void remapConnections(const EdgeVector& incoming);
766 
767 
774  void removeFromConnections(NBEdge* toEdge, int fromLane = -1, int toLane = -1, bool tryLater = false);
775 
776  void invalidateConnections(bool reallowSetting = false);
777 
778  void replaceInConnections(NBEdge* which, NBEdge* by, unsigned int laneOff);
779  void replaceInConnections(NBEdge* which, const std::vector<NBEdge::Connection>& origConns);
780  void copyConnectionsFrom(NBEdge* src);
782 
783 
784 
790  bool isTurningDirectionAt(const NBNode* n, const NBEdge* const edge) const;
791  void setTurningDestination(NBEdge* e);
792 
793 
794 
797 
802  }
803 
804 
808  bool isMacroscopicConnector() const {
810  }
811 
812 
815  void setIsInnerEdge() {
816  myAmInnerEdge = true;
817  }
818 
819 
823  bool isInnerEdge() const {
824  return myAmInnerEdge;
825  }
827 
828 
829 
830 
836  void setJunctionPriority(const NBNode* const node, int prio);
837 
838 
848  int getJunctionPriority(const NBNode* const node) const;
849 
850  void setLoadedLength(SUMOReal val);
852 
853 
854  const std::string& getTypeID() const {
855  return myType;
856  }
857 
859  bool needsLaneSpecificOutput() const;
860 
862  bool hasRestrictions() const;
863 
865  bool hasLaneSpecificPermissions() const;
866 
868  bool hasLaneSpecificSpeed() const;
869 
871  bool hasLaneSpecificOffset() const;
872 
874  bool hasLaneSpecificWidth() const;
875 
877  bool computeEdge2Edges(bool noLeftMovers);
878 
880  bool computeLanes2Edges();
881 
884  bool recheckLanes();
885 
894  void appendTurnaround(bool noTLSControlled);
895 
896 
897 
901  NBNode* tryGetNodeAtPosition(SUMOReal pos, SUMOReal tolerance = 5.0) const;
902 
903 
905 
906  bool lanesWereAssigned() const;
907 
908  bool mayBeTLSControlled(int fromLane, NBEdge* toEdge, int toLane) const;
909 
911  bool setControllingTLInformation(const NBConnection& c, const std::string& tlID);
912 
915 
917  PositionVector& into);
918 
919  SUMOReal width() const;
920 
921  PositionVector getCWBoundaryLine(const NBNode& n, SUMOReal offset) const;
922  PositionVector getCCWBoundaryLine(const NBNode& n, SUMOReal offset) const;
923 
924  bool expandableBy(NBEdge* possContinuation) const;
925  void append(NBEdge* continuation);
926 
927  bool hasSignalisedConnectionTo(const NBEdge* const e) const;
928 
929 
930  void moveOutgoingConnectionsFrom(NBEdge* e, unsigned int laneOff);
931 
932  NBEdge* getTurnDestination() const;
933 
934  std::string getLaneID(unsigned int lane) const;
935 
936  std::string getLaneIDInsecure(unsigned int lane) const;
937 
938  SUMOReal getLaneSpeed(unsigned int lane) const;
939 
940  bool isNearEnough2BeJoined2(NBEdge* e, SUMOReal threshold) const;
941 
942 
950  SUMOReal getAngleAtNode(const NBNode* const node) const;
951 
952 
953  void incLaneNo(unsigned int by);
954 
955  void decLaneNo(unsigned int by, int dir = 0);
956 
957  void markAsInLane2LaneState();
958 
960  void setPermissions(SVCPermissions permissions, int lane = -1);
961 
962  void setPreferredVehicleClass(SVCPermissions permissions, int lane = -1);
963 
965  void allowVehicleClass(int lane, SUMOVehicleClass vclass);
967  void disallowVehicleClass(int lane, SUMOVehicleClass vclass);
968 
969  void preferVehicleClass(int lane, SUMOVehicleClass vclass);
970 
971 
972 
974  void setLaneWidth(int lane, SUMOReal width);
975 
977  void setOffset(int lane, SUMOReal offset);
978 
980  void setSpeed(int lane, SUMOReal speed);
981 
983  SVCPermissions getPermissions(int lane = -1) const;
984 
985  void disableConnection4TLS(int fromLane, NBEdge* toEdge, int toLane);
986 
987 
988  // returns a reference to the internal structure for the convenience of NETEDIT
989  Lane& getLaneStruct(unsigned int lane) {
990  return myLanes[lane];
991  }
992 
993  // returns a reference to the internal structure for the convenience of NETEDIT
994  const Lane& getLaneStruct(unsigned int lane) const {
995  return myLanes[lane];
996  }
997 
998  /* declares connections as fully loaded. This is needed to avoid recomputing connections
999  * if an edge has no connections intentionally. */
1002  }
1003 
1004  void buildInnerEdges(const NBNode& n, unsigned int noInternalNoSplits, unsigned int& lno, unsigned int& splitNo);
1005 
1006  inline const std::vector<NBSign>& getSigns() const {
1007  return mySigns;
1008  }
1009 
1010  inline void addSign(NBSign sign) {
1011  mySigns.push_back(sign);
1012  }
1013 
1014 
1015 private:
1022  private:
1024  std::map<NBEdge*, std::vector<unsigned int> > myConnections;
1025 
1028 
1029  public:
1032  : myTransitions(transitions) { }
1033 
1036 
1038  void execute(const unsigned int lane, const unsigned int virtEdge);
1039 
1040  const std::map<NBEdge*, std::vector<unsigned int> >& getBuiltConnections() const {
1041  return myConnections;
1042  }
1043 
1044  private:
1047 
1050 
1051  };
1052 
1053 
1062  public:
1065 
1068  std::vector<Direction> myDirs;
1069 
1070  public:
1072  MainDirections(const EdgeVector& outgoing,
1073  NBEdge* parent, NBNode* to);
1074 
1076  ~MainDirections();
1077 
1080  bool empty() const;
1081 
1084  bool includes(Direction d) const;
1085 
1086  private:
1089 
1092 
1093  };
1094 
1096  PositionVector computeLaneShape(unsigned int lane, SUMOReal offset);
1097 
1099  //std::pair<SUMOReal, SUMOReal> laneOffset(const Position& from, const Position& to, SUMOReal laneCenterOffset);
1100 
1101  void computeLaneShapes();
1102 
1103 
1104 
1105 private:
1121  void init(unsigned int noLanes, bool tryIgnoreNodePositions);
1122 
1123 
1125  void divideOnEdges(const EdgeVector* outgoing);
1126 
1129  std::vector<unsigned int>* preparePriorities(
1130  const EdgeVector* outgoing);
1131 
1133  unsigned int computePrioritySum(std::vector<unsigned int>* priorities);
1134 
1135 
1138 
1141  void moveConnectionToLeft(unsigned int lane);
1142 
1145  void moveConnectionToRight(unsigned int lane);
1147 
1148 
1153  PositionVector startShapeAt(const PositionVector& laneShape, const NBNode* startNode) const;
1154 
1156  void computeAngle();
1157 
1158 private:
1163 
1165  std::string myType;
1166 
1169 
1172 
1177 
1180 
1183 
1187  std::vector<Connection> myConnections;
1188 
1191  std::vector<Connection> myConnectionsToDelete;
1192 
1195 
1198 
1201 
1204 
1207 
1210 
1213 
1217  std::vector<Lane> myLanes;
1218 
1221 
1224 
1225 
1228 
1231 
1235  int toLane;
1236  };
1237 
1238  std::vector<TLSDisabledConnection> myTLSDisabledConnections;
1239 
1240 
1242  std::string myStreetName;
1243 
1244 
1246  std::vector<NBSign> mySigns;
1247 
1248 
1249 public:
1254  public:
1257 
1258  bool operator()(const TLSDisabledConnection& e) const {
1259  if (e.to != myDefinition.to) {
1260  return false;
1261  }
1262  if (e.fromLane != myDefinition.fromLane) {
1263  return false;
1264  }
1265  if (e.toLane != myDefinition.toLane) {
1266  return false;
1267  }
1268  return true;
1269  }
1270 
1271  private:
1273 
1274  private:
1277 
1278  };
1279 
1280 
1281 
1286  public:
1288  connections_toedge_finder(NBEdge* const edge2find) : myEdge2Find(edge2find) { }
1289 
1290  bool operator()(const Connection& c) const {
1291  return c.toEdge == myEdge2Find;
1292  }
1293 
1294  private:
1296 
1297  private:
1300 
1301  };
1302 
1307  public:
1309  connections_toedgelane_finder(NBEdge* const edge2find, int lane2find) : myEdge2Find(edge2find), myLane2Find(lane2find) { }
1310 
1311  bool operator()(const Connection& c) const {
1312  return c.toEdge == myEdge2Find && c.toLane == myLane2Find;
1313  }
1314 
1315  private:
1318 
1319  private:
1322 
1323  };
1324 
1325 
1330  public:
1332  connections_finder(int fromLane, NBEdge* const edge2find, int lane2find) : myFromLane(fromLane), myEdge2Find(edge2find), myLane2Find(lane2find) { }
1333 
1334  bool operator()(const Connection& c) const {
1335  return c.fromLane == myFromLane && c.toEdge == myEdge2Find && c.toLane == myLane2Find;
1336  }
1337 
1338  private:
1342 
1343  private:
1346 
1347  };
1348 
1353  public:
1355  connections_fromlane_finder(int lane2find) : myLane2Find(lane2find) { }
1356 
1357  bool operator()(const Connection& c) const {
1358  return c.fromLane == myLane2Find;
1359  }
1360 
1361  private:
1363 
1364  private:
1367 
1368  };
1369 
1373  static bool connections_sorter(const Connection& c1, const Connection& c2) {
1374  if (c1.fromLane != c2.fromLane) {
1375  return c1.fromLane < c2.fromLane;
1376  }
1377  if (c1.toEdge != c2.toEdge) {
1378  return c1.toEdge->getID().compare(c1.toEdge->getID()) < 0;
1379  }
1380  return c1.toLane < c2.toLane;
1381  }
1382 
1388  public:
1391 
1392  public:
1394  int operator()(const Connection& c1, const Connection& c2) const;
1395 
1396  private:
1399  };
1400 
1401 private:
1403  NBEdge(const NBEdge& s);
1404 
1406  NBEdge& operator=(const NBEdge& s);
1407 
1408 
1409 };
1410 
1411 
1412 #endif
1413 
1414 /****************************************************************************/
1415