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 <list> 00042 #include <deque> 00043 #include <map> 00044 #include <string> 00045 #include <vector> 00046 #include "MSVehicleType.h" 00047 #include "MSBaseVehicle.h" 00048 00049 00050 // =========================================================================== 00051 // class declarations 00052 // =========================================================================== 00053 class MSLane; 00054 class MSLink; 00055 class MSMoveReminder; 00056 class MSLaneChanger; 00057 class MSVehicleTransfer; 00058 class MSAbstractLaneChangeModel; 00059 class MSBusStop; 00060 class MSPerson; 00061 class MSDevice; 00062 class MSEdgeWeightsStorage; 00063 class OutputDevice; 00064 class Position; 00065 class MSDevice_Person; 00066 #ifdef _MESSAGES 00067 class MSMessageEmitter; 00068 #endif 00069 00070 00071 // =========================================================================== 00072 // class definitions 00073 // =========================================================================== 00078 class MSVehicle : public MSBaseVehicle { 00079 public: 00080 00082 friend class MSLaneChanger; 00083 00087 class State { 00089 friend class MSVehicle; 00090 friend class MSLaneChanger; 00091 00092 public: 00094 State(SUMOReal pos, SUMOReal speed); 00095 00097 State(const State& state); 00098 00100 State& operator=(const State& state); 00101 00103 bool operator!=(const State& state); 00104 00106 SUMOReal pos() const; 00107 00109 SUMOReal speed() const { 00110 return mySpeed; 00111 }; 00112 00113 private: 00115 SUMOReal myPos; 00116 00118 SUMOReal mySpeed; 00119 00120 }; 00121 00122 00126 enum ChangeRequest { 00128 REQUEST_NONE, 00130 REQUEST_LEFT, 00132 REQUEST_RIGHT, 00134 REQUEST_HOLD 00135 }; 00136 00138 MSVehicle(SUMOVehicleParameter* pars, const MSRoute* route, 00139 const MSVehicleType* type, int vehicleIndex) ; 00140 00142 virtual ~MSVehicle() ; 00143 00144 00145 00147 00148 00156 void onRemovalFromNet(const MSMoveReminder::Notification reason) ; 00158 00159 00160 00162 00163 00167 bool ends() const ; 00168 00169 00178 bool replaceRoute(const MSRoute* route, bool onInit = false) ; 00179 00180 00186 bool willPass(const MSEdge* const edge) const ; 00187 00188 00194 MSEdgeWeightsStorage& getWeightsStorage() ; 00196 00197 00198 00199 00200 00201 00214 bool moveChecked(); 00215 00216 00224 SUMOReal gap2pred(const MSVehicle& pred) const { 00225 SUMOReal gap = pred.getPositionOnLane() - pred.getVehicleType().getLength() - getPositionOnLane() - getVehicleType().getMinGap(); 00226 if (gap < 0 && gap > -1.0e-12) { 00227 gap = 0; 00228 } 00229 return gap; 00230 } 00231 00232 00240 static inline SUMOReal gap(SUMOReal predPos, SUMOReal predLength, SUMOReal pos) { 00241 return predPos - predLength - pos; 00242 } 00243 00244 00245 00247 00248 00266 void workOnMoveReminders(SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed) ; 00268 00269 00270 00279 bool moveRegardingCritical(SUMOTime t, const MSLane* const lane, const MSVehicle* const pred, 00280 const MSVehicle* const neigh, SUMOReal lengthsInFront) ; 00281 00282 00283 00285 00286 00290 SUMOReal getPositionOnLane() const { 00291 return myState.myPos; 00292 } 00293 00294 00298 SUMOReal getSpeed() const { 00299 return myState.mySpeed; 00300 } 00301 00302 00306 SUMOReal getPreDawdleAcceleration() const { 00307 return myPreDawdleAcceleration; 00308 } 00310 00311 00312 00314 00315 00323 Position getPosition() const ; 00324 00325 00329 MSLane* getLane() const { 00330 return myLane; 00331 } 00332 00333 00337 inline bool isOnRoad() const { 00338 return myAmOnNet; 00339 } 00340 00341 00348 SUMOTime getWaitingTime() const { 00349 return myWaitingTime; 00350 } 00351 00352 00359 SUMOReal getWaitingSeconds() const { 00360 return STEPS2TIME(myWaitingTime); 00361 } 00362 00363 00367 SUMOReal getAngle() const ; 00369 00370 00371 class Influencer; 00372 00373 void setIndividualMaxSpeed(SUMOReal individualMaxSpeed) { 00374 myHasIndividualMaxSpeed = true; 00375 myIndividualMaxSpeed = individualMaxSpeed; 00376 } 00377 00378 void unsetIndividualMaxSpeed(void) { 00379 myHasIndividualMaxSpeed = false; 00380 } 00381 00382 void setPreDawdleAcceleration(SUMOReal accel) { 00383 myPreDawdleAcceleration = accel; 00384 } 00385 00386 00388 static bool overlap(const MSVehicle* veh1, const MSVehicle* veh2) { 00389 if (veh1->myState.myPos < veh2->myState.myPos) { 00390 return veh2->myState.myPos - veh2->getVehicleType().getLengthWithGap() < veh1->myState.myPos; 00391 } 00392 return veh1->myState.myPos - veh1->getVehicleType().getLengthWithGap() < veh2->myState.myPos; 00393 } 00394 00395 00398 bool congested() const { 00399 return myState.mySpeed < SUMOReal(60) / SUMOReal(3.6); 00400 } 00401 00402 00413 void activateReminders(const MSMoveReminder::Notification reason) ; 00414 00421 bool enterLaneAtMove(MSLane* enteredLane, bool onTeleporting = false); 00422 00423 00424 00432 void enterLaneAtInsertion(MSLane* enteredLane, SUMOReal pos, SUMOReal speed, 00433 MSMoveReminder::Notification notification) ; 00434 00435 00440 void enterLaneAtLaneChange(MSLane* enteredLane); 00441 00442 00444 void leaveLane(const MSMoveReminder::Notification reason); 00445 00446 00447 void vsafeCriticalCont(SUMOTime t, SUMOReal boundVSafe); 00448 00449 00450 00451 MSAbstractLaneChangeModel& getLaneChangeModel(); 00452 const MSAbstractLaneChangeModel& getLaneChangeModel() const; 00453 00456 00460 struct LaneQ { 00462 MSLane* lane; 00464 SUMOReal length; 00466 SUMOReal occupation; 00468 SUMOReal nextOccupation; 00470 int bestLaneOffset; 00472 bool allowsContinuation; 00474 std::vector<MSLane*> bestContinuations; 00475 }; 00476 00495 virtual const std::vector<LaneQ> &getBestLanes(bool forceRebuild = false, MSLane* startLane = 0) const ; 00496 00497 00502 const std::vector<MSLane*> &getBestLanesContinuation() const ; 00503 00508 const std::vector<MSLane*> &getBestLanesContinuation(const MSLane* const l) const ; 00510 00511 00520 void replaceVehicleType(MSVehicleType* type) ; 00521 00522 00530 inline const MSCFModel& getCarFollowModel() const { 00531 return myType->getCarFollowModel(); 00532 } 00533 00534 00539 inline MSCFModel::VehicleVariables* getCarFollowVariables() const { 00540 return myCFVariables; 00541 } 00542 00543 00545 00546 00550 struct Stop { 00552 MSRouteIterator edge; 00554 const MSLane* lane; 00556 MSBusStop* busstop; 00558 SUMOReal startPos; 00560 SUMOReal endPos; 00562 SUMOTime duration; 00564 SUMOTime until; 00566 bool triggered; 00568 bool parking; 00570 bool reached; 00571 }; 00572 00573 00580 bool addStop(const SUMOVehicleParameter::Stop& stopPar, SUMOTime untilOffset = 0) ; 00581 00582 00586 bool hasStops() const { 00587 return !myStops.empty(); 00588 } 00589 00593 bool isStopped() const; 00594 00598 bool isParking() const; 00600 00601 bool knowsEdgeTest(MSEdge& edge) const; 00602 unsigned int getLaneIndex() const; 00603 00613 SUMOReal getDistanceToPosition(SUMOReal destPos, const MSEdge* destEdge); 00614 00615 00622 SUMOReal processNextStop(SUMOReal currentVelocity) ; 00623 00624 00626 00627 00631 SUMOReal getHBEFA_CO2Emissions() const ; 00632 00633 00637 SUMOReal getHBEFA_COEmissions() const ; 00638 00639 00643 SUMOReal getHBEFA_HCEmissions() const ; 00644 00645 00649 SUMOReal getHBEFA_NOxEmissions() const ; 00650 00651 00655 SUMOReal getHBEFA_PMxEmissions() const ; 00656 00657 00661 SUMOReal getHBEFA_FuelConsumption() const ; 00662 00663 00667 SUMOReal getHarmonoise_NoiseEmissions() const ; 00669 00670 void addPerson(MSPerson* person) ; 00671 00672 00673 00676 00680 enum Signalling { 00682 VEH_SIGNAL_NONE = 0, 00684 VEH_SIGNAL_BLINKER_RIGHT = 1, 00686 VEH_SIGNAL_BLINKER_LEFT = 2, 00688 VEH_SIGNAL_BLINKER_EMERGENCY = 4, 00690 VEH_SIGNAL_BRAKELIGHT = 8, 00692 VEH_SIGNAL_FRONTLIGHT = 16, 00694 VEH_SIGNAL_FOGLIGHT = 32, 00696 VEH_SIGNAL_HIGHBEAM = 64, 00698 VEH_SIGNAL_BACKDRIVE = 128, 00700 VEH_SIGNAL_WIPER = 256, 00702 VEH_SIGNAL_DOOR_OPEN_LEFT = 512, 00704 VEH_SIGNAL_DOOR_OPEN_RIGHT = 1024, 00706 VEH_SIGNAL_EMERGENCY_BLUE = 2048, 00708 VEH_SIGNAL_EMERGENCY_RED = 4096, 00710 VEH_SIGNAL_EMERGENCY_YELLOW = 8192 00711 }; 00712 00713 00717 void switchOnSignal(int signal) { 00718 mySignals |= signal; 00719 } 00720 00721 00725 void switchOffSignal(int signal) { 00726 mySignals &= ~signal; 00727 } 00728 00729 00733 int getSignals() const { 00734 return mySignals; 00735 } 00736 00737 00742 bool signalSet(int which) const { 00743 return (mySignals & which) != 0; 00744 } 00746 00747 00748 00749 00750 #ifndef NO_TRACI 00751 00758 SUMOReal getSpeedWithoutTraciInfluence() const; 00759 00769 bool addTraciStop(MSLane* lane, SUMOReal pos, SUMOReal radius, SUMOTime duration); 00770 00771 00782 class Influencer { 00783 public: 00785 Influencer(); 00786 00787 00789 ~Influencer(); 00790 00791 00795 void setSpeedTimeLine(const std::vector<std::pair<SUMOTime, SUMOReal> > &speedTimeLine); 00796 00797 00801 void setLaneTimeLine(const std::vector<std::pair<SUMOTime, unsigned int> > &laneTimeLine); 00802 00803 00815 SUMOReal influenceSpeed(SUMOTime currentTime, SUMOReal speed, SUMOReal vSafe, SUMOReal vMin, SUMOReal vMax); 00816 00817 00818 ChangeRequest checkForLaneChanges(SUMOTime currentTime, const MSEdge& currentEdge, unsigned int currentLaneIndex); 00819 00820 00824 void setConsiderSafeVelocity(bool value); 00825 00826 00830 void setConsiderMaxAcceleration(bool value); 00831 00832 00836 void setConsiderMaxDeceleration(bool value); 00837 00838 00842 SUMOReal getOriginalSpeed() const { 00843 return myOriginalSpeed; 00844 } 00845 00846 00847 private: 00849 std::vector<std::pair<SUMOTime, SUMOReal> > mySpeedTimeLine; 00850 00852 std::vector<std::pair<SUMOTime, unsigned int> > myLaneTimeLine; 00853 00855 SUMOReal myOriginalSpeed; 00856 00858 bool mySpeedAdaptationStarted; 00859 00861 bool myConsiderSafeVelocity; 00862 00864 bool myConsiderMaxAcceleration; 00865 00867 bool myConsiderMaxDeceleration; 00868 }; 00869 00870 00876 Influencer& getInfluencer(); 00877 00878 00879 #endif 00880 00881 protected: 00882 00883 void checkRewindLinkLanes(SUMOReal lengthsInFront) ; 00884 SUMOReal getSpaceTillLastStanding(MSLane* l, bool& foundStopped) ; 00885 00888 00904 void adaptLaneEntering2MoveReminder(const MSLane& enteredLane) ; 00906 00907 00908 00909 void setBlinkerInformation() ; 00910 00911 00913 SUMOTime myLastLaneChangeOffset; 00914 00916 SUMOTime myWaitingTime; 00917 00918 #ifdef _MESSAGES 00919 00920 MSMessageEmitter* myLCMsgEmitter; 00921 MSMessageEmitter* myBMsgEmitter; 00922 MSMessageEmitter* myHBMsgEmitter; 00923 #endif 00924 00926 State myState; 00927 00929 MSLane* myLane; 00930 00931 MSAbstractLaneChangeModel* myLaneChangeModel; 00932 00933 mutable const MSEdge* myLastBestLanesEdge; 00934 mutable std::vector<std::vector<LaneQ> > myBestLanes; 00935 mutable std::vector<LaneQ>::iterator myCurrentLaneInBestLanes; 00936 static std::vector<MSLane*> myEmptyLaneVector; 00937 00939 std::list<Stop> myStops; 00940 00942 MSDevice_Person* myPersonDevice; 00943 00945 SUMOReal myPreDawdleAcceleration; 00946 00948 std::vector<MSLane*> myFurtherLanes; 00949 00951 int mySignals; 00952 00954 bool myAmOnNet; 00955 00957 bool myAmRegisteredAsWaitingForPerson; 00958 00959 bool myHaveToWaitOnNextLink; 00960 00961 protected: 00962 struct DriveProcessItem { 00963 MSLink* myLink; 00964 SUMOReal myVLinkPass; 00965 SUMOReal myVLinkWait; 00966 bool mySetRequest; 00967 SUMOTime myArrivalTime; 00968 SUMOReal myArrivalSpeed; 00969 SUMOReal myDistance; 00970 DriveProcessItem(MSLink* link, SUMOReal vPass, SUMOReal vWait, bool setRequest, 00971 SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal distance) : 00972 myLink(link), myVLinkPass(vPass), myVLinkWait(vWait), mySetRequest(setRequest), 00973 myArrivalTime(arrivalTime), myArrivalSpeed(arrivalSpeed), myDistance(distance) { }; 00974 }; 00975 00976 typedef std::vector< DriveProcessItem > DriveItemVector; 00977 00979 DriveItemVector myLFLinkLanes; 00980 00981 00982 private: 00984 MSEdgeWeightsStorage* myEdgeWeights; 00985 00987 MSCFModel::VehicleVariables* myCFVariables; 00988 00989 #ifndef NO_TRACI 00990 00991 Influencer* myInfluencer; 00992 #endif 00993 00994 private: 00996 MSVehicle(); 00997 00999 MSVehicle(const MSVehicle&); 01000 01002 MSVehicle& operator=(const MSVehicle&); 01003 01004 01005 }; 01006 01007 01008 #endif 01009 01010 /****************************************************************************/ 01011