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::vector<unsigned int> foeInternalLinks;
187  std::string foeIncomingLanes;
188 
190  unsigned int internalLaneIndex;
191 
192  std::string getInternalLaneID() const;
193 
194  };
195 
197  static std::pair<SUMOReal, SUMOReal> laneOffset(const Position& from,
198  const Position& to, SUMOReal laneCenterOffset, bool leftHand);
199 
207  static const SUMOReal ANGLE_LOOKAHEAD;
208 
209 public:
228  NBEdge(const std::string& id,
229  NBNode* from, NBNode* to, std::string type,
230  SUMOReal speed, unsigned int nolanes, int priority,
231  SUMOReal width, SUMOReal offset,
232  const std::string& streetName = "",
234 
235 
256  NBEdge(const std::string& id,
257  NBNode* from, NBNode* to, std::string type,
258  SUMOReal speed, unsigned int nolanes, int priority,
259  SUMOReal width, SUMOReal offset,
260  PositionVector geom,
261  const std::string& streetName = "",
263  bool tryIgnoreNodePositions = false);
264 
274  NBEdge(const std::string& id,
275  NBNode* from, NBNode* to,
276  NBEdge* tpl);
277 
278 
281  ~NBEdge();
282 
283 
299  void reinit(NBNode* from, NBNode* to, const std::string& type,
300  SUMOReal speed, unsigned int nolanes, int priority,
301  PositionVector geom, SUMOReal width, SUMOReal offset,
302  const std::string& streetName,
304  bool tryIgnoreNodePositions = false);
305 
310  void reinitNodes(NBNode* from, NBNode* to);
311 
312 
315 
320  void reshiftPosition(SUMOReal xoff, SUMOReal yoff);
322 
323 
324 
327  void setLeftHanded() {
328  myAmLeftHand = true;
329  }
330 
331 
333 
334 
338  unsigned int getNumLanes() const {
339  return (unsigned int) myLanes.size();
340  }
341 
342 
346  int getPriority() const {
347  return myPriority;
348  }
349 
350 
354  NBNode* getFromNode() const {
355  return myFrom;
356  }
357 
358 
362  NBNode* getToNode() const {
363  return myTo;
364  }
365 
366 
371  inline SUMOReal getStartAngle() const {
372  return myStartAngle;
373  }
374 
375 
380  inline SUMOReal getEndAngle() const {
381  return myEndAngle;
382  }
383 
384 
386 
390  inline SUMOReal getTotalAngle() const {
391  return myTotalAngle;
392  }
393 
397  SUMOReal getLength() const {
398  return myLength;
399  }
400 
401 
407  return myLoadedLength > 0 ? myLoadedLength : myLength;
408  }
409 
410 
414  bool hasLoadedLength() const {
415  return myLoadedLength > 0;
416  }
417 
418 
422  SUMOReal getSpeed() const {
423  return mySpeed;
424  }
425 
426 
433  return myStep;
434  }
435 
436 
441  return myLaneWidth;
442  }
443 
447  SUMOReal getLaneWidth(int lane) const;
448 
449 
452  const std::string& getStreetName() const {
453  return myStreetName;
454  }
455 
458  void setStreetName(const std::string& name) {
459  myStreetName = name;
460  }
461 
465  SUMOReal getOffset() const {
466  return myOffset;
467  }
468 
472  SUMOReal getOffset(int lane) const;
473 
474 
478  const std::string& getTypeName() const {
479  return myType;
480  }
481 
482 
486  const std::vector<NBEdge::Lane>& getLanes() const {
487  return myLanes;
488  }
490 
491 
492 
494 
495 
499  const PositionVector& getGeometry() const {
500  return myGeom;
501  }
502 
503 
505  const PositionVector getInnerGeometry() const;
506 
507 
510  bool hasDefaultGeometry() const;
511 
512 
518  bool hasDefaultGeometryEndpoints() const;
519 
520 
531  void setGeometry(const PositionVector& g, bool inner = false);
532 
533 
543  void addGeometryPoint(int index, const Position& p);
544 
545 
555  void computeEdgeShape();
556 
557 
561  const PositionVector& getLaneShape(unsigned int i) const;
562 
563 
569 
570 
576  return myLaneSpreadFunction;
577  }
578 
579 
585  bool splitGeometry(NBEdgeCont& ec, NBNodeCont& nc);
586 
587 
591  void reduceGeometry(const SUMOReal minDist);
592 
593 
599  void checkGeometry(const SUMOReal maxAngle, const SUMOReal minRadius, bool fix);
601 
602 
603 
606 
621  bool addEdge2EdgeConnection(NBEdge* dest);
622 
623 
644  bool addLane2LaneConnection(unsigned int fromLane, NBEdge* dest,
645  unsigned int toLane, Lane2LaneInfoType type,
646  bool mayUseSameDestination = false,
647  bool mayDefinitelyPass = false);
648 
649 
667  bool addLane2LaneConnections(unsigned int fromLane,
668  NBEdge* dest, unsigned int toLane, unsigned int no,
669  Lane2LaneInfoType type, bool invalidatePrevious = false,
670  bool mayDefinitelyPass = false);
671 
672 
683  void setConnection(unsigned int lane, NBEdge* destEdge,
684  unsigned int destLane,
685  Lane2LaneInfoType type,
686  bool mayUseSameDestination = false,
687  bool mayDefinitelyPass = false);
688 
689 
690 
699  std::vector<Connection> getConnectionsFromLane(unsigned int lane) const;
700 
701 
709  bool hasConnectionTo(NBEdge* destEdge, unsigned int destLane) const;
710 
711 
718  bool isConnectedTo(NBEdge* e);
719 
720 
724  const std::vector<Connection>& getConnections() const {
725  return myConnections;
726  }
727 
728 
732  std::vector<Connection>& getConnections() {
733  return myConnections;
734  }
735 
736 
741 
742 
747 
748 
752  std::vector<int> getConnectionLanes(NBEdge* currentOutgoing) const;
753 
754 
758 
759 
763 
764 
770  void remapConnections(const EdgeVector& incoming);
771 
772 
779  void removeFromConnections(NBEdge* toEdge, int fromLane = -1, int toLane = -1, bool tryLater = false);
780 
781  void invalidateConnections(bool reallowSetting = false);
782 
783  void replaceInConnections(NBEdge* which, NBEdge* by, unsigned int laneOff);
784  void replaceInConnections(NBEdge* which, const std::vector<NBEdge::Connection>& origConns);
785  void copyConnectionsFrom(NBEdge* src);
787 
788 
789 
795  bool isTurningDirectionAt(const NBNode* n, const NBEdge* const edge) const;
796  void setTurningDestination(NBEdge* e);
797 
798 
799 
802 
807  }
808 
809 
813  bool isMacroscopicConnector() const {
815  }
816 
817 
820  void setIsInnerEdge() {
821  myAmInnerEdge = true;
822  }
823 
824 
828  bool isInnerEdge() const {
829  return myAmInnerEdge;
830  }
832 
833 
834 
835 
841  void setJunctionPriority(const NBNode* const node, int prio);
842 
843 
853  int getJunctionPriority(const NBNode* const node) const;
854 
855  void setLoadedLength(SUMOReal val);
857 
858 
859  const std::string& getTypeID() const {
860  return myType;
861  }
862 
864  bool needsLaneSpecificOutput() const;
865 
867  bool hasRestrictions() const;
868 
870  bool hasLaneSpecificPermissions() const;
871 
873  bool hasLaneSpecificSpeed() const;
874 
876  bool hasLaneSpecificOffset() const;
877 
879  bool hasLaneSpecificWidth() const;
880 
882  bool computeEdge2Edges(bool noLeftMovers);
883 
885  bool computeLanes2Edges();
886 
889  bool recheckLanes();
890 
899  void appendTurnaround(bool noTLSControlled);
900 
901 
902 
906  NBNode* tryGetNodeAtPosition(SUMOReal pos, SUMOReal tolerance = 5.0) const;
907 
908 
910 
911  bool lanesWereAssigned() const;
912 
913  bool mayBeTLSControlled(int fromLane, NBEdge* toEdge, int toLane) const;
914 
916  bool setControllingTLInformation(const NBConnection& c, const std::string& tlID);
917 
920 
922  PositionVector& into);
923 
924  SUMOReal width() const;
925 
926  PositionVector getCWBoundaryLine(const NBNode& n, SUMOReal offset) const;
927  PositionVector getCCWBoundaryLine(const NBNode& n, SUMOReal offset) const;
928 
929  bool expandableBy(NBEdge* possContinuation) const;
930  void append(NBEdge* continuation);
931 
932  bool hasSignalisedConnectionTo(const NBEdge* const e) const;
933 
934 
935  void moveOutgoingConnectionsFrom(NBEdge* e, unsigned int laneOff);
936 
937  NBEdge* getTurnDestination() const;
938 
939  std::string getLaneID(unsigned int lane) const;
940 
941  std::string getLaneIDInsecure(unsigned int lane) const;
942 
943  SUMOReal getLaneSpeed(unsigned int lane) const;
944 
945  bool isNearEnough2BeJoined2(NBEdge* e, SUMOReal threshold) const;
946 
947 
955  SUMOReal getAngleAtNode(const NBNode* const node) const;
956 
957 
958  void incLaneNo(unsigned int by);
959 
960  void decLaneNo(unsigned int by, int dir = 0);
961 
962  void markAsInLane2LaneState();
963 
965  void setPermissions(SVCPermissions permissions, int lane = -1);
966 
967  void setPreferredVehicleClass(SVCPermissions permissions, int lane = -1);
968 
970  void allowVehicleClass(int lane, SUMOVehicleClass vclass);
972  void disallowVehicleClass(int lane, SUMOVehicleClass vclass);
973 
974  void preferVehicleClass(int lane, SUMOVehicleClass vclass);
975 
976 
977 
979  void setLaneWidth(int lane, SUMOReal width);
980 
982  void setOffset(int lane, SUMOReal offset);
983 
985  void setSpeed(int lane, SUMOReal speed);
986 
988  SVCPermissions getPermissions(int lane = -1) const;
989 
990  void disableConnection4TLS(int fromLane, NBEdge* toEdge, int toLane);
991 
992 
993  // returns a reference to the internal structure for the convenience of NETEDIT
994  Lane& getLaneStruct(unsigned int lane) {
995  return myLanes[lane];
996  }
997 
998  // returns a reference to the internal structure for the convenience of NETEDIT
999  const Lane& getLaneStruct(unsigned int lane) const {
1000  return myLanes[lane];
1001  }
1002 
1003  /* declares connections as fully loaded. This is needed to avoid recomputing connections
1004  * if an edge has no connections intentionally. */
1007  }
1008 
1009  /* @brief fill connection attributes shape, viaShape, ...
1010  *
1011  * @param[in,out] edgeIndex The number of connections already handled
1012  * @param[in,out] splitIndex The number of via edges already built
1013  * @param[in] tryIgnoreNodePositions Does not add node geometries if geom.size()>=2
1014  */
1015  void buildInnerEdges(const NBNode& n, unsigned int noInternalNoSplits, unsigned int& linkIndex, unsigned int& splitIndex);
1016 
1017  inline const std::vector<NBSign>& getSigns() const {
1018  return mySigns;
1019  }
1020 
1021  inline void addSign(NBSign sign) {
1022  mySigns.push_back(sign);
1023  }
1024 
1025 
1026 private:
1033  private:
1035  std::map<NBEdge*, std::vector<unsigned int> > myConnections;
1036 
1039 
1040  public:
1043  : myTransitions(transitions) { }
1044 
1047 
1049  void execute(const unsigned int lane, const unsigned int virtEdge);
1050 
1051  const std::map<NBEdge*, std::vector<unsigned int> >& getBuiltConnections() const {
1052  return myConnections;
1053  }
1054 
1055  private:
1058 
1061 
1062  };
1063 
1064 
1073  public:
1076 
1079  std::vector<Direction> myDirs;
1080 
1081  public:
1083  MainDirections(const EdgeVector& outgoing,
1084  NBEdge* parent, NBNode* to);
1085 
1087  ~MainDirections();
1088 
1091  bool empty() const;
1092 
1095  bool includes(Direction d) const;
1096 
1097  private:
1100 
1103 
1104  };
1105 
1107  PositionVector computeLaneShape(unsigned int lane, SUMOReal offset);
1108 
1110  //std::pair<SUMOReal, SUMOReal> laneOffset(const Position& from, const Position& to, SUMOReal laneCenterOffset);
1111 
1112  void computeLaneShapes();
1113 
1114 
1115 
1116 private:
1132  void init(unsigned int noLanes, bool tryIgnoreNodePositions);
1133 
1134 
1136  void divideOnEdges(const EdgeVector* outgoing);
1137 
1140  std::vector<unsigned int>* preparePriorities(
1141  const EdgeVector* outgoing);
1142 
1144  unsigned int computePrioritySum(std::vector<unsigned int>* priorities);
1145 
1146 
1149 
1152  void moveConnectionToLeft(unsigned int lane);
1153 
1156  void moveConnectionToRight(unsigned int lane);
1158 
1159 
1164  PositionVector startShapeAt(const PositionVector& laneShape, const NBNode* startNode) const;
1165 
1167  void computeAngle();
1168 
1169 private:
1174 
1176  std::string myType;
1177 
1180 
1183 
1188 
1191 
1194 
1198  std::vector<Connection> myConnections;
1199 
1202  std::vector<Connection> myConnectionsToDelete;
1203 
1206 
1209 
1212 
1215 
1218 
1221 
1224 
1228  std::vector<Lane> myLanes;
1229 
1232 
1235 
1236 
1239 
1242 
1246  int toLane;
1247  };
1248 
1249  std::vector<TLSDisabledConnection> myTLSDisabledConnections;
1250 
1251 
1253  std::string myStreetName;
1254 
1255 
1257  std::vector<NBSign> mySigns;
1258 
1259 
1260 public:
1265  public:
1268 
1269  bool operator()(const TLSDisabledConnection& e) const {
1270  if (e.to != myDefinition.to) {
1271  return false;
1272  }
1273  if (e.fromLane != myDefinition.fromLane) {
1274  return false;
1275  }
1276  if (e.toLane != myDefinition.toLane) {
1277  return false;
1278  }
1279  return true;
1280  }
1281 
1282  private:
1284 
1285  private:
1288 
1289  };
1290 
1291 
1292 
1297  public:
1299  connections_toedge_finder(NBEdge* const edge2find) : myEdge2Find(edge2find) { }
1300 
1301  bool operator()(const Connection& c) const {
1302  return c.toEdge == myEdge2Find;
1303  }
1304 
1305  private:
1307 
1308  private:
1311 
1312  };
1313 
1318  public:
1320  connections_toedgelane_finder(NBEdge* const edge2find, int lane2find) : myEdge2Find(edge2find), myLane2Find(lane2find) { }
1321 
1322  bool operator()(const Connection& c) const {
1323  return c.toEdge == myEdge2Find && c.toLane == myLane2Find;
1324  }
1325 
1326  private:
1329 
1330  private:
1333 
1334  };
1335 
1336 
1341  public:
1343  connections_finder(int fromLane, NBEdge* const edge2find, int lane2find) : myFromLane(fromLane), myEdge2Find(edge2find), myLane2Find(lane2find) { }
1344 
1345  bool operator()(const Connection& c) const {
1346  return c.fromLane == myFromLane && c.toEdge == myEdge2Find && c.toLane == myLane2Find;
1347  }
1348 
1349  private:
1353 
1354  private:
1357 
1358  };
1359 
1364  public:
1366  connections_fromlane_finder(int lane2find) : myLane2Find(lane2find) { }
1367 
1368  bool operator()(const Connection& c) const {
1369  return c.fromLane == myLane2Find;
1370  }
1371 
1372  private:
1374 
1375  private:
1378 
1379  };
1380 
1384  static bool connections_sorter(const Connection& c1, const Connection& c2) {
1385  if (c1.fromLane != c2.fromLane) {
1386  return c1.fromLane < c2.fromLane;
1387  }
1388  if (c1.toEdge != c2.toEdge) {
1389  return c1.toEdge->getID().compare(c1.toEdge->getID()) < 0;
1390  }
1391  return c1.toLane < c2.toLane;
1392  }
1393 
1399  public:
1402 
1403  public:
1405  int operator()(const Connection& c1, const Connection& c2) const;
1406 
1407  private:
1410  };
1411 
1412 private:
1414  NBEdge(const NBEdge& s);
1415 
1417  NBEdge& operator=(const NBEdge& s);
1418 
1419 
1420 };
1421 
1422 
1423 #endif
1424 
1425 /****************************************************************************/
1426