SUMO - Simulation of Urban MObility

MSLane.h

Go to the documentation of this file.
00001 /****************************************************************************/
00012 // Representation of a lane in the micro simulation
00013 /****************************************************************************/
00014 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00015 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00016 /****************************************************************************/
00017 //
00018 //   This file is part of SUMO.
00019 //   SUMO is free software: you can redistribute it and/or modify
00020 //   it under the terms of the GNU General Public License as published by
00021 //   the Free Software Foundation, either version 3 of the License, or
00022 //   (at your option) any later version.
00023 //
00024 /****************************************************************************/
00025 #ifndef MSLane_h
00026 #define MSLane_h
00027 
00028 
00029 // ===========================================================================
00030 // included modules
00031 // ===========================================================================
00032 #ifdef _MSC_VER
00033 #include <windows_config.h>
00034 #else
00035 #include <config.h>
00036 #endif
00037 
00038 #include "MSEdge.h"
00039 #include "MSLinkCont.h"
00040 #include "MSVehicle.h"
00041 #include <bitset>
00042 #include <deque>
00043 #include <vector>
00044 #include <utility>
00045 #include <map>
00046 #include <string>
00047 #include <iostream>
00048 #include "MSNet.h"
00049 #include <utils/geom/PositionVector.h>
00050 #include <utils/geom/Line.h>
00051 #include <utils/geom/GeomHelper.h>
00052 #include <utils/common/SUMOTime.h>
00053 #include <utils/common/SUMOVehicleClass.h>
00054 #include <utils/common/Named.h>
00055 
00056 
00057 // ===========================================================================
00058 // class declarations
00059 // ===========================================================================
00060 class MSLaneChanger;
00061 class MSLink;
00062 class MSMoveReminder;
00063 class GUILaneWrapper;
00064 class MSVehicleTransfer;
00065 class OutputDevice;
00066 
00067 
00068 // ===========================================================================
00069 // class definitions
00070 // ===========================================================================
00078 class MSLane : public Named {
00079 public:
00081     friend class MSLaneChanger;
00082 
00083     friend class GUILaneWrapper;
00084 
00085     friend class MSXMLRawOut;
00086 
00089     struct VehPosition : public std::binary_function < const MSVehicle*,
00090             SUMOReal, bool > {
00092         bool operator()(const MSVehicle* cmp, SUMOReal pos) const {
00093             return cmp->getPositionOnLane() >= pos;
00094         }
00095     };
00096 
00097 public:
00111     MSLane(const std::string& id, SUMOReal maxSpeed, SUMOReal length, MSEdge* const edge,
00112            unsigned int numericalID, const PositionVector& shape, SUMOReal width,
00113            const SUMOVehicleClasses& allowed,
00114            const SUMOVehicleClasses& disallowed) ;
00115 
00116 
00118     virtual ~MSLane() ;
00119 
00120 
00121 
00124 
00133     void initialize(MSLinkCont* succs);
00134 
00142     void addLink(MSLink* link);
00144 
00145 
00146 
00149 
00156     virtual void addMoveReminder(MSMoveReminder* rem) ;
00157 
00158 
00162     inline const std::vector< MSMoveReminder* > &getMoveReminders() const {
00163         return myMoveReminders;
00164     }
00166 
00167 
00168 
00171 
00187     bool insertVehicle(MSVehicle& v) ;
00188 
00189 
00207     virtual bool isInsertionSuccess(MSVehicle* vehicle, SUMOReal speed, SUMOReal pos,
00208                                     bool recheckNextLanes,
00209                                     MSMoveReminder::Notification notification = MSMoveReminder::NOTIFICATION_DEPARTED) ;
00210 
00211     bool pWagGenericInsertion(MSVehicle& veh, SUMOReal speed, SUMOReal maxPos, SUMOReal minPos) ;
00212     bool pWagSimpleInsertion(MSVehicle& veh, SUMOReal speed, SUMOReal maxPos, SUMOReal minPos) ;
00213     bool maxSpeedGapInsertion(MSVehicle& veh, SUMOReal mspeed) ;
00214 
00222     bool freeInsertion(MSVehicle& veh, SUMOReal speed,
00223                        MSMoveReminder::Notification notification = MSMoveReminder::NOTIFICATION_DEPARTED) ;
00224 
00225 
00233     void forceVehicleInsertion(MSVehicle* veh, SUMOReal pos) ;
00235 
00236 
00237 
00240 
00252     SUMOReal setPartialOccupation(MSVehicle* v, SUMOReal leftVehicleLength) ;
00253 
00254 
00258     void resetPartialOccupation(MSVehicle* v) ;
00259 
00260 
00264     MSVehicle* getPartialOccupator() const {
00265         return myInlappingVehicle;
00266     }
00267 
00268 
00272     SUMOReal getPartialOccupatorEnd() const {
00273         return myInlappingVehicleEnd;
00274     }
00275 
00276 
00285     std::pair<MSVehicle*, SUMOReal> getLastVehicleInformation() const ;
00287 
00288 
00289 
00292 
00296     unsigned int getVehicleNumber() const {
00297         return (unsigned int) myVehicles.size();
00298     }
00299 
00300 
00307     virtual const std::deque< MSVehicle* > &getVehiclesSecure() const {
00308         return myVehicles;
00309     }
00310 
00311 
00314     virtual void releaseVehicles() const { }
00316 
00317 
00318 
00321 
00322 
00326     size_t getNumericalID() const {
00327         return myNumericalID;
00328     }
00329 
00330 
00334     const PositionVector& getShape() const {
00335         return myShape;
00336     }
00337 
00338 
00342     SUMOReal getMaxSpeed() const {
00343         return myMaxSpeed;
00344     }
00345 
00346 
00350     SUMOReal getLength() const {
00351         return myLength;
00352     }
00353 
00354 
00358     const SUMOVehicleClasses& getAllowedClasses() const {
00359         return myAllowedClasses;
00360     }
00361 
00362 
00366     const SUMOVehicleClasses& getNotAllowedClasses() const {
00367         return myNotAllowedClasses;
00368     }
00369 
00370 
00374     SUMOReal getWidth() const {
00375         return myWidth;
00376     }
00378 
00379 
00380 
00383 
00384     virtual bool moveCritical(SUMOTime t);
00385 
00388     virtual bool setCritical(SUMOTime t, std::vector<MSLane*> &into);
00389 
00391     virtual bool integrateNewVehicle(SUMOTime t);
00393 
00394 
00395 
00397     virtual void detectCollisions(SUMOTime timestep);
00398 
00399 
00402     virtual bool appropriate(const MSVehicle* veh);
00403 
00404 
00406     const MSLinkCont& getLinkCont() const;
00407 
00408 
00410     bool empty() const {
00411         assert(myVehBuffer.size() == 0);
00412         return myVehicles.empty();
00413     }
00414 
00415     void setMaxSpeed(SUMOReal val) {
00416         myMaxSpeed = val;
00417     }
00418 
00419     void setLength(SUMOReal val) {
00420         myLength = val;
00421     }
00422 
00423 
00427     MSEdge& getEdge() const {
00428         return *myEdge;
00429     }
00430 
00434     static bool dictionary(std::string id, MSLane* lane);
00435 
00438     static MSLane* dictionary(std::string id);
00439 
00441     static void clear();
00442 
00443     static size_t dictSize() {
00444         return myDict.size();
00445     }
00446 
00447     static void insertIDs(std::vector<std::string> &into) ;
00448 
00450     typedef std::deque< MSVehicle* > VehCont;
00451 
00456     virtual MSLinkCont::const_iterator succLinkSec(const SUMOVehicle& veh,
00457             unsigned int nRouteSuccs,
00458             const MSLane& succLinkSource,
00459             const std::vector<MSLane*> &conts) const;
00460 
00461 
00464     bool isLinkEnd(MSLinkCont::const_iterator& i) const;
00465 
00468     bool isLinkEnd(MSLinkCont::iterator& i);
00469 
00471     virtual MSVehicle* getLastVehicle() const;
00472     virtual const MSVehicle* getFirstVehicle() const;
00473 
00474 
00475 
00476 
00477     // valid for gui-version only
00478     virtual GUILaneWrapper* buildLaneWrapper(unsigned int index);
00479 
00480     virtual MSVehicle* removeVehicle(MSVehicle* remVehicle);
00481 
00483     PositionVector myShape;
00484 
00485 
00486 
00487     void leftByLaneChange(MSVehicle* v);
00488     void enteredByLaneChange(MSVehicle* v);
00489 
00490 
00491     MSLane* getLeftLane() const;
00492     MSLane* getRightLane() const;
00493 
00494     void setAllowedClasses(const SUMOVehicleClasses& classes) {
00495         myAllowedClasses = classes;
00496     }
00497 
00498 
00499     void setNotAllowedClasses(const SUMOVehicleClasses& classes) {
00500         myNotAllowedClasses = classes;
00501     }
00502 
00503 
00504     bool allowsVehicleClass(SUMOVehicleClass vclass) const;
00505 
00506     void addIncomingLane(MSLane* lane, MSLink* viaLink);
00507 
00508 
00509     struct IncomingLaneInfo {
00510         MSLane* lane;
00511         SUMOReal length;
00512         MSLink* viaLink;
00513     };
00514 
00515     const std::vector<IncomingLaneInfo> &getIncomingLanes() const {
00516         return myIncomingLanes;
00517     }
00518 
00519 
00520     void addApproachingLane(MSLane* lane);
00521     bool isApproachedFrom(MSEdge* const edge);
00522     bool isApproachedFrom(MSEdge* const edge, MSLane* const lane);
00523 
00524 
00525 
00526     std::pair<MSVehicle* const, SUMOReal> getFollowerOnConsecutive(SUMOReal dist, SUMOReal seen,
00527             SUMOReal leaderSpeed, SUMOReal backOffset, SUMOReal predMaxDecel) const;
00528 
00529 
00552     std::pair<MSVehicle* const, SUMOReal> getLeaderOnConsecutive(SUMOReal dist, SUMOReal seen,
00553             SUMOReal speed, const MSVehicle& veh, const std::vector<MSLane*> &bestLaneConts) const ;
00554 
00555 
00556     MSLane* getLogicalPredecessorLane() const ;
00557 
00558 
00560 
00561 
00565     SUMOReal getMeanSpeed() const ;
00566 
00567 
00571     SUMOReal getOccupancy() const ;
00572 
00573 
00577     SUMOReal getVehLenSum() const ;
00578 
00579 
00583     SUMOReal getHBEFA_CO2Emissions() const ;
00584 
00585 
00589     SUMOReal getHBEFA_COEmissions() const ;
00590 
00591 
00595     SUMOReal getHBEFA_PMxEmissions() const ;
00596 
00597 
00601     SUMOReal getHBEFA_NOxEmissions() const ;
00602 
00603 
00607     SUMOReal getHBEFA_HCEmissions() const ;
00608 
00609 
00613     SUMOReal getHBEFA_FuelConsumption() const ;
00614 
00615 
00619     SUMOReal getHarmonoise_NoiseEmissions() const ;
00621 
00622 
00623 protected:
00625     virtual void swapAfterLaneChange(SUMOTime t);
00626 
00637     virtual void incorporateVehicle(MSVehicle* veh, SUMOReal pos, SUMOReal speed,
00638                                     const MSLane::VehCont::iterator& at,
00639                                     MSMoveReminder::Notification notification = MSMoveReminder::NOTIFICATION_DEPARTED) ;
00640 
00641 
00642 protected:
00644     size_t myNumericalID;
00645 
00653     VehCont myVehicles;
00654 
00656     SUMOReal myLength;
00657 
00659     SUMOReal myWidth;
00660 
00662     MSEdge* myEdge;
00663 
00665     SUMOReal myMaxSpeed;
00666 
00669     VehCont myTmpVehicles;
00670 
00671 
00672     SUMOReal myBackDistance;
00673 
00678     std::vector<MSVehicle*> myVehBuffer;
00679 
00681     SUMOVehicleClasses myAllowedClasses;
00682 
00684     SUMOVehicleClasses myNotAllowedClasses;
00685 
00686     std::vector<IncomingLaneInfo> myIncomingLanes;
00687     mutable MSLane* myLogicalPredecessorLane;
00688 
00689 
00691     SUMOReal myVehicleLengthSum;
00692 
00694     SUMOReal myInlappingVehicleEnd;
00695 
00697     MSVehicle* myInlappingVehicle;
00698 
00699 
00701     SUMOReal myLeftVehLength;
00702 
00705     MSLinkCont myLinks;
00706 
00707     std::map<MSEdge*, std::vector<MSLane*> > myApproachingLanes;
00708 
00709 
00710 
00712     typedef std::map< std::string, MSLane* > DictType;
00713 
00715     static DictType myDict;
00716 
00717 private:
00719     std::vector< MSMoveReminder* > myMoveReminders;
00720 
00721 
00726     class vehicle_position_sorter {
00727     public:
00729         explicit vehicle_position_sorter() { }
00730 
00731 
00737         int operator()(MSVehicle* v1, MSVehicle* v2) const {
00738             return v1->getPositionOnLane() > v2->getPositionOnLane();
00739         }
00740 
00741     };
00742 
00746     class by_connections_to_sorter {
00747     public:
00749         explicit by_connections_to_sorter(const MSEdge* const e)
00750             : myEdge(e), myLaneDir(e->getLanes()[0]->getShape().getBegLine().atan2PositiveAngle()) { }
00751 
00753         int operator()(const MSEdge* const e1, const MSEdge* const e2) const {
00754             const std::vector<MSLane*>* ae1 = e1->allowedLanes(*myEdge);
00755             const std::vector<MSLane*>* ae2 = e2->allowedLanes(*myEdge);
00756             SUMOReal s1 = 0;
00757             if (ae1 != 0 && ae1->size() != 0) {
00758                 s1 = (SUMOReal) ae1->size() + GeomHelper::getMinAngleDiff((*ae1)[0]->getShape().getBegLine().atan2PositiveAngle(), myLaneDir) / PI / 2.;
00759             }
00760             SUMOReal s2 = 0;
00761             if (ae2 != 0 && ae2->size() != 0) {
00762                 s2 = (SUMOReal) ae2->size() + GeomHelper::getMinAngleDiff((*ae2)[0]->getShape().getBegLine().atan2PositiveAngle(), myLaneDir) / PI / 2.;
00763             }
00764             return s1 < s2;
00765         }
00766 
00767     private:
00768         by_connections_to_sorter& operator=(const by_connections_to_sorter&); // just to avoid a compiler warning
00769     private:
00770         const MSEdge* const myEdge;
00771         SUMOReal myLaneDir;
00772     };
00773 
00777     class edge_finder {
00778     public:
00779         edge_finder(MSEdge* e) : myEdge(e) {}
00780         bool operator()(const IncomingLaneInfo& ili) const {
00781             return &(ili.lane->getEdge()) == myEdge;
00782         }
00783     private:
00784         edge_finder& operator=(const edge_finder&); // just to avoid a compiler warning
00785     private:
00786         const MSEdge* const myEdge;
00787     };
00788 
00789 private:
00791     MSLane(const MSLane&);
00792 
00794     MSLane& operator=(const MSLane&);
00795 
00796 
00797 };
00798 
00799 
00800 #endif
00801 
00802 /****************************************************************************/
00803 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines