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-2014 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 
143  MSVehicle(SUMOVehicleParameter* pars, const MSRoute* route,
144  const MSVehicleType* type, SUMOReal speedFactor);
145 
147  virtual ~MSVehicle();
148 
149 
150 
152 
153 
163 
164 
165 
167 
168 
172  bool hasArrived() const;
173 
182  bool replaceRoute(const MSRoute* route, bool onInit = false, int offset = 0);
183 
184 
190  bool willPass(const MSEdge* const edge) const;
191 
192  unsigned int getRoutePosition() const;
193  void resetRoutePosition(unsigned int index);
194 
203 
204 
212  static inline SUMOReal gap(SUMOReal predPos, SUMOReal predLength, SUMOReal pos) {
213  return predPos - predLength - pos;
214  }
215 
216 
217 
219 
220 
238  void workOnMoveReminders(SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed);
240 
241 
259  void planMove(const SUMOTime t, const MSVehicle* pred, const SUMOReal lengthsInFront);
260 
261 
274  bool executeMove();
275 
276 
278 
279 
284  return myState.myPos;
285  }
286 
287 
291  SUMOReal getSpeed() const {
292  return myState.mySpeed;
293  }
294 
295 
300  return myAcceleration;
301  }
303 
304 
305 
307 
308 
312  SUMOReal getSlope() const;
313 
314 
322  Position getPosition(const SUMOReal offset = 0) const;
323 
324 
328  MSLane* getLane() const {
329  return myLane;
330  }
331 
332 
336  inline bool isOnRoad() const {
337  return myAmOnNet;
338  }
339 
340 
346  const MSEdge* getRerouteOrigin() const {
347 #ifdef HAVE_INTERNAL_LANES
348  if (myLane != 0) {
349  return myLane->getInternalFollower();
350  }
351 #endif
352  return *myCurrEdge;
353  }
354 
355 
363  return myWaitingTime;
364  }
365 
366 
374  return STEPS2TIME(myWaitingTime);
375  }
376 
377 
381  SUMOReal getAngle() const;
383 
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 
447 
450 
454  struct LaneQ {
468  std::vector<MSLane*> bestContinuations;
469  };
470 
474  const std::vector<LaneQ>& getBestLanes() const;
475 
493  void updateBestLanes(bool forceRebuild = false, const MSLane* startLane = 0);
494 
495 
500  const std::vector<MSLane*>& getBestLanesContinuation() const;
501 
506  const std::vector<MSLane*>& getBestLanesContinuation(const MSLane* const l) const;
507 
509  int getBestLaneOffset() const;
510 
512  void adaptBestLanesOccupation(int laneIndex, SUMOReal density);
513 
515 
517  bool fixPosition();
518 
519 
528  void replaceVehicleType(MSVehicleType* type);
529 
530 
538  inline const MSCFModel& getCarFollowModel() const {
539  return myType->getCarFollowModel();
540  }
541 
542 
548  return myCFVariables;
549  }
550 
551 
553 
554 
558  struct Stop {
562  const MSLane* lane;
574  bool triggered;
576  bool parking;
578  bool reached;
580  std::set<std::string> awaitedPersons;
581  };
582 
583 
590  bool addStop(const SUMOVehicleParameter::Stop& stopPar, SUMOTime untilOffset = 0);
591 
592 
596  bool hasStops() const {
597  return !myStops.empty();
598  }
599 
603  bool isStopped() const;
604 
608  bool isParking() const;
609 
610 
614  bool isStoppedTriggered() const;
616 
617  bool knowsEdgeTest(MSEdge& edge) const;
618  unsigned int getLaneIndex() const;
619 
629  SUMOReal getDistanceToPosition(SUMOReal destPos, const MSEdge* destEdge);
630 
631 
638  SUMOReal processNextStop(SUMOReal currentVelocity);
639 
647  std::pair<const MSVehicle* const, SUMOReal> getLeader(SUMOReal dist = 0) const;
648 
655  SUMOReal getTimeGap() const;
656 
657 
659 
660 
664  SUMOReal getCO2Emissions() const;
665 
666 
670  SUMOReal getCOEmissions() const;
671 
672 
676  SUMOReal getHCEmissions() const;
677 
678 
682  SUMOReal getNOxEmissions() const;
683 
684 
688  SUMOReal getPMxEmissions() const;
689 
690 
695 
696 
702 
703 
704 
706 
707 
711  void addPerson(MSPerson* person);
712 
713 
717  unsigned int getPersonNumber() const;
718 
721 
725  enum Signalling {
756  };
757 
758 
764  LC_NEVER = 0, // lcModel shall never trigger changes at this level
765  LC_NOCONFLICT = 1, // lcModel may trigger changes if not in conflict with TraCI request
766  LC_ALWAYS = 2 // lcModel may always trigger changes of this level regardless of requests
767  };
768 
769 
772  LCP_ALWAYS = 0, // change regardless of blockers, adapt own speed and speed of blockers
773  LCP_NOOVERLAP = 1, // change unless overlapping with blockers, adapt own speed and speed of blockers
774  LCP_URGENT = 2, // change if not blocked, adapt own speed and speed of blockers
775  LCP_OPPORTUNISTIC = 3 // change if not blocked
776  };
777 
778 
782  void switchOnSignal(int signal) {
783  mySignals |= signal;
784  }
785 
786 
790  void switchOffSignal(int signal) {
791  mySignals &= ~signal;
792  }
793 
794 
798  int getSignals() const {
799  return mySignals;
800  }
801 
802 
807  bool signalSet(int which) const {
808  return (mySignals & which) != 0;
809  }
811 
812 
813 #ifndef NO_TRACI
814 
822 
833  bool addTraciStop(MSLane* lane, SUMOReal pos, SUMOReal radius, SUMOTime duration, bool parking, bool triggered);
834 
839  Stop& getNextStop();
840 
845  bool resumeFromStopping();
846 
847 
860  class Influencer {
861  public:
863  Influencer();
864 
865 
867  ~Influencer();
868 
869 
873  void setSpeedTimeLine(const std::vector<std::pair<SUMOTime, SUMOReal> >& speedTimeLine);
874 
875 
879  void setLaneTimeLine(const std::vector<std::pair<SUMOTime, unsigned int> >& laneTimeLine);
880 
881 
893  SUMOReal influenceSpeed(SUMOTime currentTime, SUMOReal speed, SUMOReal vSafe, SUMOReal vMin, SUMOReal vMax);
894 
902  int influenceChangeDecision(const SUMOTime currentTime, const MSEdge& currentEdge, const unsigned int currentLaneIndex, int state);
903 
904 
910  SUMOReal changeRequestRemainingSeconds(const SUMOTime currentTime) const;
911 
915  void setConsiderSafeVelocity(bool value);
916 
917 
921  void setConsiderMaxAcceleration(bool value);
922 
923 
927  void setConsiderMaxDeceleration(bool value);
928 
929 
933  void setRespectJunctionPriority(bool value);
934 
935 
939  inline bool getRespectJunctionPriority() const {
941  }
942 
943 
947  void setEmergencyBrakeRedLight(bool value);
948 
949 
953  inline bool getEmergencyBrakeRedLight() const {
955  }
956 
957 
961  void setLaneChangeMode(int value);
962 
963 
967  inline SUMOReal getOriginalSpeed() const {
968  return myOriginalSpeed;
969  }
970 
971  void setVTDControlled(bool c, MSLane* l, SUMOReal pos, int edgeOffset, const MSEdgeVector& route) {
972  myAmVTDControlled = c;
973  myVTDLane = l;
974  myVTDPos = pos;
975  myVTDEdgeOffset = edgeOffset;
976  myVTDRoute = route;
977  }
978 
979  void postProcessVTD(MSVehicle* v);
980 
981  inline bool isVTDControlled() const {
982  return myAmVTDControlled;
983  }
984 
985  private:
987  std::vector<std::pair<SUMOTime, SUMOReal> > mySpeedTimeLine;
988 
990  std::vector<std::pair<SUMOTime, unsigned int> > myLaneTimeLine;
991 
994 
997 
1000 
1003 
1006 
1009 
1012 
1018 
1020 
1021 
1030 
1032 
1033  };
1034 
1035 
1042 
1043  bool hasInfluencer() const {
1044  return myInfluencer != 0;
1045  }
1046 
1048  int influenceChangeDecision(int state);
1049 
1050 
1051 #endif
1052 
1054 
1055 
1057  void saveState(OutputDevice& out);
1058 
1061  void loadState(const SUMOSAXAttributes& attrs, const SUMOTime offset);
1063 
1064 protected:
1065 
1066  SUMOReal getSpaceTillLastStanding(const MSLane* l, bool& foundStopped) const;
1067 
1070 
1086  void adaptLaneEntering2MoveReminder(const MSLane& enteredLane);
1088 
1089 
1090 
1091  void setBlinkerInformation();
1092 
1094  void updateOccupancyAndCurrentBestLane(const MSLane* startLane);
1095 
1096 
1099 
1102 
1105 
1107 
1110 
1111  std::vector<std::vector<LaneQ> > myBestLanes;
1112  std::vector<LaneQ>::iterator myCurrentLaneInBestLanes;
1113  static std::vector<MSLane*> myEmptyLaneVector;
1114 
1116  std::list<Stop> myStops;
1117 
1120 
1123 
1125  std::vector<MSLane*> myFurtherLanes;
1126 
1129 
1132 
1135 
1137 
1139 
1140 protected:
1154 
1155  DriveProcessItem(MSLink* link, SUMOReal vPass, SUMOReal vWait, bool setRequest,
1156  SUMOTime arrivalTime, SUMOReal arrivalSpeed,
1157  SUMOTime arrivalTimeBraking, SUMOReal arrivalSpeedBraking,
1158  SUMOReal distance,
1159  SUMOReal leaveSpeed = -1.) :
1160  myLink(link), myVLinkPass(vPass), myVLinkWait(vWait), mySetRequest(setRequest),
1161  myArrivalTime(arrivalTime), myArrivalSpeed(arrivalSpeed),
1162  myArrivalTimeBraking(arrivalTimeBraking), myArrivalSpeedBraking(arrivalSpeedBraking),
1163  myDistance(distance),
1164  accelV(leaveSpeed), hadVehicle(false), availableSpace(-1.) {
1165  assert(vWait >= 0);
1166  assert(vPass >= 0);
1167  };
1168 
1171  myLink(0), myVLinkPass(vWait), myVLinkWait(vWait), mySetRequest(false),
1174  myDistance(distance),
1175  accelV(-1), hadVehicle(false), availableSpace(-1.) {
1176  assert(vWait >= 0);
1177  };
1178 
1179 
1180  inline void adaptLeaveSpeed(const SUMOReal v) {
1181  if (accelV < 0) {
1182  accelV = v;
1183  } else {
1184  accelV = MIN2(accelV, v);
1185  }
1186  }
1187  inline SUMOReal getLeaveSpeed() const {
1188  return accelV < 0 ? myVLinkPass : accelV;
1189  }
1190  };
1191 
1192  typedef std::vector< DriveProcessItem > DriveItemVector;
1193 
1196 
1197  void planMoveInternal(const SUMOTime t, const MSVehicle* pred, DriveItemVector& lfLinks) const;
1198  void checkRewindLinkLanes(const SUMOReal lengthsInFront, DriveItemVector& lfLinks) const;
1199 
1201  inline SUMOReal estimateLeaveSpeed(const MSLink* const link, const SUMOReal vLinkPass) const {
1202  // estimate leave speed for passing time computation
1203  // l=linkLength, a=accel, t=continuousTime, v=vLeave
1204  // l=v*t + 0.5*a*t^2, solve for t and multiply with a, then add v
1205  return MIN2(link->getViaLaneOrLane()->getVehicleMaxSpeed(this),
1207  }
1208 
1209  /* @brief estimate speed while accelerating for the given distance
1210  * @param[in] dist The distance during which accelerating takes place
1211  * @param[in] v The initial speed
1212  * @param[in] accel The acceleration
1213  */
1214  inline SUMOReal estimateSpeedAfterDistance(const SUMOReal dist, const SUMOReal v, const SUMOReal accel) const {
1215  // dist=v*t + 0.5*accel*t^2, solve for t and multiply with accel, then add v
1216  return MIN2(getVehicleType().getMaxSpeed(),
1217  (SUMOReal)sqrt(2 * dist * accel + v * v));
1218  }
1219 
1220 
1221  /* @brief estimate speed while accelerating for the given distance
1222  * @param[in] leaderInfo The leading vehicle and the (virtual) distance to it
1223  * @param[in] seen the distance to the end of the current lane
1224  * @param[in] lastLink the lastLink index
1225  * @param[in] lane The current Lane the vehicle is on
1226  * @param[in,out] the safe velocity for driving
1227  * @param[in,out] the safe velocity for arriving at the next link
1228  * @param[in] distToCrossing The distance to the crossing point with the current leader where relevant or -1
1229  */
1230  void adaptToLeader(const std::pair<const MSVehicle*, SUMOReal> leaderInfo,
1231  const SUMOReal seen, DriveProcessItem* const lastLink,
1232  const MSLane* const lane, SUMOReal& v, SUMOReal& vLinkPass,
1233  SUMOReal distToCrossing = -1) const;
1234 
1235 #ifdef HAVE_INTERNAL_LANES
1236 
1237  mutable std::set<std::string> myLinkLeaders;
1238 #endif
1239 
1240 private:
1241  /* @brief The vehicle's knowledge about edge efforts/travel times; @see MSEdgeWeightsStorage
1242  * @note member is initialized on first access */
1244 
1247 
1248 #ifndef NO_TRACI
1249 
1251 #endif
1252 
1253 private:
1255  MSVehicle();
1256 
1258  MSVehicle(const MSVehicle&);
1259 
1261  MSVehicle& operator=(const MSVehicle&);
1262 
1264 
1265 };
1266 
1267 
1268 #endif
1269 
1270 /****************************************************************************/
1271