|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00015 // Representation of a vehicle in the micro simulation 00016 /****************************************************************************/ 00017 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00018 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00019 /****************************************************************************/ 00020 // 00021 // This file is part of SUMO. 00022 // SUMO is free software: you can redistribute it and/or modify 00023 // it under the terms of the GNU General Public License as published by 00024 // the Free Software Foundation, either version 3 of the License, or 00025 // (at your option) any later version. 00026 // 00027 /****************************************************************************/ 00028 #ifndef MSVehicle_h 00029 #define MSVehicle_h 00030 00031 00032 // =========================================================================== 00033 // included modules 00034 // =========================================================================== 00035 #ifdef _MSC_VER 00036 #include <windows_config.h> 00037 #else 00038 #include <config.h> 00039 #endif 00040 00041 #include "MSBaseVehicle.h" 00042 #include "MSEdge.h" 00043 #include "MSRoute.h" 00044 #include "MSGlobals.h" 00045 #include <list> 00046 #include <deque> 00047 #include <map> 00048 #include <string> 00049 #include <vector> 00050 #include <utils/common/MsgHandler.h> 00051 #include <utils/common/ToString.h> 00052 #include <utils/common/SUMOVehicle.h> 00053 #include <utils/common/SUMOVehicleClass.h> 00054 #include "MSVehicleType.h" 00055 #include <utils/common/SUMOAbstractRouter.h> 00056 00057 #ifdef HAVE_MESOSIM 00058 #include <mesosim/MEVehicle.h> 00059 #endif 00060 00061 00062 // =========================================================================== 00063 // class declarations 00064 // =========================================================================== 00065 class MSLane; 00066 class MSLink; 00067 class MSMoveReminder; 00068 class MSLaneChanger; 00069 class MSVehicleTransfer; 00070 class MSAbstractLaneChangeModel; 00071 class MSBusStop; 00072 class MSPerson; 00073 class MSDevice; 00074 class MSEdgeWeightsStorage; 00075 class OutputDevice; 00076 class Position; 00077 class MSDevice_Person; 00078 #ifdef _MESSAGES 00079 class MSMessageEmitter; 00080 #endif 00081 00082 00083 // =========================================================================== 00084 // class definitions 00085 // =========================================================================== 00090 class MSVehicle : public MSBaseVehicle { 00091 public: 00092 00094 friend class MSLaneChanger; 00095 00099 class State { 00101 friend class MSVehicle; 00102 friend class MSLaneChanger; 00103 00104 public: 00106 State(SUMOReal pos, SUMOReal speed); 00107 00109 State(const State& state); 00110 00112 State& operator=(const State& state); 00113 00115 bool operator!=(const State& state); 00116 00118 SUMOReal pos() const; 00119 00121 SUMOReal speed() const { 00122 return mySpeed; 00123 }; 00124 00125 private: 00127 SUMOReal myPos; 00128 00130 SUMOReal mySpeed; 00131 00132 }; 00133 00134 00138 enum ChangeRequest { 00140 REQUEST_NONE, 00142 REQUEST_LEFT, 00144 REQUEST_RIGHT, 00146 REQUEST_HOLD 00147 }; 00148 00150 MSVehicle(SUMOVehicleParameter* pars, const MSRoute* route, 00151 const MSVehicleType* type, int vehicleIndex) ; 00152 00154 virtual ~MSVehicle() ; 00155 00156 00157 00159 00160 00168 void onRemovalFromNet(const MSMoveReminder::Notification reason) ; 00170 00171 00172 00174 00175 00179 bool ends() const ; 00180 00181 00190 bool replaceRoute(const MSRoute* route, bool onInit = false) ; 00191 00192 00198 bool willPass(const MSEdge* const edge) const ; 00199 00200 00206 MSEdgeWeightsStorage& getWeightsStorage() ; 00208 00209 00210 00211 00212 00213 00226 bool moveChecked(); 00227 00228 00236 SUMOReal gap2pred(const MSVehicle& pred) const { 00237 SUMOReal gap = pred.getPositionOnLane() - pred.getVehicleType().getLengthWithGap() - getPositionOnLane(); 00238 if (gap < 0 && gap > -1.0e-12) { 00239 gap = 0; 00240 } 00241 return gap; 00242 } 00243 00244 00252 static inline SUMOReal gap(SUMOReal predPos, SUMOReal predLength, SUMOReal pos) { 00253 return predPos - predLength - pos; 00254 } 00255 00256 00257 00259 00260 00278 void workOnMoveReminders(SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed) ; 00280 00281 00282 00291 bool moveRegardingCritical(SUMOTime t, const MSLane* const lane, const MSVehicle* const pred, 00292 const MSVehicle* const neigh, SUMOReal lengthsInFront) ; 00293 00294 00295 00297 00298 00302 SUMOReal getPositionOnLane() const { 00303 return myState.myPos; 00304 } 00305 00306 00310 SUMOReal getSpeed() const { 00311 return myState.mySpeed; 00312 } 00313 00314 00318 SUMOReal getPreDawdleAcceleration() const { 00319 return myPreDawdleAcceleration; 00320 } 00322 00323 00324 00326 00327 00335 Position getPosition() const ; 00336 00337 00341 MSLane* getLane() const { 00342 return myLane; 00343 } 00344 00345 00349 inline bool isOnRoad() const { 00350 return myAmOnNet; 00351 } 00352 00353 00360 SUMOTime getWaitingTime() const { 00361 return myWaitingTime; 00362 } 00363 00364 00371 SUMOReal getWaitingSeconds() const { 00372 return STEPS2TIME(myWaitingTime); 00373 } 00374 00375 00379 SUMOReal getAngle() const ; 00381 00382 00383 class Influencer; 00384 00385 void setIndividualMaxSpeed(SUMOReal individualMaxSpeed) { 00386 myHasIndividualMaxSpeed = true; 00387 myIndividualMaxSpeed = individualMaxSpeed; 00388 } 00389 00390 void unsetIndividualMaxSpeed(void) { 00391 myHasIndividualMaxSpeed = false; 00392 } 00393 00394 void setPreDawdleAcceleration(SUMOReal accel) { 00395 myPreDawdleAcceleration = accel; 00396 } 00397 00398 00400 static bool overlap(const MSVehicle* veh1, const MSVehicle* veh2) { 00401 if (veh1->myState.myPos < veh2->myState.myPos) { 00402 return veh2->myState.myPos - veh2->getVehicleType().getLengthWithGap() < veh1->myState.myPos; 00403 } 00404 return veh1->myState.myPos - veh1->getVehicleType().getLengthWithGap() < veh2->myState.myPos; 00405 } 00406 00407 00410 bool congested() const { 00411 return myState.mySpeed < SUMOReal(60) / SUMOReal(3.6); 00412 } 00413 00414 00425 void activateReminders(const MSMoveReminder::Notification reason) ; 00426 00433 bool enterLaneAtMove(MSLane* enteredLane, bool onTeleporting = false); 00434 00435 00436 00444 void enterLaneAtInsertion(MSLane* enteredLane, SUMOReal pos, SUMOReal speed, 00445 MSMoveReminder::Notification notification) ; 00446 00447 00452 void enterLaneAtLaneChange(MSLane* enteredLane); 00453 00454 00456 void leaveLane(const MSMoveReminder::Notification reason); 00457 00458 00459 void vsafeCriticalCont(SUMOTime t, SUMOReal boundVSafe); 00460 00461 00462 00463 MSAbstractLaneChangeModel& getLaneChangeModel(); 00464 const MSAbstractLaneChangeModel& getLaneChangeModel() const; 00465 00468 00472 struct LaneQ { 00474 MSLane* lane; 00476 SUMOReal length; 00478 SUMOReal occupation; 00480 SUMOReal nextOccupation; 00482 int bestLaneOffset; 00484 bool allowsContinuation; 00486 std::vector<MSLane*> bestContinuations; 00487 }; 00488 00507 virtual const std::vector<LaneQ> &getBestLanes(bool forceRebuild = false, MSLane* startLane = 0) const ; 00508 00509 00514 const std::vector<MSLane*> &getBestLanesContinuation() const ; 00515 00520 const std::vector<MSLane*> &getBestLanesContinuation(const MSLane* const l) const ; 00522 00523 00532 void replaceVehicleType(MSVehicleType* type) ; 00533 00534 00542 inline const MSCFModel& getCarFollowModel() const { 00543 return myType->getCarFollowModel(); 00544 } 00545 00546 00551 inline MSCFModel::VehicleVariables* getCarFollowVariables() const { 00552 return myCFVariables; 00553 } 00554 00555 00557 00558 00562 struct Stop { 00564 MSRouteIterator edge; 00566 const MSLane* lane; 00568 MSBusStop* busstop; 00570 SUMOReal startPos; 00572 SUMOReal endPos; 00574 SUMOTime duration; 00576 SUMOTime until; 00578 bool triggered; 00580 bool parking; 00582 bool reached; 00583 }; 00584 00585 00592 bool addStop(const SUMOVehicleParameter::Stop& stopPar, SUMOTime untilOffset = 0) ; 00593 00594 00598 bool hasStops() const { 00599 return !myStops.empty(); 00600 } 00601 00605 bool isStopped() const; 00606 00610 bool isParking() const; 00612 00613 bool knowsEdgeTest(MSEdge& edge) const; 00614 unsigned int getLaneIndex() const; 00615 00625 SUMOReal getDistanceToPosition(SUMOReal destPos, const MSEdge* destEdge); 00626 00627 00634 SUMOReal processNextStop(SUMOReal currentVelocity) ; 00635 00636 00638 00639 00643 SUMOReal getHBEFA_CO2Emissions() const ; 00644 00645 00649 SUMOReal getHBEFA_COEmissions() const ; 00650 00651 00655 SUMOReal getHBEFA_HCEmissions() const ; 00656 00657 00661 SUMOReal getHBEFA_NOxEmissions() const ; 00662 00663 00667 SUMOReal getHBEFA_PMxEmissions() const ; 00668 00669 00673 SUMOReal getHBEFA_FuelConsumption() const ; 00674 00675 00679 SUMOReal getHarmonoise_NoiseEmissions() const ; 00681 00682 void addPerson(MSPerson* person) ; 00683 00684 00685 00688 00692 enum Signalling { 00694 VEH_SIGNAL_NONE = 0, 00696 VEH_SIGNAL_BLINKER_RIGHT = 1, 00698 VEH_SIGNAL_BLINKER_LEFT = 2, 00700 VEH_SIGNAL_BLINKER_EMERGENCY = 4, 00702 VEH_SIGNAL_BRAKELIGHT = 8, 00704 VEH_SIGNAL_FRONTLIGHT = 16, 00706 VEH_SIGNAL_FOGLIGHT = 32, 00708 VEH_SIGNAL_HIGHBEAM = 64, 00710 VEH_SIGNAL_BACKDRIVE = 128, 00712 VEH_SIGNAL_WIPER = 256, 00714 VEH_SIGNAL_DOOR_OPEN_LEFT = 512, 00716 VEH_SIGNAL_DOOR_OPEN_RIGHT = 1024, 00718 VEH_SIGNAL_EMERGENCY_BLUE = 2048, 00720 VEH_SIGNAL_EMERGENCY_RED = 4096, 00722 VEH_SIGNAL_EMERGENCY_YELLOW = 8192 00723 }; 00724 00725 00729 void switchOnSignal(int signal) { 00730 mySignals |= signal; 00731 } 00732 00733 00737 void switchOffSignal(int signal) { 00738 mySignals &= ~signal; 00739 } 00740 00741 00745 int getSignals() const { 00746 return mySignals; 00747 } 00748 00749 00754 bool signalSet(int which) const { 00755 return (mySignals & which) != 0; 00756 } 00758 00759 00760 00761 00762 #ifndef NO_TRACI 00763 00770 SUMOReal getSpeedWithoutTraciInfluence() const; 00771 00781 bool addTraciStop(MSLane* lane, SUMOReal pos, SUMOReal radius, SUMOTime duration); 00782 00783 00794 class Influencer { 00795 public: 00797 Influencer(); 00798 00799 00801 ~Influencer(); 00802 00803 00807 void setSpeedTimeLine(const std::vector<std::pair<SUMOTime, SUMOReal> > &speedTimeLine); 00808 00809 00813 void setLaneTimeLine(const std::vector<std::pair<SUMOTime, unsigned int> > &laneTimeLine); 00814 00815 00827 SUMOReal influenceSpeed(SUMOTime currentTime, SUMOReal speed, SUMOReal vSafe, SUMOReal vMin, SUMOReal vMax); 00828 00829 00830 ChangeRequest checkForLaneChanges(SUMOTime currentTime, const MSEdge& currentEdge, unsigned int currentLaneIndex); 00831 00832 00836 void setConsiderSafeVelocity(bool value); 00837 00838 00842 void setConsiderMaxAcceleration(bool value); 00843 00844 00848 void setConsiderMaxDeceleration(bool value); 00849 00850 00854 SUMOReal getOriginalSpeed() const { 00855 return myOriginalSpeed; 00856 } 00857 00858 00859 private: 00861 std::vector<std::pair<SUMOTime, SUMOReal> > mySpeedTimeLine; 00862 00864 std::vector<std::pair<SUMOTime, unsigned int> > myLaneTimeLine; 00865 00867 SUMOReal myOriginalSpeed; 00868 00870 bool mySpeedAdaptationStarted; 00871 00873 bool myConsiderSafeVelocity; 00874 00876 bool myConsiderMaxAcceleration; 00877 00879 bool myConsiderMaxDeceleration; 00880 }; 00881 00882 00888 Influencer& getInfluencer(); 00889 00890 00891 #endif 00892 00893 protected: 00894 00895 void checkRewindLinkLanes(SUMOReal lengthsInFront) ; 00896 SUMOReal getSpaceTillLastStanding(MSLane* l, bool& foundStopped) ; 00897 00900 00916 void adaptLaneEntering2MoveReminder(const MSLane& enteredLane) ; 00918 00919 00920 00921 void setBlinkerInformation() ; 00922 00923 00925 SUMOTime myLastLaneChangeOffset; 00926 00928 SUMOTime myWaitingTime; 00929 00930 #ifdef _MESSAGES 00931 00932 MSMessageEmitter* myLCMsgEmitter; 00933 MSMessageEmitter* myBMsgEmitter; 00934 MSMessageEmitter* myHBMsgEmitter; 00935 #endif 00936 00938 State myState; 00939 00941 MSLane* myLane; 00942 00943 MSAbstractLaneChangeModel* myLaneChangeModel; 00944 00945 mutable const MSEdge* myLastBestLanesEdge; 00946 mutable std::vector<std::vector<LaneQ> > myBestLanes; 00947 mutable std::vector<LaneQ>::iterator myCurrentLaneInBestLanes; 00948 static std::vector<MSLane*> myEmptyLaneVector; 00949 00951 std::list<Stop> myStops; 00952 00954 MSDevice_Person* myPersonDevice; 00955 00957 SUMOReal myPreDawdleAcceleration; 00958 00960 std::vector<MSLane*> myFurtherLanes; 00961 00963 int mySignals; 00964 00966 bool myAmOnNet; 00967 00969 bool myAmRegisteredAsWaitingForPerson; 00970 00971 bool myHaveToWaitOnNextLink; 00972 00973 private: 00974 struct DriveProcessItem { 00975 MSLink* myLink; 00976 SUMOReal myVLinkPass; 00977 SUMOReal myVLinkWait; 00978 bool mySetRequest; 00979 SUMOTime myArrivalTime; 00980 SUMOReal myArrivalSpeed; 00981 SUMOReal myDistance; 00982 DriveProcessItem(MSLink* link, SUMOReal vPass, SUMOReal vWait, bool setRequest, 00983 SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal distance) : 00984 myLink(link), myVLinkPass(vPass), myVLinkWait(vWait), mySetRequest(setRequest), 00985 myArrivalTime(arrivalTime), myArrivalSpeed(arrivalSpeed), myDistance(distance) { }; 00986 }; 00987 00988 typedef std::vector< DriveProcessItem > DriveItemVector; 00989 00991 DriveItemVector myLFLinkLanes; 00992 00994 MSEdgeWeightsStorage* myEdgeWeights; 00995 00997 MSCFModel::VehicleVariables* myCFVariables; 00998 00999 #ifndef NO_TRACI 01000 01001 Influencer* myInfluencer; 01002 #endif 01003 01004 private: 01006 MSVehicle(); 01007 01009 MSVehicle(const MSVehicle&); 01010 01012 MSVehicle& operator=(const MSVehicle&); 01013 01014 01015 }; 01016 01017 01018 #endif 01019 01020 /****************************************************************************/ 01021