SUMO - Simulation of Urban MObility
|
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 <vector> 00039 #include <deque> 00040 #include <cassert> 00041 #include <utils/common/Named.h> 00042 #include <utils/common/SUMOVehicleClass.h> 00043 #include <utils/geom/PositionVector.h> 00044 #include "MSLinkCont.h" 00045 #include "MSMoveReminder.h" 00046 00047 00048 // =========================================================================== 00049 // class declarations 00050 // =========================================================================== 00051 class MSEdge; 00052 class MSVehicle; 00053 class MSLaneChanger; 00054 class MSLink; 00055 class GUILaneWrapper; 00056 class MSVehicleTransfer; 00057 class OutputDevice; 00058 00059 00060 // =========================================================================== 00061 // class definitions 00062 // =========================================================================== 00070 class MSLane : public Named { 00071 public: 00073 friend class MSLaneChanger; 00074 00075 friend class GUILaneWrapper; 00076 00077 friend class MSXMLRawOut; 00078 00081 struct VehPosition : public std::binary_function < const MSVehicle*, SUMOReal, bool > { 00083 bool operator()(const MSVehicle* cmp, SUMOReal pos) const; 00084 }; 00085 00086 public: 00099 MSLane(const std::string& id, SUMOReal maxSpeed, SUMOReal length, MSEdge* const edge, 00100 unsigned int numericalID, const PositionVector& shape, SUMOReal width, 00101 SVCPermissions permissions); 00102 00103 00105 virtual ~MSLane() ; 00106 00107 00108 00111 00120 void initialize(MSLinkCont* succs); 00121 00129 void addLink(MSLink* link); 00131 00132 00133 00136 00143 virtual void addMoveReminder(MSMoveReminder* rem) ; 00144 00145 00149 inline const std::vector< MSMoveReminder* > &getMoveReminders() const { 00150 return myMoveReminders; 00151 } 00153 00154 00155 00158 00174 bool insertVehicle(MSVehicle& v) ; 00175 00176 00194 virtual bool isInsertionSuccess(MSVehicle* vehicle, SUMOReal speed, SUMOReal pos, 00195 bool recheckNextLanes, 00196 MSMoveReminder::Notification notification = MSMoveReminder::NOTIFICATION_DEPARTED) ; 00197 00198 bool pWagGenericInsertion(MSVehicle& veh, SUMOReal speed, SUMOReal maxPos, SUMOReal minPos) ; 00199 bool pWagSimpleInsertion(MSVehicle& veh, SUMOReal speed, SUMOReal maxPos, SUMOReal minPos) ; 00200 bool maxSpeedGapInsertion(MSVehicle& veh, SUMOReal mspeed) ; 00201 00209 bool freeInsertion(MSVehicle& veh, SUMOReal speed, 00210 MSMoveReminder::Notification notification = MSMoveReminder::NOTIFICATION_DEPARTED) ; 00211 00212 00220 void forceVehicleInsertion(MSVehicle* veh, SUMOReal pos) ; 00222 00223 00224 00227 00239 SUMOReal setPartialOccupation(MSVehicle* v, SUMOReal leftVehicleLength) ; 00240 00241 00245 void resetPartialOccupation(MSVehicle* v) ; 00246 00247 00251 MSVehicle* getPartialOccupator() const { 00252 return myInlappingVehicle; 00253 } 00254 00255 00259 SUMOReal getPartialOccupatorEnd() const { 00260 return myInlappingVehicleEnd; 00261 } 00262 00263 00272 std::pair<MSVehicle*, SUMOReal> getLastVehicleInformation() const ; 00274 00275 00276 00279 00283 unsigned int getVehicleNumber() const { 00284 return (unsigned int) myVehicles.size(); 00285 } 00286 00287 00294 virtual const std::deque< MSVehicle* > &getVehiclesSecure() const { 00295 return myVehicles; 00296 } 00297 00298 00301 virtual void releaseVehicles() const { } 00303 00304 00305 00308 00309 00313 size_t getNumericalID() const { 00314 return myNumericalID; 00315 } 00316 00317 00321 const PositionVector& getShape() const { 00322 return myShape; 00323 } 00324 00325 00329 SUMOReal getMaxSpeed() const { 00330 return myMaxSpeed; 00331 } 00332 00333 00337 SUMOReal getLength() const { 00338 return myLength; 00339 } 00340 00341 00345 inline SVCPermissions getPermissions() { 00346 return myPermissions; 00347 } 00348 00349 00353 SUMOReal getWidth() const { 00354 return myWidth; 00355 } 00357 00358 00359 00362 00363 virtual bool moveCritical(SUMOTime t); 00364 00367 virtual bool setCritical(SUMOTime t, std::vector<MSLane*> &into); 00368 00370 virtual bool integrateNewVehicle(SUMOTime t); 00372 00373 00374 00376 virtual void detectCollisions(SUMOTime timestep); 00377 00378 00381 virtual bool appropriate(const MSVehicle* veh); 00382 00383 00385 const MSLinkCont& getLinkCont() const; 00386 00387 00389 bool empty() const { 00390 assert(myVehBuffer.size() == 0); 00391 return myVehicles.empty(); 00392 } 00393 00394 void setMaxSpeed(SUMOReal val) { 00395 myMaxSpeed = val; 00396 } 00397 00398 void setLength(SUMOReal val) { 00399 myLength = val; 00400 } 00401 00402 00406 MSEdge& getEdge() const { 00407 return *myEdge; 00408 } 00409 00413 static bool dictionary(std::string id, MSLane* lane); 00414 00417 static MSLane* dictionary(std::string id); 00418 00420 static void clear(); 00421 00422 static size_t dictSize() { 00423 return myDict.size(); 00424 } 00425 00426 static void insertIDs(std::vector<std::string> &into) ; 00427 00429 typedef std::deque< MSVehicle* > VehCont; 00430 00435 virtual MSLinkCont::const_iterator succLinkSec(const SUMOVehicle& veh, 00436 unsigned int nRouteSuccs, 00437 const MSLane& succLinkSource, 00438 const std::vector<MSLane*> &conts) const; 00439 00440 00443 bool isLinkEnd(MSLinkCont::const_iterator& i) const; 00444 00447 bool isLinkEnd(MSLinkCont::iterator& i); 00448 00450 virtual MSVehicle* getLastVehicle() const; 00451 virtual const MSVehicle* getFirstVehicle() const; 00452 00453 00454 00455 00456 // valid for gui-version only 00457 virtual GUILaneWrapper* buildLaneWrapper(unsigned int index); 00458 00459 virtual MSVehicle* removeVehicle(MSVehicle* remVehicle); 00460 00462 PositionVector myShape; 00463 00464 00465 00466 void leftByLaneChange(MSVehicle* v); 00467 void enteredByLaneChange(MSVehicle* v); 00468 00469 00470 MSLane* getLeftLane() const; 00471 MSLane* getRightLane() const; 00472 00473 inline void setPermissions(SVCPermissions permissions) { 00474 myPermissions = permissions; 00475 } 00476 00477 00478 inline bool allowsVehicleClass(SUMOVehicleClass vclass) const { 00479 return (myPermissions & vclass) == vclass; 00480 } 00481 00482 void addIncomingLane(MSLane* lane, MSLink* viaLink); 00483 00484 00485 struct IncomingLaneInfo { 00486 MSLane* lane; 00487 SUMOReal length; 00488 MSLink* viaLink; 00489 }; 00490 00491 const std::vector<IncomingLaneInfo> &getIncomingLanes() const { 00492 return myIncomingLanes; 00493 } 00494 00495 00496 void addApproachingLane(MSLane* lane); 00497 bool isApproachedFrom(MSEdge* const edge); 00498 bool isApproachedFrom(MSEdge* const edge, MSLane* const lane); 00499 00500 00501 00502 std::pair<MSVehicle* const, SUMOReal> getFollowerOnConsecutive(SUMOReal dist, SUMOReal seen, 00503 SUMOReal leaderSpeed, SUMOReal backOffset, SUMOReal predMaxDecel) const; 00504 00505 00528 std::pair<MSVehicle* const, SUMOReal> getLeaderOnConsecutive(SUMOReal dist, SUMOReal seen, 00529 SUMOReal speed, const MSVehicle& veh, const std::vector<MSLane*> &bestLaneConts) const ; 00530 00531 00532 MSLane* getLogicalPredecessorLane() const ; 00533 00534 00536 00537 00541 SUMOReal getMeanSpeed() const ; 00542 00543 00547 SUMOReal getOccupancy() const ; 00548 00549 00553 SUMOReal getVehLenSum() const ; 00554 00555 00559 SUMOReal getHBEFA_CO2Emissions() const ; 00560 00561 00565 SUMOReal getHBEFA_COEmissions() const ; 00566 00567 00571 SUMOReal getHBEFA_PMxEmissions() const ; 00572 00573 00577 SUMOReal getHBEFA_NOxEmissions() const ; 00578 00579 00583 SUMOReal getHBEFA_HCEmissions() const ; 00584 00585 00589 SUMOReal getHBEFA_FuelConsumption() const ; 00590 00591 00595 SUMOReal getHarmonoise_NoiseEmissions() const ; 00597 00598 00599 protected: 00601 virtual void swapAfterLaneChange(SUMOTime t); 00602 00613 virtual void incorporateVehicle(MSVehicle* veh, SUMOReal pos, SUMOReal speed, 00614 const MSLane::VehCont::iterator& at, 00615 MSMoveReminder::Notification notification = MSMoveReminder::NOTIFICATION_DEPARTED) ; 00616 00617 00618 protected: 00620 size_t myNumericalID; 00621 00629 VehCont myVehicles; 00630 00632 SUMOReal myLength; 00633 00635 SUMOReal myWidth; 00636 00638 MSEdge* myEdge; 00639 00641 SUMOReal myMaxSpeed; 00642 00645 VehCont myTmpVehicles; 00646 00647 00652 std::vector<MSVehicle*> myVehBuffer; 00653 00655 SVCPermissions myPermissions; 00656 00657 std::vector<IncomingLaneInfo> myIncomingLanes; 00658 mutable MSLane* myLogicalPredecessorLane; 00659 00660 00662 SUMOReal myVehicleLengthSum; 00663 00665 SUMOReal myInlappingVehicleEnd; 00666 00668 MSVehicle* myInlappingVehicle; 00669 00670 00672 SUMOReal myLeftVehLength; 00673 00676 MSLinkCont myLinks; 00677 00678 std::map<MSEdge*, std::vector<MSLane*> > myApproachingLanes; 00679 00680 00681 00683 typedef std::map< std::string, MSLane* > DictType; 00684 00686 static DictType myDict; 00687 00688 private: 00690 std::vector< MSMoveReminder* > myMoveReminders; 00691 00692 00697 class vehicle_position_sorter { 00698 public: 00700 explicit vehicle_position_sorter() { } 00701 00702 00708 int operator()(MSVehicle* v1, MSVehicle* v2) const; 00709 00710 }; 00711 00715 class by_connections_to_sorter { 00716 public: 00718 explicit by_connections_to_sorter(const MSEdge* const e); 00719 00721 int operator()(const MSEdge* const e1, const MSEdge* const e2) const; 00722 00723 private: 00724 by_connections_to_sorter& operator=(const by_connections_to_sorter&); // just to avoid a compiler warning 00725 private: 00726 const MSEdge* const myEdge; 00727 SUMOReal myLaneDir; 00728 }; 00729 00733 class edge_finder { 00734 public: 00735 edge_finder(MSEdge* e) : myEdge(e) {} 00736 bool operator()(const IncomingLaneInfo& ili) const { 00737 return &(ili.lane->getEdge()) == myEdge; 00738 } 00739 private: 00740 edge_finder& operator=(const edge_finder&); // just to avoid a compiler warning 00741 private: 00742 const MSEdge* const myEdge; 00743 }; 00744 00745 private: 00747 MSLane(const MSLane&); 00748 00750 MSLane& operator=(const MSLane&); 00751 00752 00753 }; 00754 00755 00756 #endif 00757 00758 /****************************************************************************/ 00759