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-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 "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->getLaneWidth()) {}
140  std::string origID;
143  };
144 
145 
149  struct Connection {
155  Connection(int fromLane_, NBEdge* toEdge_, int toLane_)
156  : fromLane(fromLane_), toEdge(toEdge_), toLane(toLane_),
157  mayDefinitelyPass(false), haveVia(false) { }
158 
160 
161 
163  int fromLane;
167  int toLane;
169  std::string tlID;
171  unsigned int tlLinkNo;
174 
175 
176  std::string origID;
177 
178  std::string id;
181 
182  bool haveVia;
183  std::string viaID;
186 
187  std::string foeInternalLanes;
188  std::string foeIncomingLanes;
189 
190  };
191 
193  static std::pair<SUMOReal, SUMOReal> laneOffset(const Position& from,
194  const Position& to, SUMOReal laneCenterOffset, bool leftHand);
195 
202 
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 
369  SUMOReal getAngle() const {
370  return myAngle;
371  }
372 
373 
377  SUMOReal getLength() const {
378  return myLength;
379  }
380 
381 
387  return myLoadedLength > 0 ? myLoadedLength : myLength;
388  }
389 
390 
394  bool hasLoadedLength() const {
395  return myLoadedLength > 0;
396  }
397 
398 
402  SUMOReal getSpeed() const {
403  return mySpeed;
404  }
405 
406 
413  return myStep;
414  }
415 
416 
421  return myLaneWidth;
422  }
423 
424 
427  const std::string& getStreetName() const {
428  return myStreetName;
429  }
430 
433  void setStreetName(const std::string& name) {
434  myStreetName = name;
435  }
436 
440  SUMOReal getOffset() const {
441  return myOffset;
442  }
443 
444 
448  const std::string& getTypeName() const {
449  return myType;
450  }
451 
452 
456  const std::vector<NBEdge::Lane>& getLanes() const {
457  return myLanes;
458  }
460 
461 
462 
464 
465 
469  const PositionVector& getGeometry() const {
470  return myGeom;
471  }
472 
473 
475  const PositionVector getInnerGeometry() const;
476 
477 
480  bool hasDefaultGeometry() const;
481 
482 
488  bool hasDefaultGeometryEndpoints() const;
489 
490 
501  void setGeometry(const PositionVector& g, bool inner = false);
502 
503 
513  void addGeometryPoint(int index, const Position& p);
514 
515 
525  void computeEdgeShape();
526 
527 
531  const PositionVector& getLaneShape(unsigned int i) const;
532 
533 
539 
540 
546  return myLaneSpreadFunction;
547  }
548 
549 
555  bool splitGeometry(NBEdgeCont& ec, NBNodeCont& nc);
556 
557 
561  void reduceGeometry(const SUMOReal minDist);
563 
564 
565 
568 
583  bool addEdge2EdgeConnection(NBEdge* dest);
584 
585 
606  bool addLane2LaneConnection(unsigned int fromLane, NBEdge* dest,
607  unsigned int toLane, Lane2LaneInfoType type,
608  bool mayUseSameDestination = false,
609  bool mayDefinitelyPass = false);
610 
611 
629  bool addLane2LaneConnections(unsigned int fromLane,
630  NBEdge* dest, unsigned int toLane, unsigned int no,
631  Lane2LaneInfoType type, bool invalidatePrevious = false,
632  bool mayDefinitelyPass = false);
633 
634 
645  void setConnection(unsigned int lane, NBEdge* destEdge,
646  unsigned int destLane,
647  Lane2LaneInfoType type,
648  bool mayUseSameDestination = false,
649  bool mayDefinitelyPass = false);
650 
651 
652 
661  std::vector<Connection> getConnectionsFromLane(unsigned int lane) const;
662 
663 
671  bool hasConnectionTo(NBEdge* destEdge, unsigned int destLane) const;
672 
673 
680  bool isConnectedTo(NBEdge* e);
681 
682 
686  const std::vector<Connection>& getConnections() const {
687  return myConnections;
688  }
689 
690 
694  std::vector<Connection>& getConnections() {
695  return myConnections;
696  }
697 
698 
703 
704 
709 
710 
714  std::vector<int> getConnectionLanes(NBEdge* currentOutgoing) const;
715 
716 
720 
721 
725 
726 
732  void remapConnections(const EdgeVector& incoming);
733 
734 
741  void removeFromConnections(NBEdge* toEdge, int fromLane = -1, int toLane = -1, bool tryLater = false);
742 
743  void invalidateConnections(bool reallowSetting = false);
744 
745  void replaceInConnections(NBEdge* which, NBEdge* by, unsigned int laneOff);
746  void replaceInConnections(NBEdge* which, const std::vector<NBEdge::Connection>& origConns);
747  void copyConnectionsFrom(NBEdge* src);
749 
750 
751 
757  bool isTurningDirectionAt(const NBNode* n, const NBEdge* const edge) const;
758  void setTurningDestination(NBEdge* e);
759 
760 
761 
764 
769  }
770 
771 
775  bool isMacroscopicConnector() const {
777  }
778 
779 
782  void setIsInnerEdge() {
783  myAmInnerEdge = true;
784  }
785 
786 
790  bool isInnerEdge() const {
791  return myAmInnerEdge;
792  }
794 
795 
796 
797 
803  void setJunctionPriority(const NBNode* const node, int prio);
804 
805 
815  int getJunctionPriority(const NBNode* const node) const;
816 
817  void setLoadedLength(SUMOReal val);
819 
820 
821  const std::string& getTypeID() const {
822  return myType;
823  }
824 
826  bool needsLaneSpecificOutput() const;
827 
829  bool hasRestrictions() const;
830 
832  bool hasLaneSpecificPermissions() const;
833 
835  bool hasLaneSpecificSpeed() const;
836 
838  bool hasLaneSpecificOffset() const;
839 
841  bool hasLaneSpecificWidth() const;
842 
844  bool computeEdge2Edges(bool noLeftMovers);
845 
847  bool computeLanes2Edges();
848 
851  bool recheckLanes();
852 
861  void appendTurnaround(bool noTLSControlled);
862 
863 
864 
868  NBNode* tryGetNodeAtPosition(SUMOReal pos, SUMOReal tolerance = 5.0) const;
869 
870 
872 
873  bool lanesWereAssigned() const;
874 
875  bool mayBeTLSControlled(int fromLane, NBEdge* toEdge, int toLane) const;
876 
878  bool setControllingTLInformation(const NBConnection& c, const std::string& tlID);
879 
882 
884  PositionVector& into);
885 
886  SUMOReal width() const;
887 
888  PositionVector getCWBoundaryLine(const NBNode& n, SUMOReal offset) const;
889  PositionVector getCCWBoundaryLine(const NBNode& n, SUMOReal offset) const;
890 
891  bool expandableBy(NBEdge* possContinuation) const;
892  void append(NBEdge* continuation);
893 
894  bool hasSignalisedConnectionTo(const NBEdge* const e) const;
895 
896 
897  void moveOutgoingConnectionsFrom(NBEdge* e, unsigned int laneOff);
898 
899  NBEdge* getTurnDestination() const;
900 
901  std::string getLaneID(unsigned int lane) const;
902 
903  std::string getLaneIDInsecure(unsigned int lane) const;
904 
905  SUMOReal getLaneSpeed(unsigned int lane) const;
906 
907  bool isNearEnough2BeJoined2(NBEdge* e, SUMOReal threshold) const;
908 
909 
917  SUMOReal getAngleAtNode(const NBNode* const node) const;
918 
919 
920  void incLaneNo(unsigned int by);
921 
922  void decLaneNo(unsigned int by, int dir = 0);
923 
924  void markAsInLane2LaneState();
925 
927  void setPermissions(SVCPermissions permissions, int lane = -1);
928 
929  void setPreferredVehicleClass(SVCPermissions permissions, int lane = -1);
930 
932  void allowVehicleClass(int lane, SUMOVehicleClass vclass);
934  void disallowVehicleClass(int lane, SUMOVehicleClass vclass);
935 
936  void preferVehicleClass(int lane, SUMOVehicleClass vclass);
937 
938 
939 
941  void setLaneWidth(int lane, SUMOReal width);
942 
944  SUMOReal getLaneWidth(int lane) const;
945 
947  void setOffset(int lane, SUMOReal offset);
948 
950  void setSpeed(int lane, SUMOReal speed);
951 
953  SVCPermissions getPermissions(int lane = -1) const;
954 
955  void disableConnection4TLS(int fromLane, NBEdge* toEdge, int toLane);
956 
957 
958  // returns a reference to the internal structure for the convenience of NETEDIT
959  Lane& getLaneStruct(unsigned int lane) {
960  return myLanes[lane];
961  }
962 
963  // returns a reference to the internal structure for the convenience of NETEDIT
964  const Lane& getLaneStruct(unsigned int lane) const {
965  return myLanes[lane];
966  }
967 
968  /* declares connections as fully loaded. This is needed to avoid recomputing connections
969  * if an edge has no connections intentionally. */
972  }
973 
974  void buildInnerEdges(const NBNode& n, unsigned int noInternalNoSplits, unsigned int& lno, unsigned int& splitNo);
975 
976  inline const std::vector<NBSign>& getSigns() const {
977  return mySigns;
978  }
979 
980  inline void addSign(NBSign sign) {
981  mySigns.push_back(sign);
982  }
983 
984 
985 private:
992  private:
994  std::map<NBEdge*, std::vector<unsigned int> > myConnections;
995 
998 
999  public:
1002  : myTransitions(transitions) { }
1003 
1006 
1008  void execute(const unsigned int lane, const unsigned int virtEdge);
1009 
1010  const std::map<NBEdge*, std::vector<unsigned int> >& getBuiltConnections() const {
1011  return myConnections;
1012  }
1013 
1014  private:
1017 
1020 
1021  };
1022 
1023 
1032  public:
1035 
1038  std::vector<Direction> myDirs;
1039 
1040  public:
1042  MainDirections(const EdgeVector& outgoing,
1043  NBEdge* parent, NBNode* to);
1044 
1046  ~MainDirections();
1047 
1050  bool empty() const;
1051 
1054  bool includes(Direction d) const;
1055 
1056  private:
1059 
1062 
1063  };
1064 
1066  PositionVector computeLaneShape(unsigned int lane, SUMOReal offset);
1067 
1069  //std::pair<SUMOReal, SUMOReal> laneOffset(const Position& from, const Position& to, SUMOReal laneCenterOffset);
1070 
1071  void computeLaneShapes();
1072 
1073 
1074 
1075 private:
1091  void init(unsigned int noLanes, bool tryIgnoreNodePositions);
1092 
1093 
1095  void divideOnEdges(const EdgeVector* outgoing);
1096 
1099  std::vector<unsigned int>* preparePriorities(
1100  const EdgeVector* outgoing);
1101 
1103  unsigned int computePrioritySum(std::vector<unsigned int>* priorities);
1104 
1105 
1108 
1111  void moveConnectionToLeft(unsigned int lane);
1112 
1115  void moveConnectionToRight(unsigned int lane);
1117 
1118 
1123  PositionVector startShapeAt(const PositionVector& laneShape, const NBNode* startNode) const;
1124 
1125 private:
1130 
1132  std::string myType;
1133 
1136 
1139 
1142 
1145 
1148 
1152  std::vector<Connection> myConnections;
1153 
1156  std::vector<Connection> myConnectionsToDelete;
1157 
1160 
1163 
1166 
1169 
1172 
1175 
1178 
1182  std::vector<Lane> myLanes;
1183 
1186 
1189 
1190 
1193 
1196 
1200  int toLane;
1201  };
1202 
1203  std::vector<TLSDisabledConnection> myTLSDisabledConnections;
1204 
1205 
1207  std::string myStreetName;
1208 
1209 
1211  std::vector<NBSign> mySigns;
1212 
1213 
1214 public:
1219  public:
1222 
1223  bool operator()(const TLSDisabledConnection& e) const {
1224  if (e.to != myDefinition.to) {
1225  return false;
1226  }
1227  if (e.fromLane != myDefinition.fromLane) {
1228  return false;
1229  }
1230  if (e.toLane != myDefinition.toLane) {
1231  return false;
1232  }
1233  return true;
1234  }
1235 
1236  private:
1238 
1239  private:
1242 
1243  };
1244 
1245 
1246 
1251  public:
1253  connections_toedge_finder(NBEdge* const edge2find) : myEdge2Find(edge2find) { }
1254 
1255  bool operator()(const Connection& c) const {
1256  return c.toEdge == myEdge2Find;
1257  }
1258 
1259  private:
1261 
1262  private:
1265 
1266  };
1267 
1272  public:
1274  connections_toedgelane_finder(NBEdge* const edge2find, int lane2find) : myEdge2Find(edge2find), myLane2Find(lane2find) { }
1275 
1276  bool operator()(const Connection& c) const {
1277  return c.toEdge == myEdge2Find && c.toLane == myLane2Find;
1278  }
1279 
1280  private:
1283 
1284  private:
1287 
1288  };
1289 
1290 
1295  public:
1297  connections_finder(int fromLane, NBEdge* const edge2find, int lane2find) : myFromLane(fromLane), myEdge2Find(edge2find), myLane2Find(lane2find) { }
1298 
1299  bool operator()(const Connection& c) const {
1300  return c.fromLane == myFromLane && c.toEdge == myEdge2Find && c.toLane == myLane2Find;
1301  }
1302 
1303  private:
1307 
1308  private:
1311 
1312  };
1313 
1318  public:
1320  connections_fromlane_finder(int lane2find) : myLane2Find(lane2find) { }
1321 
1322  bool operator()(const Connection& c) const {
1323  return c.fromLane == myLane2Find;
1324  }
1325 
1326  private:
1328 
1329  private:
1332 
1333  };
1334 
1338  static bool connections_sorter(const Connection& c1, const Connection& c2) {
1339  if (c1.fromLane != c2.fromLane) {
1340  return c1.fromLane < c2.fromLane;
1341  }
1342  if (c1.toEdge != c2.toEdge) {
1343  return c1.toEdge->getID().compare(c1.toEdge->getID()) < 0;
1344  }
1345  return c1.toLane < c2.toLane;
1346  }
1347 
1353  public:
1356  : myEdge(e), myNode(n) {}
1357 
1358  public:
1360  int operator()(const Connection& c1, const Connection& c2) const {
1361  if (c1.toEdge != c2.toEdge) {
1362  SUMOReal relAngle1 = NBHelpers::normRelAngle(
1363  myEdge->getAngle(), c1.toEdge->getAngle());
1364  SUMOReal relAngle2 = NBHelpers::normRelAngle(
1365  myEdge->getAngle(), c2.toEdge->getAngle());
1366  return relAngle1 > relAngle2;
1367  }
1368  return c1.toLane < c2.toLane;
1369  }
1370 
1371  private:
1374 
1377 
1378  };
1379 
1380 private:
1382  NBEdge(const NBEdge& s);
1383 
1385  NBEdge& operator=(const NBEdge& s);
1386 
1387 
1388 };
1389 
1390 
1391 #endif
1392 
1393 /****************************************************************************/
1394