SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00011 // A road/street connecting two junctions 00012 /****************************************************************************/ 00013 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00014 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00015 /****************************************************************************/ 00016 // 00017 // This file is part of SUMO. 00018 // SUMO is free software: you can redistribute it and/or modify 00019 // it under the terms of the GNU General Public License as published by 00020 // the Free Software Foundation, either version 3 of the License, or 00021 // (at your option) any later version. 00022 // 00023 /****************************************************************************/ 00024 #ifndef MSEdge_h 00025 #define MSEdge_h 00026 00027 00028 // =========================================================================== 00029 // included modules 00030 // =========================================================================== 00031 #ifdef _MSC_VER 00032 #include <windows_config.h> 00033 #else 00034 #include <config.h> 00035 #endif 00036 00037 #include <vector> 00038 #include <map> 00039 #include <string> 00040 #include <iostream> 00041 #include <utils/common/SUMOTime.h> 00042 #include <utils/common/SUMOVehicle.h> 00043 #include <utils/common/SUMOVehicleClass.h> 00044 #include <utils/common/ValueTimeLine.h> 00045 #include <utils/common/UtilExceptions.h> 00046 #include "MSVehicleType.h" 00047 00048 00049 // =========================================================================== 00050 // class declarations 00051 // =========================================================================== 00052 class MSLaneChanger; 00053 class OutputDevice; 00054 class SUMOVehicle; 00055 class SUMOVehicleParameter; 00056 class MSVehicle; 00057 class MSLane; 00058 00059 00060 // =========================================================================== 00061 // class definitions 00062 // =========================================================================== 00070 class MSEdge { 00071 public: 00079 enum EdgeBasicFunction { 00081 EDGEFUNCTION_UNKNOWN = -1, 00083 EDGEFUNCTION_NORMAL = 0, 00085 EDGEFUNCTION_CONNECTOR = 1, 00087 EDGEFUNCTION_INTERNAL = 2, 00089 EDGEFUNCTION_DISTRICT = 3 00090 }; 00091 00092 00094 typedef std::map< const MSEdge*, std::vector<MSLane*>* > AllowedLanesCont; 00095 00097 typedef std::map< SUMOVehicleClass, AllowedLanesCont > ClassedAllowedLanesCont; 00098 00099 00100 public: 00111 MSEdge(const std::string& id, unsigned int numericalID, const std::string& streetName = "") ; 00112 00113 00115 virtual ~MSEdge() ; 00116 00117 00124 void initialize(std::vector<MSLane*>* lanes, EdgeBasicFunction function) ; 00125 00126 00128 void closeBuilding(); 00129 00130 00133 00140 MSLane* leftLane(const MSLane* const lane) const ; 00141 00142 00149 MSLane* rightLane(const MSLane* const lane) const ; 00150 00151 00156 const std::vector<MSLane*> &getLanes() const { 00157 return *myLanes; 00158 } 00159 00160 00169 const std::vector<MSLane*>* allowedLanes(const MSEdge& destination, 00170 SUMOVehicleClass vclass = SVC_UNKNOWN) const ; 00171 00172 00180 const std::vector<MSLane*>* allowedLanes(SUMOVehicleClass vclass = SVC_UNKNOWN) const ; 00182 00183 00184 00187 00191 const std::string& getID() const { 00192 return myID; 00193 } 00194 00195 00200 EdgeBasicFunction getPurpose() const { 00201 return myFunction; 00202 } 00203 00204 00208 unsigned int getNumericalID() const { 00209 return myNumericalID; 00210 } 00211 00212 00215 const std::string& getStreetName() const { 00216 return myStreetName; 00217 } 00219 00220 00221 00224 00228 void addFollower(MSEdge* edge) { 00229 mySuccessors.push_back(edge); 00230 } 00231 00232 00236 const std::vector<MSEdge*> &getIncomingEdges() const { 00237 return myPredeccesors; 00238 } 00239 00240 00244 unsigned int getNoFollowing() const { 00245 return (unsigned int) mySuccessors.size(); 00246 } 00247 00252 const MSEdge* getFollower(unsigned int n) const { 00253 return mySuccessors[n]; 00254 } 00256 00257 00258 00261 00265 bool isVaporizing() const { 00266 return myVaporizationRequests > 0; 00267 } 00268 00269 00279 SUMOTime incVaporization(SUMOTime t) ; 00280 00281 00291 SUMOTime decVaporization(SUMOTime t) ; 00293 00294 00303 SUMOReal getCurrentTravelTime() const ; 00304 00305 00306 00309 00323 bool insertVehicle(SUMOVehicle& v, SUMOTime time) const ; 00324 00325 00340 MSLane* getFreeLane(const std::vector<MSLane*>* allowed, const SUMOVehicleClass vclass) const ; 00341 00342 00353 MSLane* getDepartLane(const MSVehicle& veh) const ; 00354 00355 00359 inline SUMOTime getLastFailedInsertionTime() const { 00360 return myLastFailedInsertionTime; 00361 } 00362 00363 00367 inline void setLastFailedInsertionTime(SUMOTime time) const { 00368 myLastFailedInsertionTime = time; 00369 } 00371 00372 00374 virtual void changeLanes(SUMOTime t) ; 00375 00376 00377 #ifdef HAVE_INTERNAL_LANES 00378 00379 const MSEdge* getInternalFollowingEdge(MSEdge* followerAfterInternal) const ; 00380 #endif 00381 00383 inline bool prohibits(const SUMOVehicle* const vehicle) const { 00384 const SUMOVehicleClass svc = vehicle->getVehicleType().getVehicleClass(); 00385 return (myCombinedPermissions & svc) != svc; 00386 } 00387 00388 void rebuildAllowedLanes(); 00389 00390 00392 SUMOReal getDistanceTo(const MSEdge* other) const; 00393 00394 00396 SUMOReal getLength() const; 00397 00399 SUMOReal getMaxSpeed() const; 00400 00404 static bool dictionary(const std::string& id, MSEdge* edge) ; 00405 00407 static MSEdge* dictionary(const std::string& id) ; 00408 00410 static MSEdge* dictionary(size_t index) ; 00411 00413 static size_t dictSize() ; 00414 00416 static void clear() ; 00417 00419 static void insertIDs(std::vector<std::string> &into) ; 00420 00421 00422 public: 00425 00434 static void parseEdgesList(const std::string& desc, std::vector<const MSEdge*> &into, 00435 const std::string& rid) ; 00436 00437 00444 static void parseEdgesList(const std::vector<std::string> &desc, std::vector<const MSEdge*> &into, 00445 const std::string& rid) ; 00447 00448 00449 protected: 00453 class by_id_sorter { 00454 public: 00456 explicit by_id_sorter() { } 00457 00459 int operator()(const MSEdge* const e1, const MSEdge* const e2) const { 00460 return e1->getID() < e2->getID(); 00461 } 00462 00463 }; 00464 00465 00474 const std::vector<MSLane*>* allowedLanes(const MSEdge* destination, 00475 SUMOVehicleClass vclass = SVC_UNKNOWN) const ; 00476 00477 00479 const std::vector<MSLane*>* getAllowedLanesWithDefault(const AllowedLanesCont& c, const MSEdge* dest) const; 00480 00481 protected: 00483 std::string myID; 00484 00486 unsigned int myNumericalID; 00487 00489 std::vector<MSLane*>* myLanes; 00490 00492 MSLaneChanger* myLaneChanger; 00493 00495 EdgeBasicFunction myFunction; 00496 00498 int myVaporizationRequests; 00499 00501 mutable SUMOTime myLastFailedInsertionTime; 00502 00504 std::vector<MSEdge*> mySuccessors; 00505 00507 std::vector<MSEdge*> myPredeccesors; 00508 00509 00510 00513 00515 AllowedLanesCont myAllowed; 00516 00518 // @note: this map is filled on demand 00519 mutable ClassedAllowedLanesCont myClassedAllowed; 00520 00522 SVCPermissions myMinimumPermissions; 00524 SVCPermissions myCombinedPermissions; 00525 00526 std::string myStreetName; 00528 00529 00530 00533 00535 typedef std::map< std::string, MSEdge* > DictType; 00536 00540 static DictType myDict; 00541 00545 static std::vector<MSEdge*> myEdges; 00547 00548 00549 00550 private: 00552 MSEdge(const MSEdge&); 00553 00555 MSEdge& operator=(const MSEdge&); 00556 00557 }; 00558 00559 00560 #endif 00561 00562 /****************************************************************************/ 00563