|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00009 // The representation of a single edge during network building 00010 /****************************************************************************/ 00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00013 /****************************************************************************/ 00014 // 00015 // This file is part of SUMO. 00016 // SUMO is free software: you can redistribute it and/or modify 00017 // it under the terms of the GNU General Public License as published by 00018 // the Free Software Foundation, either version 3 of the License, or 00019 // (at your option) any later version. 00020 // 00021 /****************************************************************************/ 00022 #ifndef NBEdge_h 00023 #define NBEdge_h 00024 00025 00026 // =========================================================================== 00027 // included modules 00028 // =========================================================================== 00029 #ifdef _MSC_VER 00030 #include <windows_config.h> 00031 #else 00032 #include <config.h> 00033 #endif 00034 00035 #include <map> 00036 #include <vector> 00037 #include <string> 00038 #include <set> 00039 #include "NBCont.h" 00040 #include <utils/common/Named.h> 00041 #include <utils/common/UtilExceptions.h> 00042 #include <utils/common/VectorHelper.h> 00043 #include <utils/geom/Bresenham.h> 00044 #include <utils/geom/PositionVector.h> 00045 #include <utils/geom/Line.h> 00046 #include <utils/common/SUMOVehicleClass.h> 00047 #include <utils/xml/SUMOXMLDefinitions.h> 00048 #include "NBHelpers.h" 00049 00050 00051 // =========================================================================== 00052 // class declarations 00053 // =========================================================================== 00054 class NBNode; 00055 class NBConnection; 00056 class NBNodeCont; 00057 class NBEdgeCont; 00058 class OutputDevice; 00059 class GNELane; 00060 00061 00062 // =========================================================================== 00063 // class definitions 00064 // =========================================================================== 00069 class NBEdge : public Named { 00071 friend class NBEdgeSuccessorBuilder; 00072 friend class NBEdgeCont; 00073 00075 friend class GNELane; 00076 friend class GNEEdge; 00077 00078 public: 00079 00087 enum EdgeBuildingStep { 00089 INIT_REJECT_CONNECTIONS, 00091 INIT, 00093 EDGE2EDGES, 00095 LANES2EDGES, 00097 LANES2LANES_RECHECK, 00099 LANES2LANES_DONE, 00101 LANES2LANES_USER 00102 }; 00103 00104 00108 enum Lane2LaneInfoType { 00110 L2L_COMPUTED, 00112 L2L_USER, 00114 L2L_VALIDATED 00115 }; 00116 00117 00121 struct Lane { 00123 PositionVector shape; 00125 SUMOReal speed; 00127 SUMOVehicleClasses allowed; 00129 SUMOVehicleClasses notAllowed; 00131 SUMOVehicleClasses preferred; 00133 SUMOReal offset; 00135 SUMOReal width; 00136 }; 00137 00138 00142 struct Connection { 00148 Connection(int fromLane_, NBEdge* toEdge_, int toLane_) 00149 : fromLane(fromLane_), toEdge(toEdge_), toLane(toLane_), 00150 mayDefinitelyPass(false), haveVia(false) { } 00151 00152 ~Connection() { } 00153 00154 00156 int fromLane; 00158 NBEdge* toEdge; 00160 int toLane; 00162 std::string tlID; 00164 unsigned int tlLinkNo; 00166 bool mayDefinitelyPass; 00167 00168 00169 std::string id; 00170 PositionVector shape; 00171 SUMOReal vmax; 00172 00173 bool haveVia; 00174 std::string viaID; 00175 SUMOReal viaVmax; 00176 PositionVector viaShape; 00177 00178 std::string crossingNames; 00179 std::string sourceNames; 00180 00181 }; 00182 00184 static std::pair<SUMOReal, SUMOReal> laneOffset(const Position& from, 00185 const Position& to, SUMOReal lanewidth, unsigned int lane, 00186 size_t noLanes, LaneSpreadFunction lsf, bool leftHand); 00187 00189 static const SUMOReal UNSPECIFIED_WIDTH; 00191 static const SUMOReal UNSPECIFIED_OFFSET; 00193 static const SUMOReal UNSPECIFIED_LOADED_LENGTH; 00194 00195 00196 public: 00215 NBEdge(const std::string& id, 00216 NBNode* from, NBNode* to, std::string type, 00217 SUMOReal speed, unsigned int nolanes, int priority, 00218 SUMOReal width, SUMOReal offset, 00219 const std::string& streetName = "", 00220 LaneSpreadFunction spread = LANESPREAD_RIGHT) ; 00221 00222 00243 NBEdge(const std::string& id, 00244 NBNode* from, NBNode* to, std::string type, 00245 SUMOReal speed, unsigned int nolanes, int priority, 00246 SUMOReal width, SUMOReal offset, 00247 PositionVector geom, 00248 const std::string& streetName = "", 00249 LaneSpreadFunction spread = LANESPREAD_RIGHT, 00250 bool tryIgnoreNodePositions = false) ; 00251 00261 NBEdge(const std::string& id, 00262 NBNode* from, NBNode* to, 00263 NBEdge* tpl); 00264 00265 00268 ~NBEdge() ; 00269 00270 00286 void reinit(NBNode* from, NBNode* to, const std::string& type, 00287 SUMOReal speed, unsigned int nolanes, int priority, 00288 PositionVector geom, SUMOReal width, SUMOReal offset, 00289 const std::string& streetName, 00290 LaneSpreadFunction spread = LANESPREAD_RIGHT, 00291 bool tryIgnoreNodePositions = false) ; 00292 00293 00294 00297 00302 void reshiftPosition(SUMOReal xoff, SUMOReal yoff) ; 00304 00305 00306 00309 void setLeftHanded() { 00310 myAmLeftHand = true; 00311 } 00312 00313 00315 00316 00320 unsigned int getNumLanes() const { 00321 return (unsigned int) myLanes.size(); 00322 } 00323 00324 00328 int getPriority() const { 00329 return myPriority; 00330 } 00331 00332 00336 NBNode* getFromNode() const { 00337 return myFrom; 00338 } 00339 00340 00344 NBNode* getToNode() const { 00345 return myTo; 00346 } 00347 00348 00356 SUMOReal getAngle() const { 00357 return myAngle; 00358 } 00359 00360 00364 SUMOReal getLength() const { 00365 return myLength; 00366 } 00367 00368 00373 SUMOReal getLoadedLength() const { 00374 return myLoadedLength > 0 ? myLoadedLength : myLength; 00375 } 00376 00377 00381 bool hasLoadedLength() const { 00382 return myLoadedLength > 0; 00383 } 00384 00385 00389 SUMOReal getSpeed() const { 00390 return mySpeed; 00391 } 00392 00393 00399 EdgeBuildingStep getStep() const { 00400 return myStep; 00401 } 00402 00403 00407 SUMOReal getWidth() const { 00408 return myWidth; 00409 } 00410 00411 00414 const std::string& getStreetName() const { 00415 return myStreetName; 00416 } 00417 00420 void setStreetName(const std::string& name) { 00421 myStreetName = name; 00422 } 00423 00427 SUMOReal getOffset() const { 00428 return myOffset; 00429 } 00430 00431 00435 const std::string& getTypeName() const { 00436 return myType; 00437 } 00438 00439 00443 const std::vector<NBEdge::Lane> &getLanes() const { 00444 return myLanes; 00445 } 00447 00448 00449 00451 00452 00456 const PositionVector& getGeometry() const { 00457 return myGeom; 00458 } 00459 00460 00462 const PositionVector getInnerGeometry() const; 00463 00464 00467 bool hasDefaultGeometry() const; 00468 00469 00475 bool hasDefaultGeometryEndpoints() const; 00476 00477 00488 void setGeometry(const PositionVector& g, bool inner = false) ; 00489 00490 00500 void addGeometryPoint(int index, const Position& p) ; 00501 00502 00512 void computeEdgeShape() ; 00513 00514 00518 const PositionVector& getLaneShape(unsigned int i) const ; 00519 00520 00525 void setLaneSpreadFunction(LaneSpreadFunction spread) ; 00526 00527 00532 LaneSpreadFunction getLaneSpreadFunction() const { 00533 return myLaneSpreadFunction; 00534 } 00535 00536 00542 bool splitGeometry(NBEdgeCont& ec, NBNodeCont& nc); 00544 00545 00546 00549 00564 bool addEdge2EdgeConnection(NBEdge* dest); 00565 00566 00587 bool addLane2LaneConnection(unsigned int fromLane, NBEdge* dest, 00588 unsigned int toLane, Lane2LaneInfoType type, 00589 bool mayUseSameDestination = false, 00590 bool mayDefinitelyPass = false); 00591 00592 00610 bool addLane2LaneConnections(unsigned int fromLane, 00611 NBEdge* dest, unsigned int toLane, unsigned int no, 00612 Lane2LaneInfoType type, bool invalidatePrevious = false, 00613 bool mayDefinitelyPass = false); 00614 00615 00626 void setConnection(unsigned int lane, NBEdge* destEdge, 00627 unsigned int destLane, 00628 Lane2LaneInfoType type, 00629 bool mayUseSameDestination = false, 00630 bool mayDefinitelyPass = false); 00631 00632 00633 00642 std::vector<Connection> getConnectionsFromLane(unsigned int lane) const; 00643 00644 00652 bool hasConnectionTo(NBEdge* destEdge, unsigned int destLane) const; 00653 00654 00661 bool isConnectedTo(NBEdge* e); 00662 00663 00667 const std::vector<Connection> &getConnections() const { 00668 return myConnections; 00669 } 00670 00671 00675 std::vector<Connection> &getConnections() { 00676 return myConnections; 00677 } 00678 00679 00683 const EdgeVector* getConnectedSorted(); 00684 00685 00689 EdgeVector getConnectedEdges() const; 00690 00691 00695 std::vector<int> getConnectionLanes(NBEdge* currentOutgoing) const; 00696 00697 00700 void sortOutgoingConnectionsByAngle(); 00701 00702 00705 void sortOutgoingConnectionsByIndex(); 00706 00707 00713 void remapConnections(const EdgeVector& incoming); 00714 00715 00721 void removeFromConnections(NBEdge* toEdge, int fromLane = -1, int toLane = -1); 00722 00723 void invalidateConnections(bool reallowSetting = false); 00724 00725 void replaceInConnections(NBEdge* which, NBEdge* by, unsigned int laneOff); 00726 void replaceInConnections(NBEdge* which, const std::vector<NBEdge::Connection> &origConns); 00727 void copyConnectionsFrom(NBEdge* src); 00729 00730 00731 00737 bool isTurningDirectionAt(const NBNode* n, const NBEdge* const edge) const ; 00738 void setTurningDestination(NBEdge* e); 00739 00740 00741 00744 00747 void setAsMacroscopicConnector() { 00748 myAmMacroscopicConnector = true; 00749 } 00750 00751 00755 bool isMacroscopicConnector() const { 00756 return myAmMacroscopicConnector; 00757 } 00758 00759 00762 void setIsInnerEdge() { 00763 myAmInnerEdge = true; 00764 } 00765 00766 00770 bool isInnerEdge() const { 00771 return myAmInnerEdge; 00772 } 00774 00775 00776 00777 00779 void computeTurningDirections(); 00780 00781 00787 void setJunctionPriority(const NBNode* const node, int prio); 00788 00789 00799 int getJunctionPriority(const NBNode* const node) const; 00800 00801 void setLoadedLength(SUMOReal val); 00802 void dismissVehicleClassInformation(); 00803 00804 00805 const std::string& getTypeID() const { 00806 return myType; 00807 } 00808 00810 bool needsLaneSpecificOutput() const; 00811 00813 bool hasRestrictions() const; 00814 00816 bool hasLaneSpecificAllow() const; 00817 00819 bool hasLaneSpecificDisallow() const; 00820 00822 bool hasLaneSpecificSpeed() const; 00823 00825 bool hasLaneSpecificOffset() const; 00826 00828 bool hasLaneSpecificWidth() const; 00829 00831 bool computeEdge2Edges(bool noLeftMovers); 00832 00834 bool computeLanes2Edges(); 00835 00838 bool recheckLanes(); 00839 00848 void appendTurnaround(bool noTLSControlled) ; 00849 00850 00851 00855 NBNode* tryGetNodeAtPosition(SUMOReal pos, SUMOReal tolerance = 5.0) const; 00856 00857 00858 SUMOReal getMaxLaneOffset(); 00859 00860 Position getMinLaneOffsetPositionAt(NBNode* node, SUMOReal width) const; 00861 Position getMaxLaneOffsetPositionAt(NBNode* node, SUMOReal width) const; 00862 00863 00864 bool lanesWereAssigned() const; 00865 00866 bool mayBeTLSControlled(int fromLane, NBEdge* toEdge, int toLane) const ; 00867 00869 bool setControllingTLInformation(const NBConnection& c, const std::string& tlID); 00870 00872 void clearControllingTLInformation(); 00873 00874 void addCrossingPointsAsIncomingWithGivenOutgoing(NBEdge* o, 00875 PositionVector& into); 00876 00877 SUMOReal width() const; 00878 00879 PositionVector getCWBoundaryLine(const NBNode& n, SUMOReal offset) const; 00880 PositionVector getCCWBoundaryLine(const NBNode& n, SUMOReal offset) const; 00881 00882 bool expandableBy(NBEdge* possContinuation) const; 00883 void append(NBEdge* continuation); 00884 SUMOReal getNormedAngle() const; 00885 00886 bool hasSignalisedConnectionTo(const NBEdge* const e) const ; 00887 00888 00889 void moveOutgoingConnectionsFrom(NBEdge* e, unsigned int laneOff); 00890 00891 NBEdge* getTurnDestination() const; 00892 00893 std::string getLaneID(unsigned int lane) const; 00894 00895 SUMOReal getLaneSpeed(unsigned int lane) const; 00896 00897 bool isNearEnough2BeJoined2(NBEdge* e, SUMOReal threshold) const; 00898 00899 SUMOReal getAngle(const NBNode& atNode) const; 00900 00901 SUMOReal getNormedAngle(const NBNode& atNode) const; 00902 00903 00904 void incLaneNo(unsigned int by); 00905 00906 void decLaneNo(unsigned int by, int dir = 0); 00907 00908 void markAsInLane2LaneState(); 00909 00911 void setVehicleClasses(const SUMOVehicleClasses& allowed, const SUMOVehicleClasses& disallowed, int lane = -1); 00912 00914 void allowVehicleClass(int lane, SUMOVehicleClass vclass); 00915 00917 void disallowVehicleClass(int lane, SUMOVehicleClass vclass); 00918 00919 void preferVehicleClass(int lane, SUMOVehicleClass vclass); 00920 00922 void setWidth(int lane, SUMOReal width); 00923 00925 void setOffset(int lane, SUMOReal offset); 00926 00928 void setSpeed(int lane, SUMOReal offset); 00929 00931 SUMOVehicleClasses getAllowedVehicleClasses() const; 00932 00934 SUMOVehicleClasses getDisallowedVehicleClasses() const; 00935 00937 SUMOVehicleClasses getAllowedVehicleClasses(unsigned int lane) const; 00938 00940 SUMOVehicleClasses getDisallowedVehicleClasses(unsigned int lane) const; 00941 00942 void disableConnection4TLS(int fromLane, NBEdge* toEdge, int toLane); 00943 00944 00945 // returns a reference to the internal structure for the convenience of NETEDIT 00946 Lane& getLaneStruct(unsigned int lane) { 00947 return myLanes[lane]; 00948 } 00949 00950 // returns a reference to the internal structure for the convenience of NETEDIT 00951 const Lane& getLaneStruct(unsigned int lane) const { 00952 return myLanes[lane]; 00953 } 00954 00955 /* declares connections as fully loaded. This is needed to avoid recomputing connections 00956 * if an edge has no connections intentionally. */ 00957 void declareConnectionsAsLoaded() { 00958 myStep = LANES2LANES_USER; 00959 } 00960 00961 void buildInnerEdges(const NBNode& n, unsigned int noInternalNoSplits, unsigned int& lno, unsigned int& splitNo); 00962 00963 00964 private: 00970 class ToEdgeConnectionsAdder : public Bresenham::BresenhamCallBack { 00971 private: 00973 std::map<NBEdge*, std::vector<unsigned int> > myConnections; 00974 00976 const EdgeVector& myTransitions; 00977 00978 public: 00980 ToEdgeConnectionsAdder(const EdgeVector& transitions) 00981 : myTransitions(transitions) { } 00982 00984 ~ToEdgeConnectionsAdder() { } 00985 00987 void execute(const unsigned int lane, const unsigned int virtEdge) ; 00988 00989 const std::map<NBEdge*, std::vector<unsigned int> > &getBuiltConnections() const { 00990 return myConnections; 00991 } 00992 00993 private: 00995 ToEdgeConnectionsAdder(const ToEdgeConnectionsAdder&); 00996 00998 ToEdgeConnectionsAdder& operator=(const ToEdgeConnectionsAdder&); 00999 01000 }; 01001 01002 01010 class MainDirections { 01011 public: 01013 enum Direction { DIR_RIGHTMOST, DIR_LEFTMOST, DIR_FORWARD }; 01014 01017 std::vector<Direction> myDirs; 01018 01019 public: 01021 MainDirections(const EdgeVector& outgoing, 01022 NBEdge* parent, NBNode* to); 01023 01025 ~MainDirections(); 01026 01029 bool empty() const; 01030 01033 bool includes(Direction d) const; 01034 01035 private: 01037 MainDirections(const MainDirections&); 01038 01040 MainDirections& operator=(const MainDirections&); 01041 01042 }; 01043 01045 PositionVector computeLaneShape(unsigned int lane) throw(InvalidArgument); 01046 01048 std::pair<SUMOReal, SUMOReal> laneOffset(const Position& from, 01049 const Position& to, SUMOReal lanewidth, unsigned int lane) throw(InvalidArgument); 01050 01051 void computeLaneShapes() ; 01052 01053 protected: 01054 bool acceptBeingTurning(NBEdge* e); 01055 01056 01057 private: 01073 void init(unsigned int noLanes, bool tryIgnoreNodePositions) ; 01074 01075 01077 void divideOnEdges(const EdgeVector* outgoing); 01078 01081 std::vector<unsigned int> *preparePriorities( 01082 const EdgeVector* outgoing); 01083 01085 unsigned int computePrioritySum(std::vector<unsigned int> *priorities); 01086 01087 01090 01093 void moveConnectionToLeft(unsigned int lane); 01094 01097 void moveConnectionToRight(unsigned int lane); 01099 01100 01105 PositionVector startShapeAt(const PositionVector& laneShape, const NBNode* startNode, unsigned int laneIndex) const; 01106 01107 01108 private: 01112 EdgeBuildingStep myStep; 01113 01115 std::string myType; 01116 01118 NBNode* myFrom, *myTo; 01119 01121 SUMOReal myLength; 01122 01124 SUMOReal myAngle; 01125 01127 int myPriority; 01128 01130 SUMOReal mySpeed; 01131 01135 std::vector<Connection> myConnections; 01136 01138 NBEdge* myTurnDestination; 01139 01141 int myFromJunctionPriority; 01142 01144 int myToJunctionPriority; 01145 01147 PositionVector myGeom; 01148 01150 LaneSpreadFunction myLaneSpreadFunction; 01151 01153 SUMOReal myOffset; 01154 01156 SUMOReal myWidth; 01157 01161 std::vector<Lane> myLanes; 01162 01164 SUMOReal myLoadedLength; 01165 01167 bool myAmLeftHand; 01168 01169 01172 01174 SUMOReal myAmTurningWithAngle; 01176 NBEdge* myAmTurningOf; 01178 01180 bool myAmInnerEdge; 01181 01183 bool myAmMacroscopicConnector; 01184 01185 struct TLSDisabledConnection { 01186 int fromLane; 01187 NBEdge* to; 01188 int toLane; 01189 }; 01190 01191 std::vector<TLSDisabledConnection> myTLSDisabledConnections; 01192 01193 01195 std::string myStreetName; 01196 01197 01198 public: 01202 class tls_disable_finder { 01203 public: 01205 tls_disable_finder(const TLSDisabledConnection& tpl) : myDefinition(tpl) { } 01206 01207 bool operator()(const TLSDisabledConnection& e) const { 01208 if (e.to != myDefinition.to) { 01209 return false; 01210 } 01211 if (e.fromLane != myDefinition.fromLane) { 01212 return false; 01213 } 01214 if (e.toLane != myDefinition.toLane) { 01215 return false; 01216 } 01217 return true; 01218 } 01219 01220 private: 01221 TLSDisabledConnection myDefinition; 01222 01223 private: 01225 tls_disable_finder& operator=(const tls_disable_finder& s); 01226 01227 }; 01228 01229 01230 01234 class connections_toedge_finder { 01235 public: 01237 connections_toedge_finder(NBEdge* const edge2find) : myEdge2Find(edge2find) { } 01238 01239 bool operator()(const Connection& c) const { 01240 return c.toEdge == myEdge2Find; 01241 } 01242 01243 private: 01244 NBEdge* const myEdge2Find; 01245 01246 private: 01248 connections_toedge_finder& operator=(const connections_toedge_finder& s); 01249 01250 }; 01251 01255 class connections_toedgelane_finder { 01256 public: 01258 connections_toedgelane_finder(NBEdge* const edge2find, int lane2find) : myEdge2Find(edge2find), myLane2Find(lane2find) { } 01259 01260 bool operator()(const Connection& c) const { 01261 return c.toEdge == myEdge2Find && c.toLane == myLane2Find; 01262 } 01263 01264 private: 01265 NBEdge* const myEdge2Find; 01266 int myLane2Find; 01267 01268 private: 01270 connections_toedgelane_finder& operator=(const connections_toedgelane_finder& s); 01271 01272 }; 01273 01274 01278 class connections_finder { 01279 public: 01281 connections_finder(int fromLane, NBEdge* const edge2find, int lane2find) : myFromLane(fromLane), myEdge2Find(edge2find), myLane2Find(lane2find) { } 01282 01283 bool operator()(const Connection& c) const { 01284 return c.fromLane == myFromLane && c.toEdge == myEdge2Find && c.toLane == myLane2Find; 01285 } 01286 01287 private: 01288 int myFromLane; 01289 NBEdge* const myEdge2Find; 01290 int myLane2Find; 01291 01292 private: 01294 connections_finder& operator=(const connections_finder& s); 01295 01296 }; 01297 01301 class connections_fromlane_finder { 01302 public: 01304 connections_fromlane_finder(int lane2find) : myLane2Find(lane2find) { } 01305 01306 bool operator()(const Connection& c) const { 01307 return c.fromLane == myLane2Find; 01308 } 01309 01310 private: 01311 int myLane2Find; 01312 01313 private: 01315 connections_fromlane_finder& operator=(const connections_fromlane_finder& s); 01316 01317 }; 01318 01322 static bool connections_sorter(const Connection& c1, const Connection& c2) { 01323 if (c1.fromLane != c2.fromLane) { 01324 return c1.fromLane < c2.fromLane; 01325 } 01326 if (c1.toEdge != c2.toEdge) { 01327 return c1.toEdge->getID().compare(c1.toEdge->getID()) < 0; 01328 } 01329 return c1.toLane < c2.toLane; 01330 } 01331 01336 class connections_relative_edgelane_sorter { 01337 public: 01339 explicit connections_relative_edgelane_sorter(NBEdge* e, NBNode* n) 01340 : myEdge(e), myNode(n) {} 01341 01342 public: 01344 int operator()(const Connection& c1, const Connection& c2) const { 01345 if (c1.toEdge != c2.toEdge) { 01346 SUMOReal relAngle1 = NBHelpers::normRelAngle( 01347 myEdge->getAngle(), c1.toEdge->getAngle()); 01348 SUMOReal relAngle2 = NBHelpers::normRelAngle( 01349 myEdge->getAngle(), c2.toEdge->getAngle()); 01350 return relAngle1 > relAngle2; 01351 } 01352 return c1.toLane < c2.toLane; 01353 } 01354 01355 private: 01357 NBEdge* myEdge; 01358 01360 NBNode* myNode; 01361 01362 }; 01363 01364 private: 01366 NBEdge(const NBEdge& s); 01367 01369 NBEdge& operator=(const NBEdge& s); 01370 01371 01372 }; 01373 01374 01375 #endif 01376 01377 /****************************************************************************/ 01378