SUMO - Simulation of Urban MObility

MSEdge.h

Go to the documentation of this file.
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/SUMOVehicleClass.h>
00043 #include <utils/common/ValueTimeLine.h>
00044 #include <utils/common/UtilExceptions.h>
00045 
00046 
00047 // ===========================================================================
00048 // class declarations
00049 // ===========================================================================
00050 class MSLane;
00051 class MSLaneChanger;
00052 class OutputDevice;
00053 class SUMOVehicle;
00054 class SUMOVehicleParameter;
00055 class MSVehicle;
00056 
00057 
00058 // ===========================================================================
00059 // class definitions
00060 // ===========================================================================
00068 class MSEdge {
00069 public:
00077     enum EdgeBasicFunction {
00079         EDGEFUNCTION_UNKNOWN = -1,
00081         EDGEFUNCTION_NORMAL = 0,
00083         EDGEFUNCTION_CONNECTOR = 1,
00085         EDGEFUNCTION_INTERNAL = 2,
00087         EDGEFUNCTION_DISTRICT = 3
00088     };
00089 
00090 
00092     typedef std::map< const MSEdge*, std::vector<MSLane*>* > AllowedLanesCont;
00093 
00095     typedef std::map< SUMOVehicleClass, AllowedLanesCont > ClassedAllowedLanesCont;
00096 
00097 
00098 public:
00109     MSEdge(const std::string& id, unsigned int numericalID, const std::string& streetName = "") ;
00110 
00111 
00113     virtual ~MSEdge() ;
00114 
00115 
00122     void initialize(std::vector<MSLane*>* lanes, EdgeBasicFunction function) ;
00123 
00124 
00126     void closeBuilding();
00127 
00128 
00131 
00138     MSLane* leftLane(const MSLane* const lane) const ;
00139 
00140 
00147     MSLane* rightLane(const MSLane* const lane) const ;
00148 
00149 
00154     const std::vector<MSLane*> &getLanes() const {
00155         return *myLanes;
00156     }
00157 
00158 
00167     const std::vector<MSLane*>* allowedLanes(const MSEdge& destination,
00168             SUMOVehicleClass vclass = SVC_UNKNOWN) const ;
00169 
00170 
00178     const std::vector<MSLane*>* allowedLanes(SUMOVehicleClass vclass = SVC_UNKNOWN) const ;
00180 
00181 
00182 
00185 
00189     const std::string& getID() const {
00190         return myID;
00191     }
00192 
00193 
00198     EdgeBasicFunction getPurpose() const {
00199         return myFunction;
00200     }
00201 
00202 
00206     unsigned int getNumericalID() const {
00207         return myNumericalID;
00208     }
00209 
00210 
00213     const std::string& getStreetName() const {
00214         return myStreetName;
00215     }
00217 
00218 
00219 
00222 
00226     void addFollower(MSEdge* edge) {
00227         mySuccessors.push_back(edge);
00228     }
00229 
00230 
00234     const std::vector<MSEdge*> &getIncomingEdges() const {
00235         return myPredeccesors;
00236     }
00237 
00238 
00242     unsigned int getNoFollowing() const {
00243         return (unsigned int) mySuccessors.size();
00244     }
00245 
00250     const MSEdge* getFollower(unsigned int n) const {
00251         return mySuccessors[n];
00252     }
00254 
00255 
00256 
00259 
00263     bool isVaporizing() const {
00264         return myVaporizationRequests > 0;
00265     }
00266 
00267 
00277     SUMOTime incVaporization(SUMOTime t) ;
00278 
00279 
00289     SUMOTime decVaporization(SUMOTime t) ;
00291 
00292 
00301     SUMOReal getCurrentTravelTime() const ;
00302 
00303 
00304 
00307 
00321     bool insertVehicle(SUMOVehicle& v, SUMOTime time) const ;
00322 
00323 
00338     MSLane* getFreeLane(const std::vector<MSLane*>* allowed, const SUMOVehicleClass vclass) const ;
00339 
00340 
00351     MSLane* getDepartLane(const MSVehicle& veh) const ;
00352 
00353 
00357     inline SUMOTime getLastFailedInsertionTime() const {
00358         return myLastFailedInsertionTime;
00359     }
00360 
00361 
00365     inline void setLastFailedInsertionTime(SUMOTime time) const {
00366         myLastFailedInsertionTime = time;
00367     }
00369 
00370 
00372     virtual void changeLanes(SUMOTime t) ;
00373 
00374 
00375 #ifdef HAVE_INTERNAL_LANES
00376 
00377     const MSEdge* getInternalFollowingEdge(MSEdge* followerAfterInternal) const ;
00378 #endif
00379 
00381     bool prohibits(const SUMOVehicle* const vehicle) const ;
00382 
00383     void rebuildAllowedLanes() ;
00384 
00385 
00386 
00390     static bool dictionary(const std::string& id, MSEdge* edge) ;
00391 
00393     static MSEdge* dictionary(const std::string& id) ;
00394 
00396     static MSEdge* dictionary(size_t index) ;
00397 
00399     static size_t dictSize() ;
00400 
00402     static void clear() ;
00403 
00405     static void insertIDs(std::vector<std::string> &into) ;
00406 
00407 
00408 public:
00411 
00420     static void parseEdgesList(const std::string& desc, std::vector<const MSEdge*> &into,
00421                                const std::string& rid) ;
00422 
00423 
00430     static void parseEdgesList(const std::vector<std::string> &desc, std::vector<const MSEdge*> &into,
00431                                const std::string& rid) ;
00433 
00434 
00435 protected:
00439     class by_id_sorter {
00440     public:
00442         explicit by_id_sorter() { }
00443 
00445         int operator()(const MSEdge* const e1, const MSEdge* const e2) const {
00446             return e1->getID() < e2->getID();
00447         }
00448 
00449     };
00450 
00451 
00460     const std::vector<MSLane*>* allowedLanes(const MSEdge* destination,
00461             SUMOVehicleClass vclass = SVC_UNKNOWN) const ;
00462 
00463 protected:
00465     std::string myID;
00466 
00468     unsigned int myNumericalID;
00469 
00471     std::vector<MSLane*>* myLanes;
00472 
00474     MSLaneChanger* myLaneChanger;
00475 
00477     EdgeBasicFunction myFunction;
00478 
00480     int myVaporizationRequests;
00481 
00483     mutable SUMOTime myLastFailedInsertionTime;
00484 
00486     std::vector<MSEdge*> mySuccessors;
00487 
00489     std::vector<MSEdge*> myPredeccesors;
00490 
00491 
00492 
00495 
00497     AllowedLanesCont myAllowed;
00498 
00500     ClassedAllowedLanesCont myClassedAllowed;
00501 
00503     bool myHaveClassConstraints;
00504 
00505     std::string myStreetName;
00507 
00508 
00509 
00512 
00514     typedef std::map< std::string, MSEdge* > DictType;
00515 
00519     static DictType myDict;
00520 
00524     static std::vector<MSEdge*> myEdges;
00526 
00527 
00528 
00529 private:
00531     MSEdge(const MSEdge&);
00532 
00534     MSEdge& operator=(const MSEdge&);
00535 
00536 };
00537 
00538 
00539 #endif
00540 
00541 /****************************************************************************/
00542 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines