SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSVehicle.h
Go to the documentation of this file.
1 /****************************************************************************/
15 // Representation of a vehicle in the micro simulation
16 /****************************************************************************/
17 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
18 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
19 /****************************************************************************/
20 //
21 // This file is part of SUMO.
22 // SUMO is free software: you can redistribute it and/or modify
23 // it under the terms of the GNU General Public License as published by
24 // the Free Software Foundation, either version 3 of the License, or
25 // (at your option) any later version.
26 //
27 /****************************************************************************/
28 #ifndef MSVehicle_h
29 #define MSVehicle_h
30 
31 
32 // ===========================================================================
33 // included modules
34 // ===========================================================================
35 #ifdef _MSC_VER
36 #include <windows_config.h>
37 #else
38 #include <config.h>
39 #endif
40 
41 #include <list>
42 #include <deque>
43 #include <map>
44 #include <string>
45 #include <vector>
46 #include "MSVehicleType.h"
47 #include "MSBaseVehicle.h"
48 
49 
50 // ===========================================================================
51 // class declarations
52 // ===========================================================================
53 class MSLane;
54 class MSLink;
55 class MSMoveReminder;
56 class MSLaneChanger;
57 class MSVehicleTransfer;
59 class MSBusStop;
60 class MSPerson;
61 class MSDevice;
63 class OutputDevice;
64 class Position;
65 class MSDevice_Person;
66 #ifdef _MESSAGES
67 class MSMessageEmitter;
68 #endif
69 
70 
71 // ===========================================================================
72 // class definitions
73 // ===========================================================================
78 class MSVehicle : public MSBaseVehicle {
79 public:
80 
82  friend class MSLaneChanger;
83 
87  class State {
89  friend class MSVehicle;
90  friend class MSLaneChanger;
91 
92  public:
95 
97  State(const State& state);
98 
100  State& operator=(const State& state);
101 
103  bool operator!=(const State& state);
104 
106  SUMOReal pos() const;
107 
109  SUMOReal speed() const {
110  return mySpeed;
111  };
112 
113  private:
115  SUMOReal myPos;
116 
119 
120  };
121 
122 
135  };
136 
145  MSVehicle(SUMOVehicleParameter* pars, const MSRoute* route,
146  const MSVehicleType* type, SUMOReal speedFactor, int vehicleIndex);
147 
149  virtual ~MSVehicle();
150 
151 
152 
154 
155 
165 
166 
167 
169 
170 
174  bool hasArrived() const;
175 
184  bool replaceRoute(const MSRoute* route, bool onInit = false);
185 
186 
192  bool willPass(const MSEdge* const edge) const;
193 
194  unsigned int getRoutePosition() const;
195  void resetRoutePosition(unsigned int index);
196 
205 
206 
214  SUMOReal gap2pred(const MSVehicle& pred) const {
216  if (gap < 0 && gap > -1.0e-12) {
217  gap = 0;
218  }
219  return gap;
220  }
221 
222 
230  static inline SUMOReal gap(SUMOReal predPos, SUMOReal predLength, SUMOReal pos) {
231  return predPos - predLength - pos;
232  }
233 
234 
235 
237 
238 
256  void workOnMoveReminders(SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed);
258 
259 
278  void planMove(SUMOTime t, MSVehicle* pred, MSVehicle* neigh, SUMOReal lengthsInFront);
279 
280 
293  bool executeMove();
294 
295 
297 
298 
303  return myState.myPos;
304  }
305 
306 
310  SUMOReal getSpeed() const {
311  return myState.mySpeed;
312  }
313 
314 
319  return myAcceleration;
320  }
322 
323 
324 
326 
327 
335  Position getPosition() const;
336 
337 
341  MSLane* getLane() const {
342  return myLane;
343  }
344 
345 
349  inline bool isOnRoad() const {
350  return myAmOnNet;
351  }
352 
353 
361  return myWaitingTime;
362  }
363 
364 
372  return STEPS2TIME(myWaitingTime);
373  }
374 
375 
379  SUMOReal getAngle() const;
381 
382 
383  class Influencer;
384 
386  static bool overlap(const MSVehicle* veh1, const MSVehicle* veh2) {
387  if (veh1->myState.myPos < veh2->myState.myPos) {
388  return veh2->myState.myPos - veh2->getVehicleType().getLengthWithGap() < veh1->myState.myPos;
389  }
390  return veh1->myState.myPos - veh1->getVehicleType().getLengthWithGap() < veh2->myState.myPos;
391  }
392 
393 
396  bool congested() const {
397  return myState.mySpeed < SUMOReal(60) / SUMOReal(3.6);
398  }
399 
400 
412 
419  bool enterLaneAtMove(MSLane* enteredLane, bool onTeleporting = false);
420 
421 
422 
430  void enterLaneAtInsertion(MSLane* enteredLane, SUMOReal pos, SUMOReal speed,
431  MSMoveReminder::Notification notification);
432 
433 
438  void enterLaneAtLaneChange(MSLane* enteredLane);
439 
440 
442  void leaveLane(const MSMoveReminder::Notification reason);
443 
444 
445 
446 
447 
450 
453 
457  struct LaneQ {
471  std::vector<MSLane*> bestContinuations;
472  };
473 
492  virtual const std::vector<LaneQ>& getBestLanes(bool forceRebuild = false, MSLane* startLane = 0) const;
493 
494 
499  const std::vector<MSLane*>& getBestLanesContinuation() const;
500 
505  const std::vector<MSLane*>& getBestLanesContinuation(const MSLane* const l) const;
507 
508 
517  void replaceVehicleType(MSVehicleType* type);
518 
519 
527  inline const MSCFModel& getCarFollowModel() const {
528  return myType->getCarFollowModel();
529  }
530 
531 
537  return myCFVariables;
538  }
539 
540 
542 
543 
547  struct Stop {
551  const MSLane* lane;
563  bool triggered;
565  bool parking;
567  bool reached;
568  };
569 
570 
577  bool addStop(const SUMOVehicleParameter::Stop& stopPar, SUMOTime untilOffset = 0);
578 
579 
583  bool hasStops() const {
584  return !myStops.empty();
585  }
586 
590  bool isStopped() const;
591 
595  bool isParking() const;
597 
598  bool knowsEdgeTest(MSEdge& edge) const;
599  unsigned int getLaneIndex() const;
600 
610  SUMOReal getDistanceToPosition(SUMOReal destPos, const MSEdge* destEdge);
611 
612 
619  SUMOReal processNextStop(SUMOReal currentVelocity);
620 
621 
623 
624 
629 
630 
635 
636 
641 
642 
647 
648 
653 
654 
659 
660 
666 
667 
668 
670 
671 
675  void addPerson(MSPerson* person);
676 
677 
681  unsigned int getPersonNumber() const;
682 
683 
686 
690  enum Signalling {
721  };
722 
723 
727  void switchOnSignal(int signal) {
728  mySignals |= signal;
729  }
730 
731 
735  void switchOffSignal(int signal) {
736  mySignals &= ~signal;
737  }
738 
739 
743  int getSignals() const {
744  return mySignals;
745  }
746 
747 
752  bool signalSet(int which) const {
753  return (mySignals & which) != 0;
754  }
756 
757 
758 
759 
760 #ifndef NO_TRACI
761 
769 
779  bool addTraciStop(MSLane* lane, SUMOReal pos, SUMOReal radius, SUMOTime duration);
780 
781 
782 #ifdef HAVE_INTERNAL_LANES
783 
784  bool hasLinkLeader(MSVehicle* veh) const {
785  return myLinkLeaders.count(veh->getID()) > 0;
786  }
787 #endif
788 
789 
800  class Influencer {
801  public:
803  Influencer();
804 
805 
807  ~Influencer();
808 
809 
813  void setSpeedTimeLine(const std::vector<std::pair<SUMOTime, SUMOReal> >& speedTimeLine);
814 
815 
819  void setLaneTimeLine(const std::vector<std::pair<SUMOTime, unsigned int> >& laneTimeLine);
820 
821 
833  SUMOReal influenceSpeed(SUMOTime currentTime, SUMOReal speed, SUMOReal vSafe, SUMOReal vMin, SUMOReal vMax);
834 
835 
836  ChangeRequest checkForLaneChanges(SUMOTime currentTime, const MSEdge& currentEdge, unsigned int currentLaneIndex);
837 
838 
842  void setConsiderSafeVelocity(bool value);
843 
844 
848  void setConsiderMaxAcceleration(bool value);
849 
850 
854  void setConsiderMaxDeceleration(bool value);
855 
856 
861  return myOriginalSpeed;
862  }
863 
864  void setVTDControlled(bool c, MSLane* l, SUMOReal pos, int edgeOffset, const MSEdgeVector& route) {
865  myAmVTDControlled = c;
866  myVTDLane = l;
867  myVTDPos = pos;
868  myVTDEdgeOffset = edgeOffset;
869  myVTDRoute = route;
870  }
871 
872  void postProcessVTD(MSVehicle* v);
873 
874  bool isVTDControlled() const {
875  return myAmVTDControlled;
876  }
877 
878  private:
880  std::vector<std::pair<SUMOTime, SUMOReal> > mySpeedTimeLine;
881 
883  std::vector<std::pair<SUMOTime, unsigned int> > myLaneTimeLine;
884 
887 
890 
893 
896 
899 
905 
906  };
907 
908 
915 
916  bool hasInfluencer() const {
917  return myInfluencer != 0;
918  }
919 
920 
921 #endif
922 
923 protected:
924 
925  void checkRewindLinkLanes(SUMOReal lengthsInFront);
926  SUMOReal getSpaceTillLastStanding(MSLane* l, bool& foundStopped);
927 
930 
946  void adaptLaneEntering2MoveReminder(const MSLane& enteredLane);
948 
949 
950 
951  void setBlinkerInformation();
952 
953 
956 
959 
960 #ifdef _MESSAGES
961 
962  MSMessageEmitter* myLCMsgEmitter;
963  MSMessageEmitter* myBMsgEmitter;
964  MSMessageEmitter* myHBMsgEmitter;
965 #endif
966 
969 
972 
974 
975  mutable const MSEdge* myLastBestLanesEdge;
976  mutable std::vector<std::vector<LaneQ> > myBestLanes;
977  mutable std::vector<LaneQ>::iterator myCurrentLaneInBestLanes;
978  static std::vector<MSLane*> myEmptyLaneVector;
979 
981  std::list<Stop> myStops;
982 
985 
988 
990  std::vector<MSLane*> myFurtherLanes;
991 
994 
996  bool myAmOnNet;
997 
1000 
1002 
1003 protected:
1013  DriveProcessItem(MSLink* link, SUMOReal vPass, SUMOReal vWait, bool setRequest,
1014  SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal distance) :
1015  myLink(link), myVLinkPass(vPass), myVLinkWait(vWait), mySetRequest(setRequest),
1016  myArrivalTime(arrivalTime), myArrivalSpeed(arrivalSpeed), myDistance(distance),
1017  accelV(-1) { };
1019  if (accelV < 0) {
1020  accelV = v;
1021  } else {
1022  accelV = MIN2(accelV, v);
1023  }
1024  }
1026  return accelV < 0 ? myVLinkPass : accelV;
1027  }
1028  };
1029 
1030  typedef std::vector< DriveProcessItem > DriveItemVector;
1031 
1034 
1036  SUMOReal estimateLeaveSpeed(MSLink* link, SUMOReal vLinkPass);
1037 
1038  /* @brief estimate speed while accelerating for the given distance
1039  * @param[in] dist The distance during which accelerating takes place
1040  * @param[in] v The initial speed
1041  */
1043 
1044  /* @brief estimate speed while accelerating for the given distance
1045  * @param[in] leaderInfo The leading vehicle and the (virtual) distance to it
1046  * @param[in] seen the distance to the end of the current lane
1047  * @param[in] lastLink the lastLink index
1048  * @param[in] lane The current Lane the vehicle is on
1049  * @param[in,out] the safe velocity for driving
1050  * @param[in,out] the safe velocity for arriving at the next link
1051  */
1052  void adaptToLeader(std::pair<MSVehicle*, SUMOReal> leaderInfo, SUMOReal seen, int lastLink, MSLane* lane, SUMOReal& v, SUMOReal& vLinkPass);
1053 
1054 private:
1055  /* @brief The vehicle's knowledge about edge efforts/travel times; @see MSEdgeWeightsStorage
1056  * @note member is initialized on first access */
1058 
1061 
1062 #ifndef NO_TRACI
1063 
1065 #endif
1066 
1067 #ifdef HAVE_INTERNAL_LANES
1068 
1069  std::set<std::string> myLinkLeaders;
1071  std::map<const MSLink*, std::string> myLeaderForLink;
1072 #endif
1073 
1074 private:
1076  MSVehicle();
1077 
1079  MSVehicle(const MSVehicle&);
1080 
1082  MSVehicle& operator=(const MSVehicle&);
1083 
1085 
1086 };
1087 
1088 
1089 #endif
1090 
1091 /****************************************************************************/
1092