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 2001-2010 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 "MSEdge.h"
00033 #include "MSNet.h"
00034 #include "MSRoute.h"
00035 #include "MSCORN.h"
00036 #include "MSGlobals.h"
00037 #include <list>
00038 #include <deque>
00039 #include <map>
00040 #include <string>
00041 #include <vector>
00042 #include <utils/common/MsgHandler.h>
00043 #include <utils/common/ToString.h>
00044 #include "MSVehicleQuitReminded.h"
00045 #include <utils/common/SUMOVehicle.h>
00046 #include <utils/common/SUMOVehicleClass.h>
00047 #include "MSVehicleType.h"
00048 #include <utils/common/SUMOAbstractRouter.h>
00049 
00050 #ifdef HAVE_MESOSIM
00051 #include <mesosim/MEVehicle.h>
00052 #endif
00053 
00054 
00055 // ===========================================================================
00056 // class declarations
00057 // ===========================================================================
00058 class MSLane;
00059 class MSMoveReminder;
00060 class MSLaneChanger;
00061 class MSVehicleTransfer;
00062 class MSAbstractLaneChangeModel;
00063 class MSBusStop;
00064 class OutputDevice;
00065 class MSDevice;
00066 class MSEdgeWeightsStorage;
00067 #ifdef _MESSAGES
00068 class MSMessageEmitter;
00069 #endif
00070 
00071 
00072 // ===========================================================================
00073 // class definitions
00074 // ===========================================================================
00079 class MSVehicle : public MSVehicleQuitReminded
00080 #ifdef HAVE_MESOSIM
00081         , public MEVehicle
00082 #else
00083         , public SUMOVehicle
00084 #endif
00085 {
00086 public:
00087 
00089     friend class MSLaneChanger;
00090 
00094     class State {
00096         friend class MSVehicle;
00097         friend class MSLaneChanger;
00098 
00099     public:
00101         State(SUMOReal pos, SUMOReal speed);
00102 
00104         State(const State& state);
00105 
00107         State& operator=(const State& state);
00108 
00110         bool operator!=(const State& state);
00111 
00113         SUMOReal pos() const;
00114 
00116         SUMOReal speed() const {
00117             return mySpeed;
00118         };
00119 
00120     private:
00122         SUMOReal myPos;
00123 
00125         SUMOReal mySpeed;
00126 
00127     };
00128 
00129 
00130 
00132     virtual ~MSVehicle() throw();
00133 
00134 
00135 
00137 
00138 
00143     const SUMOVehicleParameter &getParameter() const throw() {
00144         return *myParameter;
00145     }
00146 
00147 
00151     const MSEdge &getDepartEdge() const {
00152         return **myCurrEdge;
00153     }
00154 
00155 
00157     SUMOTime getDesiredDepart() const throw() {
00158         return myParameter->depart;
00159     }
00161 
00162 
00163 
00165 
00166 
00171     void onTryEmit() throw();
00172 
00173 
00179     void onDepart() throw();
00180 
00181 
00191     void onRemovalFromNet(bool forTeleporting) throw();
00193 
00194 
00195 
00196 
00197 
00198     void removeOnTripEnd(MSVehicle *veh) throw();
00199 
00200 
00201 
00203 
00204 
00209     inline bool hasSuccEdge(unsigned int nSuccs) const throw() {
00210         return myCurrEdge + nSuccs < myRoute->end();
00211     }
00212 
00220     const MSEdge* succEdge(unsigned int nSuccs) const throw();
00221 
00222 
00230     bool moveRoutePointer(const MSEdge* targetEdge) throw();
00231 
00232 
00236     bool ends() const throw();
00237 
00238 
00242     const MSRoute &getRoute() const throw() {
00243         return *myRoute;
00244     }
00245 
00246 
00252     const MSRoute &getRoute(int index) const throw();
00253 
00254 
00265     bool replaceRoute(const MSEdgeVector &edges, SUMOTime simTime, bool onInit=false) throw();
00266 
00267 
00273     bool willPass(const MSEdge * const edge) const throw();
00274 
00275 
00285     void reroute(SUMOTime t, SUMOAbstractRouter<MSEdge, SUMOVehicle> &router, bool withTaz=false) throw();
00286 
00287 
00293     MSEdgeWeightsStorage &getWeightsStorage() throw();
00294 
00295 
00300     bool hasValidRoute(std::string &msg) const throw();
00302 
00303 
00304 
00305 
00306 
00307 
00309     void moveFirstChecked();
00310 
00311 
00319     SUMOReal gap2pred(const MSVehicle& pred) const throw() {
00320         SUMOReal gap = pred.getPositionOnLane() - pred.getVehicleType().getLength() - getPositionOnLane();
00321         if (gap<0&&gap>-1.0e-12) {
00322             gap = 0;
00323         }
00324         return gap;
00325     }
00326 
00327 
00335     static inline SUMOReal gap(SUMOReal predPos, SUMOReal predLength, SUMOReal pos) throw() {
00336         return predPos - predLength - pos;
00337     }
00338 
00339 
00341 
00342 
00350     int getCORNIntValue(MSCORN::Function f) const throw();
00351 
00352 
00360     void *getCORNPointerValue(MSCORN::Pointer p) const throw();
00361 
00362 
00366     bool hasCORNIntValue(MSCORN::Function f) const throw();
00367 
00368 
00372     bool hasCORNPointerValue(MSCORN::Pointer p) const throw();
00374 
00375 
00377 
00378 
00396     void workOnMoveReminders(SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed) throw();
00397 
00398 
00405     SUMOReal getPositionOnActiveMoveReminderLane(const MSLane * const searchedLane) const throw();
00407 
00408 
00409 
00418     bool moveRegardingCritical(SUMOTime t, const MSLane* const lane, const MSVehicle * const pred,
00419                                const MSVehicle * const neigh, SUMOReal lengthsInFront) throw();
00420 
00421 
00423 
00424 
00429     const State &getState() const throw() {
00430         return myState;
00431     }
00432 
00436     SUMOReal getPositionOnLane() const throw() {
00437 #ifdef HAVE_MESOSIM
00438         if (MSGlobals::gUseMesoSim) {
00439             return MEVehicle::getPositionOnLane();
00440         }
00441 #endif
00442         return myState.myPos;
00443     }
00444 
00445 
00449     SUMOReal getSpeed() const throw() {
00450 #ifdef HAVE_MESOSIM
00451         if (MSGlobals::gUseMesoSim) {
00452             return MEVehicle::getSpeed();
00453         }
00454 #endif
00455         return myState.mySpeed;
00456     }
00457 
00461     SUMOReal getPreDawdleAcceleration() const throw() {
00462         return myPreDawdleAcceleration;
00463     }
00465 
00466 
00467 
00468     SUMOReal getMaxSpeed() const {
00469         if (myHasIndividualMaxSpeed)
00470             return myIndividualMaxSpeed;
00471         return myType->getMaxSpeed();
00472     }
00473 
00474     SUMOReal adaptMaxSpeed(SUMOReal referenceSpeed) {
00475         if (myType->hasSpeedDeviation() && referenceSpeed != myReferenceSpeed) {
00476             myHasIndividualMaxSpeed = true;
00477             myIndividualMaxSpeed = myType->getMaxSpeedWithDeviation(referenceSpeed);
00478             myReferenceSpeed = referenceSpeed;
00479         }
00480         if (myHasIndividualMaxSpeed)
00481             return myIndividualMaxSpeed;
00482         return MIN2(myType->getMaxSpeed(), referenceSpeed);
00483     }
00484 
00485     void setIndividualMaxSpeed(SUMOReal individualMaxSpeed) {
00486         myHasIndividualMaxSpeed = true;
00487         myIndividualMaxSpeed = individualMaxSpeed;
00488     }
00489 
00490     void unsetIndividualMaxSpeed(void) {
00491         myHasIndividualMaxSpeed = false;
00492     }
00493 
00494     void setPreDawdleAcceleration(SUMOReal accel) {
00495         myPreDawdleAcceleration = accel;
00496     }
00497 
00498 
00500     const std::string &getID() const throw();
00501 
00503     static bool overlap(const MSVehicle* veh1, const MSVehicle* veh2) {
00504         if (veh1->myState.myPos < veh2->myState.myPos) {
00505             return veh2->myState.myPos - veh2->getVehicleType().getLength() < veh1->myState.myPos;
00506         }
00507         return veh1->myState.myPos - veh1->getVehicleType().getLength() < veh2->myState.myPos;
00508     }
00509 
00510 
00513     bool congested() const {
00514         return myState.mySpeed < SUMOReal(60) / SUMOReal(3.6);
00515     }
00516 
00518     Position2D getPosition() const;
00519 
00520 
00522 
00523 
00525     void saveState(std::ostream &os);
00527 
00528 
00529     const MSEdge * const getEdge() const;
00530 
00531 
00537     void enterLaneAtMove(MSLane* enteredLane, SUMOReal driven);
00538 
00539 
00540 
00547     void enterLaneAtEmit(MSLane* enteredLane, SUMOReal pos, SUMOReal speed);
00548 
00549 
00554     void enterLaneAtLaneChange(MSLane* enteredLane);
00555 
00556 
00561     void leaveLaneAtMove(SUMOReal driven);
00562 
00563 
00565     void leaveLane(bool isArrival);
00566 
00567 
00568     friend class MSVehicleControl;
00569 
00570     void vsafeCriticalCont(SUMOTime t, SUMOReal minVSafe, SUMOReal lengthsInFront);
00571 
00572     MSLane *getTargetLane() const;
00573 
00575     const MSLane &getLane() const;
00576 
00580     inline bool isOnRoad() const throw() {
00581 #ifdef HAVE_MESOSIM
00582         if (MSGlobals::gUseMesoSim) {
00583             return MEVehicle::getSegment() != 0;
00584         }
00585 #endif
00586         return myLane!=0;
00587     }
00588 
00589 
00590 
00596     SUMOTime getWaitingTime() const throw() {
00597         return myWaitingTime;
00598     }
00599 
00600 
00606     SUMOReal getWaitingSeconds() const throw() {
00607         return STEPS2TIME(myWaitingTime);
00608     }
00609 
00610 
00611 
00612     void quitRemindedEntered(MSVehicleQuitReminded *r);
00613     void quitRemindedLeft(MSVehicleQuitReminded *r);
00614 
00615 
00616     MSAbstractLaneChangeModel &getLaneChangeModel();
00617     const MSAbstractLaneChangeModel &getLaneChangeModel() const;
00618 
00621 
00626     struct LaneQ {
00627         MSLane *lane;
00628         SUMOReal length;
00629         SUMOReal v;
00630         SUMOReal occupied;
00631         int bestLaneOffset;
00632         bool allowsContinuation;
00633         std::vector<MSLane*> joined;
00634     };
00635 
00654     virtual const std::vector<LaneQ> &getBestLanes(bool forceRebuild=false, MSLane *startLane=0) const throw();
00655 
00656 
00661     const std::vector<MSLane*> &getBestLanesContinuation() const throw();
00662 
00667     const std::vector<MSLane*> &getBestLanesContinuation(const MSLane * const l) const throw();
00669 
00670 
00671 
00675     inline const MSVehicleType &getVehicleType() const throw() {
00676         return *myType;
00677     }
00678 
00679 
00687     inline const MSCFModel &getCarFollowModel() const throw() {
00688         return myType->getCarFollowModel();
00689     }
00690 
00691 
00692     void writeXMLRoute(OutputDevice &os, int index=-1) const;
00693 
00694 
00696 
00697 
00701     struct Stop {
00703         const MSLane *lane;
00705         MSBusStop *busstop;
00707         SUMOReal pos;
00709         SUMOTime duration;
00711         SUMOTime until;
00713         bool reached;
00714     };
00715 
00716 
00723     bool addStop(const SUMOVehicleParameter::Stop &stopPar, SUMOTime untilOffset=0) throw();
00724 
00725 
00729     bool hasStops() {
00730         return !myStops.empty();
00731     }
00732 
00736     bool isStopped();
00738 
00739     bool knowsEdgeTest(MSEdge &edge) const;
00740 
00741 
00745     const std::vector<MSDevice*> &getDevices() const {
00746         return myDevices;
00747     }
00748 
00749     void setWasVaporized(bool onDepart);
00750 
00760     SUMOReal getDistanceToPosition(SUMOReal destPos, const MSEdge* destEdge);
00761 
00762 
00769     SUMOReal processNextStop(SUMOReal currentVelocity) throw();
00770 
00771 
00773 
00774 
00778     SUMOReal getHBEFA_CO2Emissions() const throw();
00779 
00780 
00784     SUMOReal getHBEFA_COEmissions() const throw();
00785 
00786 
00790     SUMOReal getHBEFA_HCEmissions() const throw();
00791 
00792 
00796     SUMOReal getHBEFA_NOxEmissions() const throw();
00797 
00798 
00802     SUMOReal getHBEFA_PMxEmissions() const throw();
00803 
00804 
00808     SUMOReal getHBEFA_FuelConsumption() const throw();
00809 
00810 
00814     SUMOReal getHarmonoise_NoiseEmissions() const throw();
00816 
00817     void addPerson(MSPerson* person) throw();
00818 
00819 #ifndef NO_TRACI
00820 
00823     SUMOReal getSpeedWithoutTraciInfluence() const throw() {
00824         return speedWithoutTraciInfluence;
00825     }
00826 
00836     bool addTraciStop(MSLane* lane, SUMOReal pos, SUMOReal radius, SUMOTime duration);
00837 
00838 
00847     bool startSpeedAdaption(float newSpeed, SUMOTime duration, SUMOTime currentTime);
00848 
00852     void adaptSpeed();
00853 
00858     void checkLaneChangeConstraint(SUMOTime time);
00859 
00864     void checkForLaneChanges();
00865 
00871     void startLaneChange(unsigned lane, SUMOTime stickyTime);
00872 
00877     void processTraCICommands(SUMOTime time);
00878 #endif
00879 
00880 protected:
00881 
00882 
00883 
00884 
00885     void checkRewindLinkLanes(SUMOReal lengthsInFront) throw();
00886 
00889 
00900     void activateReminders(bool isEmit, bool isLaneChange) throw();
00901 
00902 
00918     void adaptLaneEntering2MoveReminder(const MSLane &enteredLane) throw();
00920 
00921 
00922 
00923     void rebuildContinuationsFor(LaneQ &q, MSLane *l, MSRouteIterator ce, int seen) const;
00924     virtual void setBlinkerInformation() { }
00925 
00926 
00928     MSVehicle(SUMOVehicleParameter* pars, const MSRoute* route,
00929               const MSVehicleType* type, int vehicleIndex) throw(ProcessError);
00930 
00932     MSLane *myTarget;
00933 
00935     SUMOReal myLastLaneChangeOffset;
00936 
00938     SUMOTime myWaitingTime;
00939 
00940 #ifdef _MESSAGES
00942     MSMessageEmitter *myLCMsgEmitter;
00943     MSMessageEmitter *myBMsgEmitter;
00944     MSMessageEmitter *myHBMsgEmitter;
00945 #endif
00946 
00948     const SUMOVehicleParameter* myParameter;
00949 
00951     const MSRoute* myRoute;
00952 
00954     State myState;
00955 
00960     SUMOReal myIndividualMaxSpeed;
00961 
00963     bool myHasIndividualMaxSpeed;
00964 
00966     SUMOReal myReferenceSpeed;
00967 
00969     MSLane* myLane;
00970 
00971     MSAbstractLaneChangeModel *myLaneChangeModel;
00972 
00973     const MSVehicleType * const myType;
00974 
00975     mutable const MSEdge *myLastBestLanesEdge;
00976     mutable std::vector<std::vector<LaneQ> > myBestLanes;
00977     mutable std::vector<LaneQ>::iterator myCurrentLaneInBestLanes;
00978     static std::vector<MSLane*> myEmptyLaneVector;
00979 
00980     std::map<MSCORN::Pointer, void*> myPointerCORNMap;
00981     std::map<MSCORN::Function, int> myIntCORNMap;
00982 
00984     std::list<Stop> myStops;
00985 
00987     SUMOReal myArrivalPos;
00988 
00990     SUMOReal myPreDawdleAcceleration;
00991 
00993     std::vector<MSLane*> myFurtherLanes;
00994 
00995 
00996 private:
00998     std::vector<MSDevice*> myDevices;
00999 
01001     MSRouteIterator myCurrEdge;
01002 
01003 
01004     struct DriveProcessItem {
01005         MSLink *myLink;
01006         SUMOReal myVLinkPass;
01007         SUMOReal myVLinkWait;
01008         SUMOTime myArrivalTime;
01009         SUMOReal myArrivalSpeed;
01010         bool mySetRequest;
01011         DriveProcessItem(MSLink *link, SUMOReal vPass, SUMOReal vWait, bool setRequest,
01012                          SUMOTime arrivalTime, SUMOReal arrivalSpeed) :
01013                 myLink(link), myVLinkPass(vPass), myVLinkWait(vWait), mySetRequest(setRequest),
01014                 myArrivalTime(arrivalTime), myArrivalSpeed(arrivalSpeed) { };
01015     };
01016 
01017     typedef std::vector< DriveProcessItem > DriveItemVector;
01018 
01020     DriveItemVector myLFLinkLanes;
01021 
01022 
01025 
01027     typedef std::vector< MSMoveReminder* > MoveReminderCont;
01028 
01030     MoveReminderCont myMoveReminders;
01031 
01033     MoveReminderCont myOldLaneMoveReminders;
01034 
01036     typedef std::vector<SUMOReal> OffsetVector;
01037 
01039     OffsetVector myOldLaneMoveReminderOffsets;
01041 
01042     typedef std::vector<MSVehicleQuitReminded*> QuitRemindedVector;
01043     QuitRemindedVector myQuitReminded;
01044 
01045 
01046 
01056     class RouteReplaceInfo {
01057     public:
01059         RouteReplaceInfo(const MSEdge * const edge_, SUMOTime time_, MSRoute *route_)
01060                 : edge(edge_), time(time_), route(route_) {}
01061 
01063         ~RouteReplaceInfo() { }
01064 
01066         const MSEdge *edge;
01067 
01069         SUMOTime time;
01070 
01072         MSRoute *route;
01073 
01074     };
01075 
01077     typedef std::vector<RouteReplaceInfo> ReplacedRoutesVector;
01078 
01079 
01080     struct DepartArrivalInformation {
01081         SUMOTime time;
01082         MSLane *lane;
01083         SUMOReal pos;
01084         SUMOReal speed;
01085     };
01086 
01087 
01089     MSEdgeWeightsStorage *myEdgeWeights;
01090 
01091 
01092 #ifndef NO_TRACI
01093     /* indicates whether the vehicle is adapting its speed caused by the TraCI command slowDown*/
01094     bool adaptingSpeed;
01095     bool isLastAdaption;
01096 
01097     /* speed of the vehicle before any speed adaption began */
01098     SUMOReal speedBeforeAdaption;
01099 
01100     /* speed of the vehicle before influence of TraCI settings takes place */
01101     SUMOReal speedWithoutTraciInfluence;
01102 
01103     /* the amount by wich the speed shall be reduced */
01104     SUMOReal speedReduction;
01105 
01106     /* simulation time, when the last speed adaption started */
01107     SUMOTime timeBeforeAdaption;
01108 
01109     /* duration of the last speed adaption */
01110     SUMOTime adaptDuration;
01111 
01112     /* simulation time when the last lane change was forced */
01113     SUMOTime timeBeforeLaneChange;
01114 
01115     /* duration for which the last lane change will be in effect */
01116     SUMOTime laneChangeStickyTime;
01117 
01118     /* lane index of the destination road map position for an active lane change*/
01119     unsigned myDestinationLane;
01120 
01121     /* true if any forced lane change is in effect*/
01122     bool laneChangeConstraintActive;
01123 
01124 #endif
01125 
01126 private:
01128     MSVehicle();
01129 
01131     MSVehicle(const MSVehicle&);
01132 
01134     MSVehicle& operator=(const MSVehicle&);
01135 
01136 
01137 };
01138 
01139 
01140 #endif
01141 
01142 /****************************************************************************/
01143 

Generated on Wed May 5 00:06:32 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6