SUMO - Simulation of Urban MObility

MSVehicle.h

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Representation of a vehicle 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 MSVehicle_h
00020 #define MSVehicle_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 "MSBaseVehicle.h"
00033 #include "MSEdge.h"
00034 #include "MSRoute.h"
00035 #include "MSGlobals.h"
00036 #include <list>
00037 #include <deque>
00038 #include <map>
00039 #include <string>
00040 #include <vector>
00041 #include <utils/common/MsgHandler.h>
00042 #include <utils/common/ToString.h>
00043 #include <utils/common/SUMOVehicle.h>
00044 #include <utils/common/SUMOVehicleClass.h>
00045 #include "MSVehicleType.h"
00046 #include <utils/common/SUMOAbstractRouter.h>
00047 
00048 #ifdef HAVE_MESOSIM
00049 #include <mesosim/MEVehicle.h>
00050 #endif
00051 
00052 
00053 // ===========================================================================
00054 // class declarations
00055 // ===========================================================================
00056 class MSLane;
00057 class MSLink;
00058 class MSMoveReminder;
00059 class MSLaneChanger;
00060 class MSVehicleTransfer;
00061 class MSAbstractLaneChangeModel;
00062 class MSBusStop;
00063 class MSPerson;
00064 class MSDevice;
00065 class MSEdgeWeightsStorage;
00066 class OutputDevice;
00067 class Position;
00068 class MSDevice_Person;
00069 #ifdef _MESSAGES
00070 class MSMessageEmitter;
00071 #endif
00072 
00073 
00074 // ===========================================================================
00075 // class definitions
00076 // ===========================================================================
00081 class MSVehicle : public MSBaseVehicle {
00082 public:
00083 
00085     friend class MSLaneChanger;
00086 
00090     class State {
00092         friend class MSVehicle;
00093         friend class MSLaneChanger;
00094 
00095     public:
00097         State(SUMOReal pos, SUMOReal speed);
00098 
00100         State(const State& state);
00101 
00103         State& operator=(const State& state);
00104 
00106         bool operator!=(const State& state);
00107 
00109         SUMOReal pos() const;
00110 
00112         SUMOReal speed() const {
00113             return mySpeed;
00114         };
00115 
00116     private:
00118         SUMOReal myPos;
00119 
00121         SUMOReal mySpeed;
00122 
00123     };
00124 
00125 
00129     enum ChangeRequest {
00131         REQUEST_NONE,
00133         REQUEST_LEFT,
00135         REQUEST_RIGHT,
00137         REQUEST_HOLD
00138     };
00139 
00141     MSVehicle(SUMOVehicleParameter* pars, const MSRoute* route,
00142               const MSVehicleType* type, int vehicleIndex) throw(ProcessError);
00143 
00145     virtual ~MSVehicle() throw();
00146 
00147 
00148 
00150 
00151 
00159     void onRemovalFromNet(const MSMoveReminder::Notification reason) throw();
00161 
00162 
00163 
00165 
00166 
00170     bool ends() const throw();
00171 
00172 
00181     bool replaceRoute(const MSRoute* route, bool onInit=false) throw();
00182 
00183 
00189     bool willPass(const MSEdge* const edge) const throw();
00190 
00191 
00197     MSEdgeWeightsStorage& getWeightsStorage() throw();
00199 
00200 
00201 
00202 
00203 
00204 
00217     bool moveChecked();
00218 
00219 
00227     SUMOReal gap2pred(const MSVehicle& pred) const throw() {
00228         SUMOReal gap = pred.getPositionOnLane() - pred.getVehicleType().getLengthWithGap() - getPositionOnLane();
00229         if (gap<0&&gap>-1.0e-12) {
00230             gap = 0;
00231         }
00232         return gap;
00233     }
00234 
00235 
00243     static inline SUMOReal gap(SUMOReal predPos, SUMOReal predLength, SUMOReal pos) throw() {
00244         return predPos - predLength - pos;
00245     }
00246 
00247 
00248 
00250 
00251 
00269     void workOnMoveReminders(SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed) throw();
00271 
00272 
00273 
00282     bool moveRegardingCritical(SUMOTime t, const MSLane* const lane, const MSVehicle* const pred,
00283                                const MSVehicle* const neigh, SUMOReal lengthsInFront) throw();
00284 
00285 
00286 
00288 
00289 
00293     SUMOReal getPositionOnLane() const throw() {
00294         return myState.myPos;
00295     }
00296 
00297 
00301     SUMOReal getSpeed() const throw() {
00302         return myState.mySpeed;
00303     }
00304 
00305 
00309     SUMOReal getPreDawdleAcceleration() const throw() {
00310         return myPreDawdleAcceleration;
00311     }
00313 
00314 
00315 
00317 
00318 
00326     Position getPosition() const throw();
00327 
00328 
00332     MSLane* getLane() const throw() {
00333         return myLane;
00334     }
00335 
00336 
00340     inline bool isOnRoad() const throw() {
00341         return myAmOnNet;
00342     }
00343 
00344 
00351     SUMOTime getWaitingTime() const throw() {
00352         return myWaitingTime;
00353     }
00354 
00355 
00362     SUMOReal getWaitingSeconds() const throw() {
00363         return STEPS2TIME(myWaitingTime);
00364     }
00365 
00366 
00370     SUMOReal getAngle() const throw();
00372 
00373 
00374     class Influencer;
00375 
00376     void setIndividualMaxSpeed(SUMOReal individualMaxSpeed) {
00377         myHasIndividualMaxSpeed = true;
00378         myIndividualMaxSpeed = individualMaxSpeed;
00379     }
00380 
00381     void unsetIndividualMaxSpeed(void) {
00382         myHasIndividualMaxSpeed = false;
00383     }
00384 
00385     void setPreDawdleAcceleration(SUMOReal accel) {
00386         myPreDawdleAcceleration = accel;
00387     }
00388 
00389 
00391     static bool overlap(const MSVehicle* veh1, const MSVehicle* veh2) {
00392         if (veh1->myState.myPos < veh2->myState.myPos) {
00393             return veh2->myState.myPos - veh2->getVehicleType().getLengthWithGap() < veh1->myState.myPos;
00394         }
00395         return veh1->myState.myPos - veh1->getVehicleType().getLengthWithGap() < veh2->myState.myPos;
00396     }
00397 
00398 
00401     bool congested() const {
00402         return myState.mySpeed < SUMOReal(60) / SUMOReal(3.6);
00403     }
00404 
00405 
00416     void activateReminders(const MSMoveReminder::Notification reason) throw();
00417 
00424     bool enterLaneAtMove(MSLane* enteredLane, bool onTeleporting=false);
00425 
00426 
00427 
00435     void enterLaneAtInsertion(MSLane* enteredLane, SUMOReal pos, SUMOReal speed,
00436                               MSMoveReminder::Notification notification) throw(ProcessError);
00437 
00438 
00443     void enterLaneAtLaneChange(MSLane* enteredLane);
00444 
00445 
00447     void leaveLane(const MSMoveReminder::Notification reason);
00448 
00449 
00450     void vsafeCriticalCont(SUMOTime t, SUMOReal boundVSafe);
00451 
00452 
00453 
00454     MSAbstractLaneChangeModel& getLaneChangeModel();
00455     const MSAbstractLaneChangeModel& getLaneChangeModel() const;
00456 
00459 
00463     struct LaneQ {
00465         MSLane* lane;
00467         SUMOReal length;
00469         SUMOReal occupation;
00471         SUMOReal nextOccupation;
00473         int bestLaneOffset;
00475         bool allowsContinuation;
00477         std::vector<MSLane*> bestContinuations;
00478     };
00479 
00498     virtual const std::vector<LaneQ> &getBestLanes(bool forceRebuild=false, MSLane* startLane=0) const throw();
00499 
00500 
00505     const std::vector<MSLane*> &getBestLanesContinuation() const throw();
00506 
00511     const std::vector<MSLane*> &getBestLanesContinuation(const MSLane* const l) const throw();
00513 
00514 
00523     void replaceVehicleType(MSVehicleType* type) throw();
00524 
00525 
00533     inline const MSCFModel& getCarFollowModel() const throw() {
00534         return myType->getCarFollowModel();
00535     }
00536 
00537 
00542     inline MSCFModel::VehicleVariables* getCarFollowVariables() const throw() {
00543         return myCFVariables;
00544     }
00545 
00546 
00548 
00549 
00553     struct Stop {
00555         MSRouteIterator edge;
00557         const MSLane* lane;
00559         MSBusStop* busstop;
00561         SUMOReal startPos;
00563         SUMOReal endPos;
00565         SUMOTime duration;
00567         SUMOTime until;
00569         bool triggered;
00571         bool parking;
00573         bool reached;
00574     };
00575 
00576 
00583     bool addStop(const SUMOVehicleParameter::Stop& stopPar, SUMOTime untilOffset=0) throw();
00584 
00585 
00589     bool hasStops() const {
00590         return !myStops.empty();
00591     }
00592 
00596     bool isStopped() const;
00597 
00601     bool isParking() const;
00603 
00604     bool knowsEdgeTest(MSEdge& edge) const;
00605     unsigned int getLaneIndex() const;
00606 
00616     SUMOReal getDistanceToPosition(SUMOReal destPos, const MSEdge* destEdge);
00617 
00618 
00625     SUMOReal processNextStop(SUMOReal currentVelocity) throw();
00626 
00627 
00629 
00630 
00634     SUMOReal getHBEFA_CO2Emissions() const throw();
00635 
00636 
00640     SUMOReal getHBEFA_COEmissions() const throw();
00641 
00642 
00646     SUMOReal getHBEFA_HCEmissions() const throw();
00647 
00648 
00652     SUMOReal getHBEFA_NOxEmissions() const throw();
00653 
00654 
00658     SUMOReal getHBEFA_PMxEmissions() const throw();
00659 
00660 
00664     SUMOReal getHBEFA_FuelConsumption() const throw();
00665 
00666 
00670     SUMOReal getHarmonoise_NoiseEmissions() const throw();
00672 
00673     void addPerson(MSPerson* person) throw();
00674 
00675 
00676 
00679 
00683     enum Signalling {
00685         VEH_SIGNAL_NONE = 0,
00687         VEH_SIGNAL_BLINKER_RIGHT = 1,
00689         VEH_SIGNAL_BLINKER_LEFT = 2,
00691         VEH_SIGNAL_BLINKER_EMERGENCY = 4,
00693         VEH_SIGNAL_BRAKELIGHT = 8,
00695         VEH_SIGNAL_FRONTLIGHT = 16,
00697         VEH_SIGNAL_FOGLIGHT = 32,
00699         VEH_SIGNAL_HIGHBEAM = 64,
00701         VEH_SIGNAL_BACKDRIVE = 128,
00703         VEH_SIGNAL_WIPER = 256,
00705         VEH_SIGNAL_DOOR_OPEN_LEFT = 512,
00707         VEH_SIGNAL_DOOR_OPEN_RIGHT = 1024,
00709         VEH_SIGNAL_EMERGENCY_BLUE = 2048,
00711         VEH_SIGNAL_EMERGENCY_RED = 4096,
00713         VEH_SIGNAL_EMERGENCY_YELLOW = 8192
00714     };
00715 
00716 
00720     void switchOnSignal(int signal) throw() {
00721         mySignals |= signal;
00722     }
00723 
00724 
00728     void switchOffSignal(int signal) throw() {
00729         mySignals &= ~signal;
00730     }
00731 
00732 
00736     int getSignals() const throw() {
00737         return mySignals;
00738     }
00739 
00740 
00745     bool signalSet(int which) const throw() {
00746         return (mySignals&which)!=0;
00747     }
00749 
00750 
00751 
00752 
00753 #ifndef NO_TRACI
00754 
00761     SUMOReal getSpeedWithoutTraciInfluence() const;
00762 
00772     bool addTraciStop(MSLane* lane, SUMOReal pos, SUMOReal radius, SUMOTime duration);
00773 
00774 
00785     class Influencer {
00786     public:
00788         Influencer();
00789 
00790 
00792         ~Influencer();
00793 
00794 
00798         void setSpeedTimeLine(const std::vector<std::pair<SUMOTime, SUMOReal> > &speedTimeLine);
00799 
00800 
00804         void setLaneTimeLine(const std::vector<std::pair<SUMOTime, unsigned int> > &laneTimeLine);
00805 
00806 
00818         SUMOReal influenceSpeed(SUMOTime currentTime, SUMOReal speed, SUMOReal vSafe, SUMOReal vMin, SUMOReal vMax);
00819 
00820 
00821         ChangeRequest checkForLaneChanges(SUMOTime currentTime, const MSEdge& currentEdge, unsigned int currentLaneIndex);
00822 
00823 
00827         void setConsiderSafeVelocity(bool value);
00828 
00829 
00833         void setConsiderMaxAcceleration(bool value);
00834 
00835 
00839         void setConsiderMaxDeceleration(bool value);
00840 
00841 
00845         SUMOReal getOriginalSpeed() const {
00846             return myOriginalSpeed;
00847         }
00848 
00849 
00850     private:
00852         std::vector<std::pair<SUMOTime, SUMOReal> > mySpeedTimeLine;
00853 
00855         std::vector<std::pair<SUMOTime, unsigned int> > myLaneTimeLine;
00856 
00858         SUMOReal myOriginalSpeed;
00859 
00861         bool mySpeedAdaptationStarted;
00862 
00864         bool myConsiderSafeVelocity;
00865 
00867         bool myConsiderMaxAcceleration;
00868 
00870         bool myConsiderMaxDeceleration;
00871     };
00872 
00873 
00879     Influencer& getInfluencer();
00880 
00881 
00882 #endif
00883 
00884 protected:
00885 
00886     void checkRewindLinkLanes(SUMOReal lengthsInFront) throw();
00887     SUMOReal getSpaceTillLastStanding(MSLane* l, bool& foundStopped) throw();
00888 
00891 
00907     void adaptLaneEntering2MoveReminder(const MSLane& enteredLane) throw();
00909 
00910 
00911 
00912     void setBlinkerInformation() throw();
00913 
00914 
00916     SUMOTime myLastLaneChangeOffset;
00917 
00919     SUMOTime myWaitingTime;
00920 
00921 #ifdef _MESSAGES
00922 
00923     MSMessageEmitter* myLCMsgEmitter;
00924     MSMessageEmitter* myBMsgEmitter;
00925     MSMessageEmitter* myHBMsgEmitter;
00926 #endif
00927 
00929     State myState;
00930 
00932     MSLane* myLane;
00933 
00934     MSAbstractLaneChangeModel* myLaneChangeModel;
00935 
00936     mutable const MSEdge* myLastBestLanesEdge;
00937     mutable std::vector<std::vector<LaneQ> > myBestLanes;
00938     mutable std::vector<LaneQ>::iterator myCurrentLaneInBestLanes;
00939     static std::vector<MSLane*> myEmptyLaneVector;
00940 
00942     std::list<Stop> myStops;
00943 
00945     MSDevice_Person* myPersonDevice;
00946 
00948     SUMOReal myPreDawdleAcceleration;
00949 
00951     std::vector<MSLane*> myFurtherLanes;
00952 
00954     int mySignals;
00955 
00957     bool myAmOnNet;
00958 
00960     bool myAmRegisteredAsWaitingForPerson;
00961 
00962     bool myHaveToWaitOnNextLink;
00963 
00964 private:
00965     struct DriveProcessItem {
00966         MSLink* myLink;
00967         SUMOReal myVLinkPass;
00968         SUMOReal myVLinkWait;
00969         bool mySetRequest;
00970         SUMOTime myArrivalTime;
00971         SUMOReal myArrivalSpeed;
00972         SUMOReal myDistance;
00973         DriveProcessItem(MSLink* link, SUMOReal vPass, SUMOReal vWait, bool setRequest,
00974                          SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal distance) :
00975             myLink(link), myVLinkPass(vPass), myVLinkWait(vWait), mySetRequest(setRequest),
00976             myArrivalTime(arrivalTime), myArrivalSpeed(arrivalSpeed), myDistance(distance) { };
00977     };
00978 
00979     typedef std::vector< DriveProcessItem > DriveItemVector;
00980 
00982     DriveItemVector myLFLinkLanes;
00983 
00985     MSEdgeWeightsStorage* myEdgeWeights;
00986 
00988     MSCFModel::VehicleVariables* myCFVariables;
00989 
00990 #ifndef NO_TRACI
00991 
00992     Influencer* myInfluencer;
00993 #endif
00994 
00995 private:
00997     MSVehicle();
00998 
01000     MSVehicle(const MSVehicle&);
01001 
01003     MSVehicle& operator=(const MSVehicle&);
01004 
01005 
01006 };
01007 
01008 
01009 #endif
01010 
01011 /****************************************************************************/
01012 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines