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-2014 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  endOffset(e->getEndOffset()), 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 
209  static const SUMOReal ANGLE_LOOKAHEAD;
210 
211 public:
230  NBEdge(const std::string& id,
231  NBNode* from, NBNode* to, std::string type,
232  SUMOReal speed, unsigned int nolanes, int priority,
233  SUMOReal width, SUMOReal offset,
234  const std::string& streetName = "",
236 
237 
258  NBEdge(const std::string& id,
259  NBNode* from, NBNode* to, std::string type,
260  SUMOReal speed, unsigned int nolanes, int priority,
261  SUMOReal width, SUMOReal offset,
262  PositionVector geom,
263  const std::string& streetName = "",
265  bool tryIgnoreNodePositions = false);
266 
278  NBEdge(const std::string& id,
279  NBNode* from, NBNode* to,
280  NBEdge* tpl,
281  const PositionVector& geom = PositionVector(),
282  int numLanes = -1);
283 
284 
287  ~NBEdge();
288 
289 
305  void reinit(NBNode* from, NBNode* to, const std::string& type,
306  SUMOReal speed, unsigned int nolanes, int priority,
307  PositionVector geom, SUMOReal width, SUMOReal offset,
308  const std::string& streetName,
310  bool tryIgnoreNodePositions = false);
311 
316  void reinitNodes(NBNode* from, NBNode* to);
317 
318 
321 
326  void reshiftPosition(SUMOReal xoff, SUMOReal yoff);
328 
329 
330 
333  void setLeftHanded() {
334  myAmLeftHand = true;
335  }
336 
337 
339 
340 
344  unsigned int getNumLanes() const {
345  return (unsigned int) myLanes.size();
346  }
347 
348 
352  int getPriority() const {
353  return myPriority;
354  }
355 
356 
360  NBNode* getFromNode() const {
361  return myFrom;
362  }
363 
364 
368  NBNode* getToNode() const {
369  return myTo;
370  }
371 
372 
377  inline SUMOReal getStartAngle() const {
378  return myStartAngle;
379  }
380 
381 
386  inline SUMOReal getEndAngle() const {
387  return myEndAngle;
388  }
389 
390 
392 
396  inline SUMOReal getTotalAngle() const {
397  return myTotalAngle;
398  }
399 
403  SUMOReal getLength() const {
404  return myLength;
405  }
406 
407 
413  return myLoadedLength > 0 ? myLoadedLength : myLength;
414  }
415 
416 
420  bool hasLoadedLength() const {
421  return myLoadedLength > 0;
422  }
423 
424 
428  SUMOReal getSpeed() const {
429  return mySpeed;
430  }
431 
432 
439  return myStep;
440  }
441 
442 
447  return myLaneWidth;
448  }
449 
453  SUMOReal getLaneWidth(int lane) const;
454 
455 
458  const std::string& getStreetName() const {
459  return myStreetName;
460  }
461 
464  void setStreetName(const std::string& name) {
465  myStreetName = name;
466  }
467 
472  return myEndOffset;
473  }
474 
478  SUMOReal getEndOffset(int lane) const;
479 
483  return mySignalOffset;
484  }
485 
488  void setSignalOffset(SUMOReal offset) {
489  mySignalOffset = offset;
490  }
491 
495  const std::string& getTypeName() const {
496  return myType;
497  }
498 
499 
503  const std::vector<NBEdge::Lane>& getLanes() const {
504  return myLanes;
505  }
507 
509  int getFirstNonPedestrianLaneIndex(int direction) const;
510  NBEdge::Lane getFirstNonPedestrianLane(int direction) const;
511 
514 
516 
517 
521  const PositionVector& getGeometry() const {
522  return myGeom;
523  }
524 
525 
527  const PositionVector getInnerGeometry() const;
528 
529 
532  bool hasDefaultGeometry() const;
533 
534 
540  bool hasDefaultGeometryEndpoints() const;
541 
542 
553  void setGeometry(const PositionVector& g, bool inner = false);
554 
555 
565  void addGeometryPoint(int index, const Position& p);
566 
567 
577  void computeEdgeShape();
578 
579 
583  const PositionVector& getLaneShape(unsigned int i) const;
584 
585 
591 
592 
598  return myLaneSpreadFunction;
599  }
600 
601 
607  bool splitGeometry(NBEdgeCont& ec, NBNodeCont& nc);
608 
609 
613  void reduceGeometry(const SUMOReal minDist);
614 
615 
621  void checkGeometry(const SUMOReal maxAngle, const SUMOReal minRadius, bool fix);
623 
624 
625 
628 
643  bool addEdge2EdgeConnection(NBEdge* dest);
644 
645 
666  bool addLane2LaneConnection(unsigned int fromLane, NBEdge* dest,
667  unsigned int toLane, Lane2LaneInfoType type,
668  bool mayUseSameDestination = false,
669  bool mayDefinitelyPass = false);
670 
671 
689  bool addLane2LaneConnections(unsigned int fromLane,
690  NBEdge* dest, unsigned int toLane, unsigned int no,
691  Lane2LaneInfoType type, bool invalidatePrevious = false,
692  bool mayDefinitelyPass = false);
693 
694 
705  void setConnection(unsigned int lane, NBEdge* destEdge,
706  unsigned int destLane,
707  Lane2LaneInfoType type,
708  bool mayUseSameDestination = false,
709  bool mayDefinitelyPass = false);
710 
711 
712 
721  std::vector<Connection> getConnectionsFromLane(unsigned int lane) const;
722 
723 
732  bool hasConnectionTo(NBEdge* destEdge, unsigned int destLane, int fromLane = -1) const;
733 
734 
741  bool isConnectedTo(NBEdge* e);
742 
743 
747  const std::vector<Connection>& getConnections() const {
748  return myConnections;
749  }
750 
751 
755  std::vector<Connection>& getConnections() {
756  return myConnections;
757  }
758 
759 
764 
765 
770 
771 
775  std::vector<int> getConnectionLanes(NBEdge* currentOutgoing) const;
776 
777 
781 
782 
786 
787 
793  void remapConnections(const EdgeVector& incoming);
794 
795 
802  void removeFromConnections(NBEdge* toEdge, int fromLane = -1, int toLane = -1, bool tryLater = false);
803 
804  void invalidateConnections(bool reallowSetting = false);
805 
806  void replaceInConnections(NBEdge* which, NBEdge* by, unsigned int laneOff);
807  void replaceInConnections(NBEdge* which, const std::vector<NBEdge::Connection>& origConns);
808  void copyConnectionsFrom(NBEdge* src);
809 
811  void shiftToLanesToEdge(NBEdge* to, unsigned int laneOff);
813 
814 
815 
821  bool isTurningDirectionAt(const NBNode* n, const NBEdge* const edge) const;
822  void setTurningDestination(NBEdge* e);
823 
824 
825 
828 
833  }
834 
835 
839  bool isMacroscopicConnector() const {
841  }
842 
843 
846  void setIsInnerEdge() {
847  myAmInnerEdge = true;
848  }
849 
850 
854  bool isInnerEdge() const {
855  return myAmInnerEdge;
856  }
858 
859 
860 
861 
867  void setJunctionPriority(const NBNode* const node, int prio);
868 
869 
879  int getJunctionPriority(const NBNode* const node) const;
880 
881  void setLoadedLength(SUMOReal val);
883 
884 
885  const std::string& getTypeID() const {
886  return myType;
887  }
888 
890  bool needsLaneSpecificOutput() const;
891 
893  bool hasRestrictions() const;
894 
896  bool hasLaneSpecificPermissions() const;
897 
899  bool hasLaneSpecificSpeed() const;
900 
902  bool hasLaneSpecificEndOffset() const;
903 
905  bool hasLaneSpecificWidth() const;
906 
908  bool computeEdge2Edges(bool noLeftMovers);
909 
911  bool computeLanes2Edges(const bool buildCrossingsAndWalkingAreas);
912 
915  bool recheckLanes(const bool buildCrossingsAndWalkingAreas);
916 
925  void appendTurnaround(bool noTLSControlled);
926 
927 
928 
932  NBNode* tryGetNodeAtPosition(SUMOReal pos, SUMOReal tolerance = 5.0) const;
933 
934 
936 
937  bool lanesWereAssigned() const;
938 
939  bool mayBeTLSControlled(int fromLane, NBEdge* toEdge, int toLane) const;
940 
942  bool setControllingTLInformation(const NBConnection& c, const std::string& tlID);
943 
946 
948  PositionVector& into);
949 
950  SUMOReal width() const;
951 
952  PositionVector getCWBoundaryLine(const NBNode& n, SUMOReal offset) const;
953  PositionVector getCCWBoundaryLine(const NBNode& n, SUMOReal offset) const;
954 
955  bool expandableBy(NBEdge* possContinuation) const;
956  void append(NBEdge* continuation);
957 
958  bool hasSignalisedConnectionTo(const NBEdge* const e) const;
959 
960 
961  void moveOutgoingConnectionsFrom(NBEdge* e, unsigned int laneOff);
962 
963  NBEdge* getTurnDestination() const;
964 
965  std::string getLaneID(unsigned int lane) const;
966 
967  std::string getLaneIDInsecure(unsigned int lane) const;
968 
969  SUMOReal getLaneSpeed(unsigned int lane) const;
970 
971  bool isNearEnough2BeJoined2(NBEdge* e, SUMOReal threshold) const;
972 
973 
981  SUMOReal getAngleAtNode(const NBNode* const node) const;
982 
983 
984  void incLaneNo(unsigned int by);
985 
986  void decLaneNo(unsigned int by, int dir = 0);
987 
988  void markAsInLane2LaneState();
989 
991  void addSidewalk(SUMOReal width);
992 
994  void setPermissions(SVCPermissions permissions, int lane = -1);
995 
996  void setPreferredVehicleClass(SVCPermissions permissions, int lane = -1);
997 
999  void allowVehicleClass(int lane, SUMOVehicleClass vclass);
1001  void disallowVehicleClass(int lane, SUMOVehicleClass vclass);
1002 
1003  void preferVehicleClass(int lane, SUMOVehicleClass vclass);
1004 
1005 
1007  void setLaneWidth(int lane, SUMOReal width);
1008 
1010  void setEndOffset(int lane, SUMOReal offset);
1011 
1013  void setSpeed(int lane, SUMOReal speed);
1014 
1016  SVCPermissions getPermissions(int lane = -1) const;
1017 
1018  void disableConnection4TLS(int fromLane, NBEdge* toEdge, int toLane);
1019 
1020 
1021  // returns a reference to the internal structure for the convenience of NETEDIT
1022  Lane& getLaneStruct(unsigned int lane) {
1023  return myLanes[lane];
1024  }
1025 
1026  // returns a reference to the internal structure for the convenience of NETEDIT
1027  const Lane& getLaneStruct(unsigned int lane) const {
1028  return myLanes[lane];
1029  }
1030 
1031  /* declares connections as fully loaded. This is needed to avoid recomputing connections
1032  * if an edge has no connections intentionally. */
1035  }
1036 
1037  /* @brief fill connection attributes shape, viaShape, ...
1038  *
1039  * @param[in,out] edgeIndex The number of connections already handled
1040  * @param[in,out] splitIndex The number of via edges already built
1041  * @param[in] tryIgnoreNodePositions Does not add node geometries if geom.size()>=2
1042  */
1043  void buildInnerEdges(const NBNode& n, unsigned int noInternalNoSplits, unsigned int& linkIndex, unsigned int& splitIndex);
1044 
1045  inline const std::vector<NBSign>& getSigns() const {
1046  return mySigns;
1047  }
1048 
1049  inline void addSign(NBSign sign) {
1050  mySigns.push_back(sign);
1051  }
1052 
1053 
1054 private:
1061  private:
1063  std::map<NBEdge*, std::vector<unsigned int> > myConnections;
1064 
1067 
1068  public:
1071  : myTransitions(transitions) { }
1072 
1075 
1077  void execute(const unsigned int lane, const unsigned int virtEdge);
1078 
1079  const std::map<NBEdge*, std::vector<unsigned int> >& getBuiltConnections() const {
1080  return myConnections;
1081  }
1082 
1083  private:
1086 
1089 
1090  };
1091 
1092 
1101  public:
1104 
1107  std::vector<Direction> myDirs;
1108 
1109  public:
1111  MainDirections(const EdgeVector& outgoing,
1112  NBEdge* parent, NBNode* to);
1113 
1115  ~MainDirections();
1116 
1119  bool empty() const;
1120 
1123  bool includes(Direction d) const;
1124 
1125  private:
1128 
1131 
1132  };
1133 
1135  PositionVector computeLaneShape(unsigned int lane, SUMOReal offset);
1136 
1138  //std::pair<SUMOReal, SUMOReal> laneOffset(const Position& from, const Position& to, SUMOReal laneCenterOffset);
1139 
1140  void computeLaneShapes();
1141 
1142 
1143 
1144 private:
1160  void init(unsigned int noLanes, bool tryIgnoreNodePositions);
1161 
1162 
1164  void divideOnEdges(const EdgeVector* outgoing, const bool buildCrossingsAndWalkingAreas);
1165 
1168  std::vector<unsigned int>* prepareEdgePriorities(
1169  const EdgeVector* outgoing);
1170 
1172  unsigned int computePrioritySum(std::vector<unsigned int>* priorities);
1173 
1174 
1177 
1180  void moveConnectionToLeft(unsigned int lane, const bool buildCrossingsAndWalkingAreas);
1181 
1184  void moveConnectionToRight(unsigned int lane, const bool buildCrossingsAndWalkingAreas);
1185 
1187  bool canMoveConnection(const Connection& con, unsigned int newFromLane, const bool buildCrossingsAndWalkingAreas) const;
1189 
1190 
1195  PositionVector startShapeAt(const PositionVector& laneShape, const NBNode* startNode) const;
1196 
1198  void computeAngle();
1199 
1200 private:
1205 
1207  std::string myType;
1208 
1211 
1214 
1219 
1222 
1225 
1229  std::vector<Connection> myConnections;
1230 
1233  std::vector<Connection> myConnectionsToDelete;
1234 
1237 
1240 
1243 
1246 
1249 
1252 
1255 
1259  std::vector<Lane> myLanes;
1260 
1263 
1266 
1267 
1270 
1273 
1277  int toLane;
1278  };
1279 
1280  std::vector<TLSDisabledConnection> myTLSDisabledConnections;
1281 
1282 
1284  std::string myStreetName;
1285 
1286 
1288  std::vector<NBSign> mySigns;
1289 
1292 
1293 public:
1298  public:
1301 
1302  bool operator()(const TLSDisabledConnection& e) const {
1303  if (e.to != myDefinition.to) {
1304  return false;
1305  }
1306  if (e.fromLane != myDefinition.fromLane) {
1307  return false;
1308  }
1309  if (e.toLane != myDefinition.toLane) {
1310  return false;
1311  }
1312  return true;
1313  }
1314 
1315  private:
1317 
1318  private:
1321 
1322  };
1323 
1324 
1325 
1330  public:
1332  connections_toedge_finder(NBEdge* const edge2find) : myEdge2Find(edge2find) { }
1333 
1334  bool operator()(const Connection& c) const {
1335  return c.toEdge == myEdge2Find;
1336  }
1337 
1338  private:
1340 
1341  private:
1344 
1345  };
1346 
1351  public:
1353  connections_toedgelane_finder(NBEdge* const edge2find, int lane2find, int fromLane2find) :
1354  myEdge2Find(edge2find),
1355  myLane2Find(lane2find),
1356  myFromLane2Find(fromLane2find) { }
1357 
1358  bool operator()(const Connection& c) const {
1359  return c.toEdge == myEdge2Find && c.toLane == myLane2Find && (myFromLane2Find < 0 || c.fromLane == myFromLane2Find);
1360  }
1361 
1362  private:
1366 
1367  private:
1370 
1371  };
1372 
1373 
1378  public:
1380  connections_finder(int fromLane, NBEdge* const edge2find, int lane2find) : myFromLane(fromLane), myEdge2Find(edge2find), myLane2Find(lane2find) { }
1381 
1382  bool operator()(const Connection& c) const {
1383  return c.fromLane == myFromLane && c.toEdge == myEdge2Find && c.toLane == myLane2Find;
1384  }
1385 
1386  private:
1390 
1391  private:
1394 
1395  };
1396 
1401  public:
1403  connections_fromlane_finder(int lane2find) : myLane2Find(lane2find) { }
1404 
1405  bool operator()(const Connection& c) const {
1406  return c.fromLane == myLane2Find;
1407  }
1408 
1409  private:
1411 
1412  private:
1415 
1416  };
1417 
1421  static bool connections_sorter(const Connection& c1, const Connection& c2);
1422 
1428  public:
1431 
1432  public:
1434  int operator()(const Connection& c1, const Connection& c2) const;
1435 
1436  private:
1439  };
1440 
1441 private:
1443  NBEdge(const NBEdge& s);
1444 
1446  NBEdge& operator=(const NBEdge& s);
1447 
1448 
1449 };
1450 
1451 
1452 #endif
1453 
1454 /****************************************************************************/
1455