SUMO - Simulation of Urban MObility

MSLane.h

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Representation of a lane in the micro simulation
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 MSLane_h
00020 #define MSLane_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 "MSEdge.h"
00033 #include "MSLinkCont.h"
00034 #include "MSVehicle.h"
00035 #include <bitset>
00036 #include <deque>
00037 #include <vector>
00038 #include <utility>
00039 #include <map>
00040 #include <string>
00041 #include <iostream>
00042 #include "MSNet.h"
00043 #include <utils/geom/PositionVector.h>
00044 #include <utils/geom/Line.h>
00045 #include <utils/geom/GeomHelper.h>
00046 #include <utils/common/SUMOTime.h>
00047 #include <utils/common/SUMOVehicleClass.h>
00048 #include <utils/common/Named.h>
00049 
00050 
00051 // ===========================================================================
00052 // class declarations
00053 // ===========================================================================
00054 class MSLaneChanger;
00055 class MSLink;
00056 class MSMoveReminder;
00057 class GUILaneWrapper;
00058 class MSVehicleTransfer;
00059 class OutputDevice;
00060 
00061 
00062 // ===========================================================================
00063 // class definitions
00064 // ===========================================================================
00072 class MSLane : public Named {
00073 public:
00075     friend class MSLaneChanger;
00076 
00077     friend class GUILaneWrapper;
00078 
00079     friend class MSXMLRawOut;
00080 
00083     struct VehPosition : public std::binary_function< const MSVehicle*,
00084             SUMOReal, bool > {
00086         bool operator()(const MSVehicle* cmp, SUMOReal pos) const {
00087             return cmp->getPositionOnLane() >= pos;
00088         }
00089     };
00090 
00091 public:
00105     MSLane(const std::string& id, SUMOReal maxSpeed, SUMOReal length, MSEdge* const edge,
00106            unsigned int numericalID, const PositionVector& shape, SUMOReal width,
00107            const SUMOVehicleClasses& allowed,
00108            const SUMOVehicleClasses& disallowed) throw();
00109 
00110 
00112     virtual ~MSLane() throw();
00113 
00114 
00115 
00118 
00127     void initialize(MSLinkCont* succs);
00128 
00136     void addLink(MSLink* link);
00138 
00139 
00140 
00143 
00150     virtual void addMoveReminder(MSMoveReminder* rem) throw();
00151 
00152 
00156     inline const std::vector< MSMoveReminder* > &getMoveReminders() const throw() {
00157         return myMoveReminders;
00158     }
00160 
00161 
00162 
00165 
00181     bool insertVehicle(MSVehicle& v) throw(ProcessError);
00182 
00183 
00201     virtual bool isInsertionSuccess(MSVehicle* vehicle, SUMOReal speed, SUMOReal pos,
00202                                     bool recheckNextLanes,
00203                                     MSMoveReminder::Notification notification = MSMoveReminder::NOTIFICATION_DEPARTED) throw(ProcessError);
00204 
00205     bool pWagGenericInsertion(MSVehicle& veh, SUMOReal speed, SUMOReal maxPos, SUMOReal minPos) throw();
00206     bool pWagSimpleInsertion(MSVehicle& veh, SUMOReal speed, SUMOReal maxPos, SUMOReal minPos) throw();
00207     bool maxSpeedGapInsertion(MSVehicle& veh, SUMOReal mspeed) throw();
00208 
00216     bool freeInsertion(MSVehicle& veh, SUMOReal speed,
00217                        MSMoveReminder::Notification notification = MSMoveReminder::NOTIFICATION_DEPARTED) throw();
00218 
00219 
00227     void forceVehicleInsertion(MSVehicle* veh, SUMOReal pos) throw();
00229 
00230 
00231 
00234 
00246     SUMOReal setPartialOccupation(MSVehicle* v, SUMOReal leftVehicleLength) throw();
00247 
00248 
00252     void resetPartialOccupation(MSVehicle* v) throw();
00253 
00254 
00258     MSVehicle* getPartialOccupator() const throw() {
00259         return myInlappingVehicle;
00260     }
00261 
00262 
00266     SUMOReal getPartialOccupatorEnd() const throw() {
00267         return myInlappingVehicleEnd;
00268     }
00269 
00270 
00279     std::pair<MSVehicle*, SUMOReal> getLastVehicleInformation() const throw();
00281 
00282 
00283 
00286 
00290     unsigned int getVehicleNumber() const throw() {
00291         return (unsigned int) myVehicles.size();
00292     }
00293 
00294 
00301     virtual const std::deque< MSVehicle* > &getVehiclesSecure() const throw() {
00302         return myVehicles;
00303     }
00304 
00305 
00308     virtual void releaseVehicles() const throw() { }
00310 
00311 
00312 
00315 
00316 
00320     size_t getNumericalID() const throw() {
00321         return myNumericalID;
00322     }
00323 
00324 
00328     const PositionVector& getShape() const throw() {
00329         return myShape;
00330     }
00331 
00332 
00336     SUMOReal getMaxSpeed() const throw() {
00337         return myMaxSpeed;
00338     }
00339 
00340 
00344     SUMOReal getLength() const throw() {
00345         return myLength;
00346     }
00347 
00348 
00352     const SUMOVehicleClasses& getAllowedClasses() const throw() {
00353         return myAllowedClasses;
00354     }
00355 
00356 
00360     const SUMOVehicleClasses& getNotAllowedClasses() const throw() {
00361         return myNotAllowedClasses;
00362     }
00363 
00364 
00368     SUMOReal getWidth() const throw() {
00369         return myWidth;
00370     }
00372 
00373 
00374 
00377 
00378     virtual bool moveCritical(SUMOTime t);
00379 
00382     virtual bool setCritical(SUMOTime t, std::vector<MSLane*> &into);
00383 
00385     virtual bool integrateNewVehicle(SUMOTime t);
00387 
00388 
00389 
00391     virtual void detectCollisions(SUMOTime timestep);
00392 
00393 
00396     virtual bool appropriate(const MSVehicle* veh);
00397 
00398 
00400     const MSLinkCont& getLinkCont() const;
00401 
00402 
00404     bool empty() const {
00405         assert(myVehBuffer.size()==0);
00406         return myVehicles.empty();
00407     }
00408 
00409     void setMaxSpeed(SUMOReal val) throw() {
00410         myMaxSpeed = val;
00411     }
00412 
00413     void setLength(SUMOReal val) throw() {
00414         myLength = val;
00415     }
00416 
00417 
00421     MSEdge& getEdge() const throw() {
00422         return *myEdge;
00423     }
00424 
00428     static bool dictionary(std::string id, MSLane* lane);
00429 
00432     static MSLane* dictionary(std::string id);
00433 
00435     static void clear();
00436 
00437     static size_t dictSize() {
00438         return myDict.size();
00439     }
00440 
00441     static void insertIDs(std::vector<std::string> &into) throw();
00442 
00444     typedef std::deque< MSVehicle* > VehCont;
00445 
00450     virtual MSLinkCont::const_iterator succLinkSec(const SUMOVehicle& veh,
00451             unsigned int nRouteSuccs,
00452             const MSLane& succLinkSource,
00453             const std::vector<MSLane*> &conts) const;
00454 
00455 
00458     bool isLinkEnd(MSLinkCont::const_iterator& i) const;
00459 
00462     bool isLinkEnd(MSLinkCont::iterator& i);
00463 
00465     virtual MSVehicle* getLastVehicle() const;
00466     virtual const MSVehicle* getFirstVehicle() const;
00467 
00468 
00469 
00470 
00471     // valid for gui-version only
00472     virtual GUILaneWrapper* buildLaneWrapper(unsigned int index);
00473 
00474     virtual MSVehicle* removeVehicle(MSVehicle* remVehicle);
00475 
00477     PositionVector myShape;
00478 
00479 
00480 
00481     void leftByLaneChange(MSVehicle* v);
00482     void enteredByLaneChange(MSVehicle* v);
00483 
00484 
00485     MSLane* getLeftLane() const;
00486     MSLane* getRightLane() const;
00487 
00488     void setAllowedClasses(const SUMOVehicleClasses& classes) throw() {
00489         myAllowedClasses = classes;
00490     }
00491 
00492 
00493     void setNotAllowedClasses(const SUMOVehicleClasses& classes) throw() {
00494         myNotAllowedClasses = classes;
00495     }
00496 
00497 
00498     bool allowsVehicleClass(SUMOVehicleClass vclass) const;
00499 
00500     void addIncomingLane(MSLane* lane, MSLink* viaLink);
00501 
00502 
00503     struct IncomingLaneInfo {
00504         MSLane* lane;
00505         SUMOReal length;
00506         MSLink* viaLink;
00507     };
00508 
00509     const std::vector<IncomingLaneInfo> &getIncomingLanes() const {
00510         return myIncomingLanes;
00511     }
00512 
00513 
00514     void addApproachingLane(MSLane* lane);
00515     bool isApproachedFrom(MSEdge* const edge);
00516     bool isApproachedFrom(MSEdge* const edge, MSLane* const lane);
00517 
00518 
00519 
00520     std::pair<MSVehicle* const, SUMOReal> getFollowerOnConsecutive(SUMOReal dist, SUMOReal seen,
00521             SUMOReal leaderSpeed, SUMOReal backOffset, SUMOReal predMaxDecel) const;
00522 
00523 
00546     std::pair<MSVehicle* const, SUMOReal> getLeaderOnConsecutive(SUMOReal dist, SUMOReal seen,
00547             SUMOReal speed, const MSVehicle& veh, const std::vector<MSLane*> &bestLaneConts) const throw();
00548 
00549 
00550     MSLane* getLogicalPredecessorLane() const throw();
00551 
00552 
00554 
00555 
00559     SUMOReal getMeanSpeed() const throw();
00560 
00561 
00565     SUMOReal getOccupancy() const throw();
00566 
00567 
00571     SUMOReal getVehLenSum() const throw();
00572 
00573 
00577     SUMOReal getHBEFA_CO2Emissions() const throw();
00578 
00579 
00583     SUMOReal getHBEFA_COEmissions() const throw();
00584 
00585 
00589     SUMOReal getHBEFA_PMxEmissions() const throw();
00590 
00591 
00595     SUMOReal getHBEFA_NOxEmissions() const throw();
00596 
00597 
00601     SUMOReal getHBEFA_HCEmissions() const throw();
00602 
00603 
00607     SUMOReal getHBEFA_FuelConsumption() const throw();
00608 
00609 
00613     SUMOReal getHarmonoise_NoiseEmissions() const throw();
00615 
00616 
00617 protected:
00619     virtual void swapAfterLaneChange(SUMOTime t);
00620 
00631     virtual void incorporateVehicle(MSVehicle* veh, SUMOReal pos, SUMOReal speed,
00632                                     const MSLane::VehCont::iterator& at,
00633                                     MSMoveReminder::Notification notification = MSMoveReminder::NOTIFICATION_DEPARTED) throw(ProcessError);
00634 
00635 
00636 protected:
00638     size_t myNumericalID;
00639 
00647     VehCont myVehicles;
00648 
00650     SUMOReal myLength;
00651 
00653     SUMOReal myWidth;
00654 
00656     MSEdge* myEdge;
00657 
00659     SUMOReal myMaxSpeed;
00660 
00663     VehCont myTmpVehicles;
00664 
00665 
00666     SUMOReal myBackDistance;
00667 
00672     std::vector<MSVehicle*> myVehBuffer;
00673 
00675     SUMOVehicleClasses myAllowedClasses;
00676 
00678     SUMOVehicleClasses myNotAllowedClasses;
00679 
00680     std::vector<IncomingLaneInfo> myIncomingLanes;
00681     mutable MSLane* myLogicalPredecessorLane;
00682 
00683 
00685     SUMOReal myVehicleLengthSum;
00686 
00688     SUMOReal myInlappingVehicleEnd;
00689 
00691     MSVehicle* myInlappingVehicle;
00692 
00693 
00695     SUMOReal myLeftVehLength;
00696 
00699     MSLinkCont myLinks;
00700 
00701     std::map<MSEdge*, std::vector<MSLane*> > myApproachingLanes;
00702 
00703 
00704 
00706     typedef std::map< std::string, MSLane* > DictType;
00707 
00709     static DictType myDict;
00710 
00711 private:
00713     std::vector< MSMoveReminder* > myMoveReminders;
00714 
00715 
00720     class vehicle_position_sorter {
00721     public:
00723         explicit vehicle_position_sorter() { }
00724 
00725 
00731         int operator()(MSVehicle* v1, MSVehicle* v2) const {
00732             return v1->getPositionOnLane()>v2->getPositionOnLane();
00733         }
00734 
00735     };
00736 
00740     class by_connections_to_sorter {
00741     public:
00743         explicit by_connections_to_sorter(const MSEdge* const e)
00744             : myEdge(e), myLaneDir(e->getLanes()[0]->getShape().getBegLine().atan2PositiveAngle()) { }
00745 
00747         int operator()(const MSEdge* const e1, const MSEdge* const e2) const {
00748             const std::vector<MSLane*>* ae1 = e1->allowedLanes(*myEdge);
00749             const std::vector<MSLane*>* ae2 = e2->allowedLanes(*myEdge);
00750             SUMOReal s1 = 0;
00751             if (ae1!=0&&ae1->size()!=0) {
00752                 s1 = (SUMOReal) ae1->size() + GeomHelper::getMinAngleDiff((*ae1)[0]->getShape().getBegLine().atan2PositiveAngle(), myLaneDir) / PI / 2.;
00753             }
00754             SUMOReal s2 = 0;
00755             if (ae2!=0&&ae2->size()!=0) {
00756                 s2 = (SUMOReal) ae2->size() + GeomHelper::getMinAngleDiff((*ae2)[0]->getShape().getBegLine().atan2PositiveAngle(), myLaneDir) / PI / 2.;
00757             }
00758             return s1<s2;
00759         }
00760 
00761     private:
00762         by_connections_to_sorter& operator=(const by_connections_to_sorter&); // just to avoid a compiler warning
00763     private:
00764         const MSEdge* const myEdge;
00765         SUMOReal myLaneDir;
00766     };
00767 
00771     class edge_finder {
00772     public:
00773         edge_finder(MSEdge* e) : myEdge(e) {}
00774         bool operator()(const IncomingLaneInfo& ili) const {
00775             return &(ili.lane->getEdge())==myEdge;
00776         }
00777     private:
00778         edge_finder& operator=(const edge_finder&); // just to avoid a compiler warning
00779     private:
00780         const MSEdge* const myEdge;
00781     };
00782 
00783 private:
00785     MSLane(const MSLane&);
00786 
00788     MSLane& operator=(const MSLane&);
00789 
00790 
00791 };
00792 
00793 
00794 #endif
00795 
00796 /****************************************************************************/
00797 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines