SUMO - Simulation of Urban MObility

MSEdge.h

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // A road/street connecting two junctions
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This program is free software; you can redistribute it and/or modify
00014 //   it under the terms of the GNU General Public License as published by
00015 //   the Free Software Foundation; either version 2 of the License, or
00016 //   (at your option) any later version.
00017 //
00018 /****************************************************************************/
00019 #ifndef MSEdge_h
00020 #define MSEdge_h
00021 
00022 
00023 // ===========================================================================
00024 // included modules
00025 // ===========================================================================
00026 #ifdef _MSC_VER
00027 #include <windows_config.h>
00028 #else
00029 #include <config.h>
00030 #endif
00031 
00032 #include <vector>
00033 #include <map>
00034 #include <string>
00035 #include <iostream>
00036 #include <utils/common/SUMOTime.h>
00037 #include <utils/common/SUMOVehicleClass.h>
00038 #include <utils/common/ValueTimeLine.h>
00039 #include <utils/common/UtilExceptions.h>
00040 
00041 
00042 // ===========================================================================
00043 // class declarations
00044 // ===========================================================================
00045 class MSLane;
00046 class MSLaneChanger;
00047 class OutputDevice;
00048 class SUMOVehicle;
00049 class SUMOVehicleParameter;
00050 class MSVehicle;
00051 
00052 
00053 // ===========================================================================
00054 // class definitions
00055 // ===========================================================================
00063 class MSEdge {
00064 public:
00072     enum EdgeBasicFunction {
00074         EDGEFUNCTION_UNKNOWN = -1,
00076         EDGEFUNCTION_NORMAL = 0,
00078         EDGEFUNCTION_CONNECTOR = 1,
00080         EDGEFUNCTION_INTERNAL = 2,
00082         EDGEFUNCTION_DISTRICT = 3
00083     };
00084 
00085 
00087     typedef std::map< const MSEdge*, std::vector<MSLane*>* > AllowedLanesCont;
00088 
00090     typedef std::map< SUMOVehicleClass, AllowedLanesCont > ClassedAllowedLanesCont;
00091 
00092 
00093 public:
00104     MSEdge(const std::string& id, unsigned int numericalID, const std::string& streetName="") throw();
00105 
00106 
00108     virtual ~MSEdge() throw();
00109 
00110 
00117     void initialize(std::vector<MSLane*>* lanes, EdgeBasicFunction function) throw();
00118 
00119 
00121     void closeBuilding();
00122 
00123 
00126 
00133     MSLane* leftLane(const MSLane* const lane) const throw();
00134 
00135 
00142     MSLane* rightLane(const MSLane* const lane) const throw();
00143 
00144 
00149     const std::vector<MSLane*> &getLanes() const throw() {
00150         return *myLanes;
00151     }
00152 
00153 
00162     const std::vector<MSLane*>* allowedLanes(const MSEdge& destination,
00163             SUMOVehicleClass vclass=SVC_UNKNOWN) const throw();
00164 
00165 
00173     const std::vector<MSLane*>* allowedLanes(SUMOVehicleClass vclass=SVC_UNKNOWN) const throw();
00175 
00176 
00177 
00180 
00184     const std::string& getID() const throw() {
00185         return myID;
00186     }
00187 
00188 
00193     EdgeBasicFunction getPurpose() const throw() {
00194         return myFunction;
00195     }
00196 
00197 
00201     unsigned int getNumericalID() const throw() {
00202         return myNumericalID;
00203     }
00204 
00205 
00208     const std::string& getStreetName() const {
00209         return myStreetName;
00210     }
00212 
00213 
00214 
00217 
00221     void addFollower(MSEdge* edge) throw() {
00222         mySuccessors.push_back(edge);
00223     }
00224 
00225 
00229     const std::vector<MSEdge*> &getIncomingEdges() const throw() {
00230         return myPredeccesors;
00231     }
00232 
00233 
00237     unsigned int getNoFollowing() const throw() {
00238         return (unsigned int) mySuccessors.size();
00239     }
00240 
00245     const MSEdge* getFollower(unsigned int n) const throw() {
00246         return mySuccessors[n];
00247     }
00249 
00250 
00251 
00254 
00258     bool isVaporizing() const throw() {
00259         return myVaporizationRequests>0;
00260     }
00261 
00262 
00272     SUMOTime incVaporization(SUMOTime t) throw(ProcessError);
00273 
00274 
00284     SUMOTime decVaporization(SUMOTime t) throw(ProcessError);
00286 
00287 
00296     SUMOReal getCurrentTravelTime() const throw();
00297 
00298 
00299 
00302 
00316     bool insertVehicle(SUMOVehicle& v, SUMOTime time) const throw(ProcessError);
00317 
00318 
00333     MSLane* getFreeLane(const std::vector<MSLane*>* allowed, const SUMOVehicleClass vclass) const throw();
00334 
00335 
00346     MSLane* getDepartLane(const MSVehicle& veh) const throw();
00347 
00348 
00352     inline SUMOTime getLastFailedInsertionTime() const throw() {
00353         return myLastFailedInsertionTime;
00354     }
00355 
00356 
00360     inline void setLastFailedInsertionTime(SUMOTime time) const throw() {
00361         myLastFailedInsertionTime = time;
00362     }
00364 
00365 
00367     virtual void changeLanes(SUMOTime t) throw();
00368 
00369 
00370 #ifdef HAVE_INTERNAL_LANES
00371 
00372     const MSEdge* getInternalFollowingEdge(MSEdge* followerAfterInternal) const throw();
00373 #endif
00374 
00376     bool prohibits(const SUMOVehicle* const vehicle) const throw();
00377 
00378     void rebuildAllowedLanes() throw();
00379 
00380 
00381 
00385     static bool dictionary(const std::string& id, MSEdge* edge) throw();
00386 
00388     static MSEdge* dictionary(const std::string& id) throw();
00389 
00391     static MSEdge* dictionary(size_t index) throw();
00392 
00394     static size_t dictSize() throw();
00395 
00397     static void clear() throw();
00398 
00400     static void insertIDs(std::vector<std::string> &into) throw();
00401 
00402 
00403 public:
00406 
00415     static void parseEdgesList(const std::string& desc, std::vector<const MSEdge*> &into,
00416                                const std::string& rid) throw(ProcessError);
00417 
00418 
00425     static void parseEdgesList(const std::vector<std::string> &desc, std::vector<const MSEdge*> &into,
00426                                const std::string& rid) throw(ProcessError);
00428 
00429 
00430 protected:
00434     class by_id_sorter {
00435     public:
00437         explicit by_id_sorter() { }
00438 
00440         int operator()(const MSEdge* const e1, const MSEdge* const e2) const {
00441             return e1->getID()<e2->getID();
00442         }
00443 
00444     };
00445 
00446 
00455     const std::vector<MSLane*>* allowedLanes(const MSEdge* destination,
00456             SUMOVehicleClass vclass=SVC_UNKNOWN) const throw();
00457 
00458 protected:
00460     std::string myID;
00461 
00463     unsigned int myNumericalID;
00464 
00466     std::vector<MSLane*>* myLanes;
00467 
00469     MSLaneChanger* myLaneChanger;
00470 
00472     EdgeBasicFunction myFunction;
00473 
00475     int myVaporizationRequests;
00476 
00478     mutable SUMOTime myLastFailedInsertionTime;
00479 
00481     std::vector<MSEdge*> mySuccessors;
00482 
00484     std::vector<MSEdge*> myPredeccesors;
00485 
00486 
00487 
00490 
00492     AllowedLanesCont myAllowed;
00493 
00495     ClassedAllowedLanesCont myClassedAllowed;
00496 
00498     bool myHaveClassConstraints;
00499 
00500     std::string myStreetName;
00502 
00503 
00504 
00507 
00509     typedef std::map< std::string, MSEdge* > DictType;
00510 
00514     static DictType myDict;
00515 
00519     static std::vector<MSEdge*> myEdges;
00521 
00522 
00523 
00524 private:
00526     MSEdge(const MSEdge&);
00527 
00529     MSEdge& operator=(const MSEdge&);
00530 
00531 };
00532 
00533 
00534 #endif
00535 
00536 /****************************************************************************/
00537 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines