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-sim.org/
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 <set>
45 #include <string>
46 #include <vector>
47 #include "MSVehicleType.h"
48 #include "MSBaseVehicle.h"
49 #include "MSLink.h"
50 #include "MSLane.h"
51 
52 
53 // ===========================================================================
54 // class declarations
55 // ===========================================================================
56 class SUMOSAXAttributes;
57 class MSMoveReminder;
58 class MSLaneChanger;
59 class MSVehicleTransfer;
61 class MSBusStop;
62 class MSPerson;
63 class MSDevice;
65 class OutputDevice;
66 class Position;
67 class MSDevice_Person;
68 
69 
70 // ===========================================================================
71 // class definitions
72 // ===========================================================================
77 class MSVehicle : public MSBaseVehicle {
78 public:
79 
81  friend class MSLaneChanger;
82 
86  class State {
88  friend class MSVehicle;
89  friend class MSLaneChanger;
90 
91  public:
94 
96  State(const State& state);
97 
99  State& operator=(const State& state);
100 
102  bool operator!=(const State& state);
103 
105  SUMOReal pos() const;
106 
108  SUMOReal speed() const {
109  return mySpeed;
110  };
111 
112  private:
114  SUMOReal myPos;
115 
118 
119  };
120 
121 
134  };
135 
144  MSVehicle(SUMOVehicleParameter* pars, const MSRoute* route,
145  const MSVehicleType* type, SUMOReal speedFactor, int vehicleIndex);
146 
148  virtual ~MSVehicle();
149 
150 
151 
153 
154 
164 
165 
166 
168 
169 
173  bool hasArrived() const;
174 
183  bool replaceRoute(const MSRoute* route, bool onInit = false);
184 
185 
191  bool willPass(const MSEdge* const edge) const;
192 
193  unsigned int getRoutePosition() const;
194  void resetRoutePosition(unsigned int index);
195 
204 
205 
213  static inline SUMOReal gap(SUMOReal predPos, SUMOReal predLength, SUMOReal pos) {
214  return predPos - predLength - pos;
215  }
216 
217 
218 
220 
221 
239  void workOnMoveReminders(SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed);
241 
242 
260  void planMove(const SUMOTime t, const MSVehicle* pred, const SUMOReal lengthsInFront);
261 
262 
275  bool executeMove();
276 
277 
279 
280 
285  return myState.myPos;
286  }
287 
288 
292  SUMOReal getSpeed() const {
293  return myState.mySpeed;
294  }
295 
296 
301  return myAcceleration;
302  }
304 
305 
306 
308 
309 
317  Position getPosition(SUMOReal offset = 0) const;
318 
319 
323  MSLane* getLane() const {
324  return myLane;
325  }
326 
327 
331  inline bool isOnRoad() const {
332  return myAmOnNet;
333  }
334 
335 
343  return myWaitingTime;
344  }
345 
346 
354  return STEPS2TIME(myWaitingTime);
355  }
356 
357 
361  SUMOReal getAngle() const;
363 
364 
365  class Influencer;
366 
368  static bool overlap(const MSVehicle* veh1, const MSVehicle* veh2) {
369  if (veh1->myState.myPos < veh2->myState.myPos) {
370  return veh2->myState.myPos - veh2->getVehicleType().getLengthWithGap() < veh1->myState.myPos;
371  }
372  return veh1->myState.myPos - veh1->getVehicleType().getLengthWithGap() < veh2->myState.myPos;
373  }
374 
375 
378  bool congested() const {
379  return myState.mySpeed < SUMOReal(60) / SUMOReal(3.6);
380  }
381 
382 
394 
401  bool enterLaneAtMove(MSLane* enteredLane, bool onTeleporting = false);
402 
403 
404 
412  void enterLaneAtInsertion(MSLane* enteredLane, SUMOReal pos, SUMOReal speed,
413  MSMoveReminder::Notification notification);
414 
415 
420  void enterLaneAtLaneChange(MSLane* enteredLane);
421 
422 
424  void leaveLane(const MSMoveReminder::Notification reason);
425 
426 
429 
432 
436  struct LaneQ {
450  std::vector<MSLane*> bestContinuations;
451  };
452 
471  virtual const std::vector<LaneQ>& getBestLanes(bool forceRebuild = false, MSLane* startLane = 0) const;
472 
473 
478  const std::vector<MSLane*>& getBestLanesContinuation() const;
479 
484  const std::vector<MSLane*>& getBestLanesContinuation(const MSLane* const l) const;
485 
486 
488  bool fixContinuations();
490 
492  bool fixPosition();
493 
494 
503  void replaceVehicleType(MSVehicleType* type);
504 
505 
513  inline const MSCFModel& getCarFollowModel() const {
514  return myType->getCarFollowModel();
515  }
516 
517 
523  return myCFVariables;
524  }
525 
526 
528 
529 
533  struct Stop {
537  const MSLane* lane;
549  bool triggered;
551  bool parking;
553  bool reached;
555  std::set<std::string> awaitedPersons;
556  };
557 
558 
565  bool addStop(const SUMOVehicleParameter::Stop& stopPar, SUMOTime untilOffset = 0);
566 
567 
571  bool hasStops() const {
572  return !myStops.empty();
573  }
574 
578  bool isStopped() const;
579 
583  bool isParking() const;
584 
585 
589  bool isStoppedTriggered() const;
591 
592  bool knowsEdgeTest(MSEdge& edge) const;
593  unsigned int getLaneIndex() const;
594 
604  SUMOReal getDistanceToPosition(SUMOReal destPos, const MSEdge* destEdge);
605 
606 
613  SUMOReal processNextStop(SUMOReal currentVelocity);
614 
615 
617 
618 
623 
624 
629 
630 
635 
636 
641 
642 
647 
648 
653 
654 
660 
661 
662 
664 
665 
669  void addPerson(MSPerson* person);
670 
671 
675  unsigned int getPersonNumber() const;
676 
678  SUMOReal getImpatience() const;
679 
682 
686  enum Signalling {
717  };
718 
719 
723  void switchOnSignal(int signal) {
724  mySignals |= signal;
725  }
726 
727 
731  void switchOffSignal(int signal) {
732  mySignals &= ~signal;
733  }
734 
735 
739  int getSignals() const {
740  return mySignals;
741  }
742 
743 
748  bool signalSet(int which) const {
749  return (mySignals & which) != 0;
750  }
752 
753 
754 #ifndef NO_TRACI
755 
763 
774  bool addTraciStop(MSLane* lane, SUMOReal pos, SUMOReal radius, SUMOTime duration, bool parking, bool triggered);
775 
780  Stop& getNextStop();
781 
786  bool resumeFromStopping();
787 
788 
799  class Influencer {
800  public:
802  Influencer();
803 
804 
806  ~Influencer();
807 
808 
812  void setSpeedTimeLine(const std::vector<std::pair<SUMOTime, SUMOReal> >& speedTimeLine);
813 
814 
818  void setLaneTimeLine(const std::vector<std::pair<SUMOTime, unsigned int> >& laneTimeLine);
819 
820 
832  SUMOReal influenceSpeed(SUMOTime currentTime, SUMOReal speed, SUMOReal vSafe, SUMOReal vMin, SUMOReal vMax);
833 
834 
835  ChangeRequest checkForLaneChanges(SUMOTime currentTime, const MSEdge& currentEdge, unsigned int currentLaneIndex);
836 
837 
841  void setConsiderSafeVelocity(bool value);
842 
843 
847  void setConsiderMaxAcceleration(bool value);
848 
849 
853  void setConsiderMaxDeceleration(bool value);
854 
855 
860  return myOriginalSpeed;
861  }
862 
863  void setVTDControlled(bool c, MSLane* l, SUMOReal pos, int edgeOffset, const MSEdgeVector& route) {
864  myAmVTDControlled = c;
865  myVTDLane = l;
866  myVTDPos = pos;
867  myVTDEdgeOffset = edgeOffset;
868  myVTDRoute = route;
869  }
870 
871  void postProcessVTD(MSVehicle* v);
872 
873  bool isVTDControlled() const {
874  return myAmVTDControlled;
875  }
876 
877  private:
879  std::vector<std::pair<SUMOTime, SUMOReal> > mySpeedTimeLine;
880 
882  std::vector<std::pair<SUMOTime, unsigned int> > myLaneTimeLine;
883 
886 
889 
892 
895 
898 
904 
905  };
906 
907 
914 
915  bool hasInfluencer() const {
916  return myInfluencer != 0;
917  }
918 
919 
920 #endif
921 
923 
924 
926  void saveState(OutputDevice& out);
927 
930  void loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset);
932 
933 protected:
934 
935  SUMOReal getSpaceTillLastStanding(const MSLane* l, bool& foundStopped) const;
936 
939 
955  void adaptLaneEntering2MoveReminder(const MSLane& enteredLane);
957 
958 
959 
960  void setBlinkerInformation();
961 
962 
965 
968 
971 
973 
974  mutable const MSEdge* myLastBestLanesEdge;
975  mutable std::vector<std::vector<LaneQ> > myBestLanes;
976  mutable std::vector<LaneQ>::iterator myCurrentLaneInBestLanes;
977  static std::vector<MSLane*> myEmptyLaneVector;
978 
980  std::list<Stop> myStops;
981 
984 
987 
989  std::vector<MSLane*> myFurtherLanes;
990 
993 
995  bool myAmOnNet;
996 
999 
1001 
1002 protected:
1016 
1017  DriveProcessItem(MSLink* link, SUMOReal vPass, SUMOReal vWait, bool setRequest,
1018  SUMOTime arrivalTime, SUMOReal arrivalSpeed,
1019  SUMOTime arrivalTimeBraking, SUMOReal arrivalSpeedBraking,
1020  SUMOReal distance,
1021  SUMOReal leaveSpeed = -1.) :
1022  myLink(link), myVLinkPass(vPass), myVLinkWait(vWait), mySetRequest(setRequest),
1023  myArrivalTime(arrivalTime), myArrivalSpeed(arrivalSpeed),
1024  myArrivalTimeBraking(arrivalTimeBraking), myArrivalSpeedBraking(arrivalSpeedBraking),
1025  myDistance(distance),
1026  accelV(leaveSpeed), hadVehicle(false), availableSpace(-1.) { };
1027 
1030  myLink(0), myVLinkPass(vWait), myVLinkWait(vWait), mySetRequest(false),
1033  myDistance(distance),
1034  accelV(-1), hadVehicle(false), availableSpace(-1.) { };
1035 
1036 
1037  inline void adaptLeaveSpeed(const SUMOReal v) {
1038  if (accelV < 0) {
1039  accelV = v;
1040  } else {
1041  accelV = MIN2(accelV, v);
1042  }
1043  }
1044  inline SUMOReal getLeaveSpeed() const {
1045  return accelV < 0 ? myVLinkPass : accelV;
1046  }
1047  };
1048 
1049  typedef std::vector< DriveProcessItem > DriveItemVector;
1050 
1053 
1054  void planMoveInternal(const SUMOTime t, const MSVehicle* pred, DriveItemVector& lfLinks) const;
1055  void checkRewindLinkLanes(const SUMOReal lengthsInFront, DriveItemVector& lfLinks) const;
1056 
1058  inline SUMOReal estimateLeaveSpeed(const MSLink* const link, const SUMOReal vLinkPass) const {
1059  // estimate leave speed for passing time computation
1060  // l=linkLength, a=accel, t=continuousTime, v=vLeave
1061  // l=v*t + 0.5*a*t^2, solve for t and multiply with a, then add v
1062  return MIN2(link->getViaLaneOrLane()->getVehicleMaxSpeed(this),
1064  }
1065 
1066  /* @brief estimate speed while accelerating for the given distance
1067  * @param[in] dist The distance during which accelerating takes place
1068  * @param[in] v The initial speed
1069  * @param[in] accel The acceleration
1070  */
1071  inline SUMOReal estimateSpeedAfterDistance(const SUMOReal dist, const SUMOReal v, const SUMOReal accel) const {
1072  // dist=v*t + 0.5*accel*t^2, solve for t and multiply with accel, then add v
1073  return MIN2(getVehicleType().getMaxSpeed(),
1074  (SUMOReal)sqrt(2 * dist * accel + v * v));
1075  }
1076 
1077 
1078  /* @brief estimate speed while accelerating for the given distance
1079  * @param[in] leaderInfo The leading vehicle and the (virtual) distance to it
1080  * @param[in] seen the distance to the end of the current lane
1081  * @param[in] lastLink the lastLink index
1082  * @param[in] lane The current Lane the vehicle is on
1083  * @param[in,out] the safe velocity for driving
1084  * @param[in,out] the safe velocity for arriving at the next link
1085  */
1086  void adaptToLeader(const std::pair<const MSVehicle*, SUMOReal> leaderInfo,
1087  const SUMOReal seen, DriveProcessItem* const lastLink,
1088  const MSLane* const lane, SUMOReal& v, SUMOReal& vLinkPass) const;
1089 
1090 #ifdef HAVE_INTERNAL_LANES
1091  mutable std::set<std::string> myLinkLeaders;
1093 #endif
1094 
1095 private:
1096  /* @brief The vehicle's knowledge about edge efforts/travel times; @see MSEdgeWeightsStorage
1097  * @note member is initialized on first access */
1099 
1102 
1103 #ifndef NO_TRACI
1106 #endif
1107 
1108 #ifdef HAVE_INTERNAL_LANES
1109  mutable std::map<const MSLink*, std::string> myLeaderForLink;
1111 #endif
1112 
1113 private:
1115  MSVehicle();
1116 
1118  MSVehicle(const MSVehicle&);
1119 
1121  MSVehicle& operator=(const MSVehicle&);
1122 
1124 
1125 };
1126 
1127 
1128 #endif
1129 
1130 /****************************************************************************/
1131