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>
44 #include <utils/geom/Bresenham.h>
46 #include <utils/geom/Line.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->getWidth()) {}
140  std::string origID;
141  };
142 
143 
147  struct Connection {
153  Connection(int fromLane_, NBEdge* toEdge_, int toLane_)
154  : fromLane(fromLane_), toEdge(toEdge_), toLane(toLane_),
155  mayDefinitelyPass(false), haveVia(false) { }
156 
158 
159 
161  int fromLane;
165  int toLane;
167  std::string tlID;
169  unsigned int tlLinkNo;
172 
173 
174  std::string origID;
175 
176  std::string id;
179 
180  bool haveVia;
181  std::string viaID;
184 
185  std::string foeInternalLanes;
186  std::string foeIncomingLanes;
187 
188  };
189 
191  static std::pair<SUMOReal, SUMOReal> laneOffset(const Position& from,
192  const Position& to, SUMOReal lanewidth, unsigned int lane,
193  size_t noLanes, LaneSpreadFunction lsf, bool leftHand);
194 
201 
202 
203 public:
222  NBEdge(const std::string& id,
223  NBNode* from, NBNode* to, std::string type,
224  SUMOReal speed, unsigned int nolanes, int priority,
225  SUMOReal width, SUMOReal offset,
226  const std::string& streetName = "",
228 
229 
250  NBEdge(const std::string& id,
251  NBNode* from, NBNode* to, std::string type,
252  SUMOReal speed, unsigned int nolanes, int priority,
253  SUMOReal width, SUMOReal offset,
254  PositionVector geom,
255  const std::string& streetName = "",
257  bool tryIgnoreNodePositions = false);
258 
268  NBEdge(const std::string& id,
269  NBNode* from, NBNode* to,
270  NBEdge* tpl);
271 
272 
275  ~NBEdge();
276 
277 
293  void reinit(NBNode* from, NBNode* to, const std::string& type,
294  SUMOReal speed, unsigned int nolanes, int priority,
295  PositionVector geom, SUMOReal width, SUMOReal offset,
296  const std::string& streetName,
298  bool tryIgnoreNodePositions = false);
299 
304  void reinitNodes(NBNode* from, NBNode* to);
305 
306 
309 
314  void reshiftPosition(SUMOReal xoff, SUMOReal yoff);
316 
317 
318 
321  void setLeftHanded() {
322  myAmLeftHand = true;
323  }
324 
325 
327 
328 
332  unsigned int getNumLanes() const {
333  return (unsigned int) myLanes.size();
334  }
335 
336 
340  int getPriority() const {
341  return myPriority;
342  }
343 
344 
348  NBNode* getFromNode() const {
349  return myFrom;
350  }
351 
352 
356  NBNode* getToNode() const {
357  return myTo;
358  }
359 
360 
368  SUMOReal getAngle() const {
369  return myAngle;
370  }
371 
372 
376  SUMOReal getLength() const {
377  return myLength;
378  }
379 
380 
386  return myLoadedLength > 0 ? myLoadedLength : myLength;
387  }
388 
389 
393  bool hasLoadedLength() const {
394  return myLoadedLength > 0;
395  }
396 
397 
401  SUMOReal getSpeed() const {
402  return mySpeed;
403  }
404 
405 
412  return myStep;
413  }
414 
415 
419  SUMOReal getWidth() const {
420  return myWidth;
421  }
422 
423 
426  const std::string& getStreetName() const {
427  return myStreetName;
428  }
429 
432  void setStreetName(const std::string& name) {
433  myStreetName = name;
434  }
435 
439  SUMOReal getOffset() const {
440  return myOffset;
441  }
442 
443 
447  const std::string& getTypeName() const {
448  return myType;
449  }
450 
451 
455  const std::vector<NBEdge::Lane>& getLanes() const {
456  return myLanes;
457  }
459 
460 
461 
463 
464 
468  const PositionVector& getGeometry() const {
469  return myGeom;
470  }
471 
472 
474  const PositionVector getInnerGeometry() const;
475 
476 
479  bool hasDefaultGeometry() const;
480 
481 
487  bool hasDefaultGeometryEndpoints() const;
488 
489 
500  void setGeometry(const PositionVector& g, bool inner = false);
501 
502 
512  void addGeometryPoint(int index, const Position& p);
513 
514 
524  void computeEdgeShape();
525 
526 
530  const PositionVector& getLaneShape(unsigned int i) const;
531 
532 
538 
539 
545  return myLaneSpreadFunction;
546  }
547 
548 
554  bool splitGeometry(NBEdgeCont& ec, NBNodeCont& nc);
556 
557 
558 
561 
576  bool addEdge2EdgeConnection(NBEdge* dest);
577 
578 
599  bool addLane2LaneConnection(unsigned int fromLane, NBEdge* dest,
600  unsigned int toLane, Lane2LaneInfoType type,
601  bool mayUseSameDestination = false,
602  bool mayDefinitelyPass = false);
603 
604 
622  bool addLane2LaneConnections(unsigned int fromLane,
623  NBEdge* dest, unsigned int toLane, unsigned int no,
624  Lane2LaneInfoType type, bool invalidatePrevious = false,
625  bool mayDefinitelyPass = false);
626 
627 
638  void setConnection(unsigned int lane, NBEdge* destEdge,
639  unsigned int destLane,
640  Lane2LaneInfoType type,
641  bool mayUseSameDestination = false,
642  bool mayDefinitelyPass = false);
643 
644 
645 
654  std::vector<Connection> getConnectionsFromLane(unsigned int lane) const;
655 
656 
664  bool hasConnectionTo(NBEdge* destEdge, unsigned int destLane) const;
665 
666 
673  bool isConnectedTo(NBEdge* e);
674 
675 
679  const std::vector<Connection>& getConnections() const {
680  return myConnections;
681  }
682 
683 
687  std::vector<Connection>& getConnections() {
688  return myConnections;
689  }
690 
691 
696 
697 
702 
703 
707  std::vector<int> getConnectionLanes(NBEdge* currentOutgoing) const;
708 
709 
713 
714 
718 
719 
725  void remapConnections(const EdgeVector& incoming);
726 
727 
733  void removeFromConnections(NBEdge* toEdge, int fromLane = -1, int toLane = -1);
734 
735  void invalidateConnections(bool reallowSetting = false);
736 
737  void replaceInConnections(NBEdge* which, NBEdge* by, unsigned int laneOff);
738  void replaceInConnections(NBEdge* which, const std::vector<NBEdge::Connection>& origConns);
739  void copyConnectionsFrom(NBEdge* src);
741 
742 
743 
749  bool isTurningDirectionAt(const NBNode* n, const NBEdge* const edge) const;
750  void setTurningDestination(NBEdge* e);
751 
752 
753 
756 
761  }
762 
763 
767  bool isMacroscopicConnector() const {
769  }
770 
771 
774  void setIsInnerEdge() {
775  myAmInnerEdge = true;
776  }
777 
778 
782  bool isInnerEdge() const {
783  return myAmInnerEdge;
784  }
786 
787 
788 
789 
795  void setJunctionPriority(const NBNode* const node, int prio);
796 
797 
807  int getJunctionPriority(const NBNode* const node) const;
808 
809  void setLoadedLength(SUMOReal val);
811 
812 
813  const std::string& getTypeID() const {
814  return myType;
815  }
816 
818  bool needsLaneSpecificOutput() const;
819 
821  bool hasRestrictions() const;
822 
824  bool hasLaneSpecificPermissions() const;
825 
827  bool hasLaneSpecificSpeed() const;
828 
830  bool hasLaneSpecificOffset() const;
831 
833  bool hasLaneSpecificWidth() const;
834 
836  bool computeEdge2Edges(bool noLeftMovers);
837 
839  bool computeLanes2Edges();
840 
843  bool recheckLanes();
844 
853  void appendTurnaround(bool noTLSControlled);
854 
855 
856 
860  NBNode* tryGetNodeAtPosition(SUMOReal pos, SUMOReal tolerance = 5.0) const;
861 
862 
864 
867 
868 
869  bool lanesWereAssigned() const;
870 
871  bool mayBeTLSControlled(int fromLane, NBEdge* toEdge, int toLane) const;
872 
874  bool setControllingTLInformation(const NBConnection& c, const std::string& tlID);
875 
878 
880  PositionVector& into);
881 
882  SUMOReal width() const;
883 
884  PositionVector getCWBoundaryLine(const NBNode& n, SUMOReal offset) const;
885  PositionVector getCCWBoundaryLine(const NBNode& n, SUMOReal offset) const;
886 
887  bool expandableBy(NBEdge* possContinuation) const;
888  void append(NBEdge* continuation);
889 
890  bool hasSignalisedConnectionTo(const NBEdge* const e) const;
891 
892 
893  void moveOutgoingConnectionsFrom(NBEdge* e, unsigned int laneOff);
894 
895  NBEdge* getTurnDestination() const;
896 
897  std::string getLaneID(unsigned int lane) const;
898 
899  SUMOReal getLaneSpeed(unsigned int lane) const;
900 
901  bool isNearEnough2BeJoined2(NBEdge* e, SUMOReal threshold) const;
902 
903 
911  SUMOReal getAngleAtNode(const NBNode* const node) const;
912 
913 
914  void incLaneNo(unsigned int by);
915 
916  void decLaneNo(unsigned int by, int dir = 0);
917 
918  void markAsInLane2LaneState();
919 
921  void setPermissions(SVCPermissions permissions, int lane = -1);
922 
923  void setPreferredVehicleClass(SVCPermissions permissions, int lane = -1);
924 
926  void allowVehicleClass(int lane, SUMOVehicleClass vclass);
928  void disallowVehicleClass(int lane, SUMOVehicleClass vclass);
929 
930  void preferVehicleClass(int lane, SUMOVehicleClass vclass);
931 
932 
933 
935  void setWidth(int lane, SUMOReal width);
936 
938  void setOffset(int lane, SUMOReal offset);
939 
941  void setSpeed(int lane, SUMOReal offset);
942 
944  SVCPermissions getPermissions(int lane = -1) const;
945 
946  void disableConnection4TLS(int fromLane, NBEdge* toEdge, int toLane);
947 
948 
949  // returns a reference to the internal structure for the convenience of NETEDIT
950  Lane& getLaneStruct(unsigned int lane) {
951  return myLanes[lane];
952  }
953 
954  // returns a reference to the internal structure for the convenience of NETEDIT
955  const Lane& getLaneStruct(unsigned int lane) const {
956  return myLanes[lane];
957  }
958 
959  /* declares connections as fully loaded. This is needed to avoid recomputing connections
960  * if an edge has no connections intentionally. */
963  }
964 
965  void buildInnerEdges(const NBNode& n, unsigned int noInternalNoSplits, unsigned int& lno, unsigned int& splitNo);
966 
967  inline const std::vector<NBSign>& getSigns() const {
968  return mySigns;
969  }
970 
971  inline void addSign(NBSign sign) {
972  mySigns.push_back(sign);
973  }
974 
975 
976 private:
983  private:
985  std::map<NBEdge*, std::vector<unsigned int> > myConnections;
986 
989 
990  public:
992  ToEdgeConnectionsAdder(const EdgeVector& transitions)
993  : myTransitions(transitions) { }
994 
997 
999  void execute(const unsigned int lane, const unsigned int virtEdge);
1000 
1001  const std::map<NBEdge*, std::vector<unsigned int> >& getBuiltConnections() const {
1002  return myConnections;
1003  }
1004 
1005  private:
1008 
1011 
1012  };
1013 
1014 
1023  public:
1026 
1029  std::vector<Direction> myDirs;
1030 
1031  public:
1033  MainDirections(const EdgeVector& outgoing,
1034  NBEdge* parent, NBNode* to);
1035 
1037  ~MainDirections();
1038 
1041  bool empty() const;
1042 
1045  bool includes(Direction d) const;
1046 
1047  private:
1050 
1053 
1054  };
1055 
1057  PositionVector computeLaneShape(unsigned int lane) throw(InvalidArgument);
1058 
1060  std::pair<SUMOReal, SUMOReal> laneOffset(const Position& from,
1061  const Position& to, SUMOReal lanewidth, unsigned int lane) throw(InvalidArgument);
1062 
1063  void computeLaneShapes();
1064 
1065 
1066 
1067 private:
1083  void init(unsigned int noLanes, bool tryIgnoreNodePositions);
1084 
1085 
1087  void divideOnEdges(const EdgeVector* outgoing);
1088 
1091  std::vector<unsigned int>* preparePriorities(
1092  const EdgeVector* outgoing);
1093 
1095  unsigned int computePrioritySum(std::vector<unsigned int>* priorities);
1096 
1097 
1100 
1103  void moveConnectionToLeft(unsigned int lane);
1104 
1107  void moveConnectionToRight(unsigned int lane);
1109 
1110 
1115  PositionVector startShapeAt(const PositionVector& laneShape, const NBNode* startNode, unsigned int laneIndex) const;
1116 
1117 private:
1122 
1124  std::string myType;
1125 
1128 
1131 
1134 
1137 
1140 
1144  std::vector<Connection> myConnections;
1145 
1148 
1151 
1154 
1157 
1160 
1163 
1166 
1170  std::vector<Lane> myLanes;
1171 
1174 
1177 
1178 
1181 
1184 
1188  int toLane;
1189  };
1190 
1191  std::vector<TLSDisabledConnection> myTLSDisabledConnections;
1192 
1193 
1195  std::string myStreetName;
1196 
1197 
1199  std::vector<NBSign> mySigns;
1200 
1201 
1202 public:
1207  public:
1210 
1211  bool operator()(const TLSDisabledConnection& e) const {
1212  if (e.to != myDefinition.to) {
1213  return false;
1214  }
1215  if (e.fromLane != myDefinition.fromLane) {
1216  return false;
1217  }
1218  if (e.toLane != myDefinition.toLane) {
1219  return false;
1220  }
1221  return true;
1222  }
1223 
1224  private:
1226 
1227  private:
1230 
1231  };
1232 
1233 
1234 
1239  public:
1241  connections_toedge_finder(NBEdge* const edge2find) : myEdge2Find(edge2find) { }
1242 
1243  bool operator()(const Connection& c) const {
1244  return c.toEdge == myEdge2Find;
1245  }
1246 
1247  private:
1249 
1250  private:
1253 
1254  };
1255 
1260  public:
1262  connections_toedgelane_finder(NBEdge* const edge2find, int lane2find) : myEdge2Find(edge2find), myLane2Find(lane2find) { }
1263 
1264  bool operator()(const Connection& c) const {
1265  return c.toEdge == myEdge2Find && c.toLane == myLane2Find;
1266  }
1267 
1268  private:
1271 
1272  private:
1275 
1276  };
1277 
1278 
1283  public:
1285  connections_finder(int fromLane, NBEdge* const edge2find, int lane2find) : myFromLane(fromLane), myEdge2Find(edge2find), myLane2Find(lane2find) { }
1286 
1287  bool operator()(const Connection& c) const {
1288  return c.fromLane == myFromLane && c.toEdge == myEdge2Find && c.toLane == myLane2Find;
1289  }
1290 
1291  private:
1295 
1296  private:
1299 
1300  };
1301 
1306  public:
1308  connections_fromlane_finder(int lane2find) : myLane2Find(lane2find) { }
1309 
1310  bool operator()(const Connection& c) const {
1311  return c.fromLane == myLane2Find;
1312  }
1313 
1314  private:
1316 
1317  private:
1320 
1321  };
1322 
1326  static bool connections_sorter(const Connection& c1, const Connection& c2) {
1327  if (c1.fromLane != c2.fromLane) {
1328  return c1.fromLane < c2.fromLane;
1329  }
1330  if (c1.toEdge != c2.toEdge) {
1331  return c1.toEdge->getID().compare(c1.toEdge->getID()) < 0;
1332  }
1333  return c1.toLane < c2.toLane;
1334  }
1335 
1341  public:
1344  : myEdge(e), myNode(n) {}
1345 
1346  public:
1348  int operator()(const Connection& c1, const Connection& c2) const {
1349  if (c1.toEdge != c2.toEdge) {
1350  SUMOReal relAngle1 = NBHelpers::normRelAngle(
1351  myEdge->getAngle(), c1.toEdge->getAngle());
1352  SUMOReal relAngle2 = NBHelpers::normRelAngle(
1353  myEdge->getAngle(), c2.toEdge->getAngle());
1354  return relAngle1 > relAngle2;
1355  }
1356  return c1.toLane < c2.toLane;
1357  }
1358 
1359  private:
1362 
1365 
1366  };
1367 
1368 private:
1370  NBEdge(const NBEdge& s);
1371 
1373  NBEdge& operator=(const NBEdge& s);
1374 
1375 
1376 };
1377 
1378 
1379 #endif
1380 
1381 /****************************************************************************/
1382