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.sourceforge.net/
12 // Copyright (C) 2001-2012 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 "NBCont.h"
40 #include <utils/common/Named.h>
43 #include <utils/geom/Bresenham.h>
45 #include <utils/geom/Line.h>
48 #include "NBHelpers.h"
49 
50 
51 // ===========================================================================
52 // class declarations
53 // ===========================================================================
54 class NBNode;
55 class NBConnection;
56 class NBNodeCont;
57 class NBEdgeCont;
58 class OutputDevice;
59 class GNELane;
60 
61 
62 // ===========================================================================
63 // class definitions
64 // ===========================================================================
69 class NBEdge : public Named {
71  friend class NBEdgeSuccessorBuilder;
72  friend class NBEdgeCont;
73 
75  friend class GNELane;
76  friend class GNEEdge;
77 
78 public:
79 
102  };
103 
104 
115  };
116 
117 
121  struct Lane {
122  Lane(NBEdge* e) :
124  offset(e->getOffset()), width(e->getWidth()) {}
137  };
138 
139 
143  struct Connection {
149  Connection(int fromLane_, NBEdge* toEdge_, int toLane_)
150  : fromLane(fromLane_), toEdge(toEdge_), toLane(toLane_),
151  mayDefinitelyPass(false), haveVia(false) { }
152 
154 
155 
157  int fromLane;
161  int toLane;
163  std::string tlID;
165  unsigned int tlLinkNo;
168 
169 
170  std::string id;
173 
174  bool haveVia;
175  std::string viaID;
178 
179  std::string foeInternalLanes;
180  std::string foeIncomingLanes;
181 
182  };
183 
185  static std::pair<SUMOReal, SUMOReal> laneOffset(const Position& from,
186  const Position& to, SUMOReal lanewidth, unsigned int lane,
187  size_t noLanes, LaneSpreadFunction lsf, bool leftHand);
188 
195 
196 
197 public:
216  NBEdge(const std::string& id,
217  NBNode* from, NBNode* to, std::string type,
218  SUMOReal speed, unsigned int nolanes, int priority,
219  SUMOReal width, SUMOReal offset,
220  const std::string& streetName = "",
222 
223 
244  NBEdge(const std::string& id,
245  NBNode* from, NBNode* to, std::string type,
246  SUMOReal speed, unsigned int nolanes, int priority,
247  SUMOReal width, SUMOReal offset,
248  PositionVector geom,
249  const std::string& streetName = "",
251  bool tryIgnoreNodePositions = false) ;
252 
262  NBEdge(const std::string& id,
263  NBNode* from, NBNode* to,
264  NBEdge* tpl);
265 
266 
269  ~NBEdge() ;
270 
271 
287  void reinit(NBNode* from, NBNode* to, const std::string& type,
288  SUMOReal speed, unsigned int nolanes, int priority,
289  PositionVector geom, SUMOReal width, SUMOReal offset,
290  const std::string& streetName,
292  bool tryIgnoreNodePositions = false) ;
293 
294 
295 
298 
303  void reshiftPosition(SUMOReal xoff, SUMOReal yoff) ;
305 
306 
307 
310  void setLeftHanded() {
311  myAmLeftHand = true;
312  }
313 
314 
316 
317 
321  unsigned int getNumLanes() const {
322  return (unsigned int) myLanes.size();
323  }
324 
325 
329  int getPriority() const {
330  return myPriority;
331  }
332 
333 
337  NBNode* getFromNode() const {
338  return myFrom;
339  }
340 
341 
345  NBNode* getToNode() const {
346  return myTo;
347  }
348 
349 
357  SUMOReal getAngle() const {
358  return myAngle;
359  }
360 
361 
365  SUMOReal getLength() const {
366  return myLength;
367  }
368 
369 
375  return myLoadedLength > 0 ? myLoadedLength : myLength;
376  }
377 
378 
382  bool hasLoadedLength() const {
383  return myLoadedLength > 0;
384  }
385 
386 
390  SUMOReal getSpeed() const {
391  return mySpeed;
392  }
393 
394 
401  return myStep;
402  }
403 
404 
408  SUMOReal getWidth() const {
409  return myWidth;
410  }
411 
412 
415  const std::string& getStreetName() const {
416  return myStreetName;
417  }
418 
421  void setStreetName(const std::string& name) {
422  myStreetName = name;
423  }
424 
428  SUMOReal getOffset() const {
429  return myOffset;
430  }
431 
432 
436  const std::string& getTypeName() const {
437  return myType;
438  }
439 
440 
444  const std::vector<NBEdge::Lane> &getLanes() const {
445  return myLanes;
446  }
448 
449 
450 
452 
453 
457  const PositionVector& getGeometry() const {
458  return myGeom;
459  }
460 
461 
463  const PositionVector getInnerGeometry() const;
464 
465 
468  bool hasDefaultGeometry() const;
469 
470 
476  bool hasDefaultGeometryEndpoints() const;
477 
478 
489  void setGeometry(const PositionVector& g, bool inner = false) ;
490 
491 
501  void addGeometryPoint(int index, const Position& p) ;
502 
503 
513  void computeEdgeShape() ;
514 
515 
519  const PositionVector& getLaneShape(unsigned int i) const ;
520 
521 
527 
528 
534  return myLaneSpreadFunction;
535  }
536 
537 
543  bool splitGeometry(NBEdgeCont& ec, NBNodeCont& nc);
545 
546 
547 
550 
565  bool addEdge2EdgeConnection(NBEdge* dest);
566 
567 
588  bool addLane2LaneConnection(unsigned int fromLane, NBEdge* dest,
589  unsigned int toLane, Lane2LaneInfoType type,
590  bool mayUseSameDestination = false,
591  bool mayDefinitelyPass = false);
592 
593 
611  bool addLane2LaneConnections(unsigned int fromLane,
612  NBEdge* dest, unsigned int toLane, unsigned int no,
613  Lane2LaneInfoType type, bool invalidatePrevious = false,
614  bool mayDefinitelyPass = false);
615 
616 
627  void setConnection(unsigned int lane, NBEdge* destEdge,
628  unsigned int destLane,
629  Lane2LaneInfoType type,
630  bool mayUseSameDestination = false,
631  bool mayDefinitelyPass = false);
632 
633 
634 
643  std::vector<Connection> getConnectionsFromLane(unsigned int lane) const;
644 
645 
653  bool hasConnectionTo(NBEdge* destEdge, unsigned int destLane) const;
654 
655 
662  bool isConnectedTo(NBEdge* e);
663 
664 
668  const std::vector<Connection> &getConnections() const {
669  return myConnections;
670  }
671 
672 
676  std::vector<Connection> &getConnections() {
677  return myConnections;
678  }
679 
680 
685 
686 
691 
692 
696  std::vector<int> getConnectionLanes(NBEdge* currentOutgoing) const;
697 
698 
702 
703 
707 
708 
714  void remapConnections(const EdgeVector& incoming);
715 
716 
722  void removeFromConnections(NBEdge* toEdge, int fromLane = -1, int toLane = -1);
723 
724  void invalidateConnections(bool reallowSetting = false);
725 
726  void replaceInConnections(NBEdge* which, NBEdge* by, unsigned int laneOff);
727  void replaceInConnections(NBEdge* which, const std::vector<NBEdge::Connection> &origConns);
728  void copyConnectionsFrom(NBEdge* src);
730 
731 
732 
738  bool isTurningDirectionAt(const NBNode* n, const NBEdge* const edge) const ;
739  void setTurningDestination(NBEdge* e);
740 
741 
742 
745 
750  }
751 
752 
756  bool isMacroscopicConnector() const {
758  }
759 
760 
763  void setIsInnerEdge() {
764  myAmInnerEdge = true;
765  }
766 
767 
771  bool isInnerEdge() const {
772  return myAmInnerEdge;
773  }
775 
776 
777 
778 
784  void setJunctionPriority(const NBNode* const node, int prio);
785 
786 
796  int getJunctionPriority(const NBNode* const node) const;
797 
798  void setLoadedLength(SUMOReal val);
800 
801 
802  const std::string& getTypeID() const {
803  return myType;
804  }
805 
807  bool needsLaneSpecificOutput() const;
808 
810  bool hasRestrictions() const;
811 
813  bool hasLaneSpecificPermissions() const;
814 
816  bool hasLaneSpecificSpeed() const;
817 
819  bool hasLaneSpecificOffset() const;
820 
822  bool hasLaneSpecificWidth() const;
823 
825  bool computeEdge2Edges(bool noLeftMovers);
826 
828  bool computeLanes2Edges();
829 
832  bool recheckLanes();
833 
842  void appendTurnaround(bool noTLSControlled) ;
843 
844 
845 
849  NBNode* tryGetNodeAtPosition(SUMOReal pos, SUMOReal tolerance = 5.0) const;
850 
851 
853 
856 
857 
858  bool lanesWereAssigned() const;
859 
860  bool mayBeTLSControlled(int fromLane, NBEdge* toEdge, int toLane) const ;
861 
863  bool setControllingTLInformation(const NBConnection& c, const std::string& tlID);
864 
867 
869  PositionVector& into);
870 
871  SUMOReal width() const;
872 
873  PositionVector getCWBoundaryLine(const NBNode& n, SUMOReal offset) const;
874  PositionVector getCCWBoundaryLine(const NBNode& n, SUMOReal offset) const;
875 
876  bool expandableBy(NBEdge* possContinuation) const;
877  void append(NBEdge* continuation);
878 
879  bool hasSignalisedConnectionTo(const NBEdge* const e) const ;
880 
881 
882  void moveOutgoingConnectionsFrom(NBEdge* e, unsigned int laneOff);
883 
884  NBEdge* getTurnDestination() const;
885 
886  std::string getLaneID(unsigned int lane) const;
887 
888  SUMOReal getLaneSpeed(unsigned int lane) const;
889 
890  bool isNearEnough2BeJoined2(NBEdge* e, SUMOReal threshold) const;
891 
892 
900  SUMOReal getAngleAtNode(const NBNode * const node) const;
901 
902 
903  void incLaneNo(unsigned int by);
904 
905  void decLaneNo(unsigned int by, int dir = 0);
906 
907  void markAsInLane2LaneState();
908 
910  void setPermissions(SVCPermissions permissions, int lane = -1);
911 
912  void setPreferredVehicleClass(SVCPermissions permissions, int lane = -1);
913 
915  void allowVehicleClass(int lane, SUMOVehicleClass vclass);
917  void disallowVehicleClass(int lane, SUMOVehicleClass vclass);
918 
919  void preferVehicleClass(int lane, SUMOVehicleClass vclass);
920 
921 
922 
924  void setWidth(int lane, SUMOReal width);
925 
927  void setOffset(int lane, SUMOReal offset);
928 
930  void setSpeed(int lane, SUMOReal offset);
931 
933  SVCPermissions getPermissions(int lane = -1) const;
934 
935  void disableConnection4TLS(int fromLane, NBEdge* toEdge, int toLane);
936 
937 
938  // returns a reference to the internal structure for the convenience of NETEDIT
939  Lane& getLaneStruct(unsigned int lane) {
940  return myLanes[lane];
941  }
942 
943  // returns a reference to the internal structure for the convenience of NETEDIT
944  const Lane& getLaneStruct(unsigned int lane) const {
945  return myLanes[lane];
946  }
947 
948  /* declares connections as fully loaded. This is needed to avoid recomputing connections
949  * if an edge has no connections intentionally. */
952  }
953 
954  void buildInnerEdges(const NBNode& n, unsigned int noInternalNoSplits, unsigned int& lno, unsigned int& splitNo);
955 
956 
957 private:
964  private:
966  std::map<NBEdge*, std::vector<unsigned int> > myConnections;
967 
970 
971  public:
973  ToEdgeConnectionsAdder(const EdgeVector& transitions)
974  : myTransitions(transitions) { }
975 
978 
980  void execute(const unsigned int lane, const unsigned int virtEdge) ;
981 
982  const std::map<NBEdge*, std::vector<unsigned int> > &getBuiltConnections() const {
983  return myConnections;
984  }
985 
986  private:
989 
992 
993  };
994 
995 
1004  public:
1007 
1010  std::vector<Direction> myDirs;
1011 
1012  public:
1014  MainDirections(const EdgeVector& outgoing,
1015  NBEdge* parent, NBNode* to);
1016 
1018  ~MainDirections();
1019 
1022  bool empty() const;
1023 
1026  bool includes(Direction d) const;
1027 
1028  private:
1031 
1034 
1035  };
1036 
1038  PositionVector computeLaneShape(unsigned int lane) throw(InvalidArgument);
1039 
1041  std::pair<SUMOReal, SUMOReal> laneOffset(const Position& from,
1042  const Position& to, SUMOReal lanewidth, unsigned int lane) throw(InvalidArgument);
1043 
1044  void computeLaneShapes() ;
1045 
1046 
1047 
1048 private:
1064  void init(unsigned int noLanes, bool tryIgnoreNodePositions) ;
1065 
1066 
1068  void divideOnEdges(const EdgeVector* outgoing);
1069 
1072  std::vector<unsigned int> *preparePriorities(
1073  const EdgeVector* outgoing);
1074 
1076  unsigned int computePrioritySum(std::vector<unsigned int> *priorities);
1077 
1078 
1081 
1084  void moveConnectionToLeft(unsigned int lane);
1085 
1088  void moveConnectionToRight(unsigned int lane);
1090 
1091 
1096  PositionVector startShapeAt(const PositionVector& laneShape, const NBNode* startNode, unsigned int laneIndex) const;
1097 
1098 
1099 private:
1104 
1106  std::string myType;
1107 
1110 
1113 
1116 
1119 
1122 
1126  std::vector<Connection> myConnections;
1127 
1130 
1133 
1136 
1139 
1142 
1145 
1148 
1152  std::vector<Lane> myLanes;
1153 
1156 
1159 
1160 
1163 
1166 
1170  int toLane;
1171  };
1172 
1173  std::vector<TLSDisabledConnection> myTLSDisabledConnections;
1174 
1175 
1177  std::string myStreetName;
1178 
1179 
1180 public:
1185  public:
1188 
1189  bool operator()(const TLSDisabledConnection& e) const {
1190  if (e.to != myDefinition.to) {
1191  return false;
1192  }
1193  if (e.fromLane != myDefinition.fromLane) {
1194  return false;
1195  }
1196  if (e.toLane != myDefinition.toLane) {
1197  return false;
1198  }
1199  return true;
1200  }
1201 
1202  private:
1204 
1205  private:
1208 
1209  };
1210 
1211 
1212 
1217  public:
1219  connections_toedge_finder(NBEdge* const edge2find) : myEdge2Find(edge2find) { }
1220 
1221  bool operator()(const Connection& c) const {
1222  return c.toEdge == myEdge2Find;
1223  }
1224 
1225  private:
1227 
1228  private:
1231 
1232  };
1233 
1238  public:
1240  connections_toedgelane_finder(NBEdge* const edge2find, int lane2find) : myEdge2Find(edge2find), myLane2Find(lane2find) { }
1241 
1242  bool operator()(const Connection& c) const {
1243  return c.toEdge == myEdge2Find && c.toLane == myLane2Find;
1244  }
1245 
1246  private:
1249 
1250  private:
1253 
1254  };
1255 
1256 
1261  public:
1263  connections_finder(int fromLane, NBEdge* const edge2find, int lane2find) : myFromLane(fromLane), myEdge2Find(edge2find), myLane2Find(lane2find) { }
1264 
1265  bool operator()(const Connection& c) const {
1266  return c.fromLane == myFromLane && c.toEdge == myEdge2Find && c.toLane == myLane2Find;
1267  }
1268 
1269  private:
1273 
1274  private:
1277 
1278  };
1279 
1284  public:
1286  connections_fromlane_finder(int lane2find) : myLane2Find(lane2find) { }
1287 
1288  bool operator()(const Connection& c) const {
1289  return c.fromLane == myLane2Find;
1290  }
1291 
1292  private:
1294 
1295  private:
1298 
1299  };
1300 
1304  static bool connections_sorter(const Connection& c1, const Connection& c2) {
1305  if (c1.fromLane != c2.fromLane) {
1306  return c1.fromLane < c2.fromLane;
1307  }
1308  if (c1.toEdge != c2.toEdge) {
1309  return c1.toEdge->getID().compare(c1.toEdge->getID()) < 0;
1310  }
1311  return c1.toLane < c2.toLane;
1312  }
1313 
1319  public:
1322  : myEdge(e), myNode(n) {}
1323 
1324  public:
1326  int operator()(const Connection& c1, const Connection& c2) const {
1327  if (c1.toEdge != c2.toEdge) {
1328  SUMOReal relAngle1 = NBHelpers::normRelAngle(
1329  myEdge->getAngle(), c1.toEdge->getAngle());
1330  SUMOReal relAngle2 = NBHelpers::normRelAngle(
1331  myEdge->getAngle(), c2.toEdge->getAngle());
1332  return relAngle1 > relAngle2;
1333  }
1334  return c1.toLane < c2.toLane;
1335  }
1336 
1337  private:
1340 
1343 
1344  };
1345 
1346 private:
1348  NBEdge(const NBEdge& s);
1349 
1351  NBEdge& operator=(const NBEdge& s);
1352 
1353 
1354 };
1355 
1356 
1357 #endif
1358 
1359 /****************************************************************************/
1360