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-2012 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 
138  MSVehicle(SUMOVehicleParameter* pars, const MSRoute* route,
139  const MSVehicleType* type, int vehicleIndex) ;
140 
142  virtual ~MSVehicle() ;
143 
144 
145 
147 
148 
158 
159 
160 
162 
163 
167  bool ends() const ;
168 
169 
178  bool replaceRoute(const MSRoute* route, bool onInit = false) ;
179 
180 
186  bool willPass(const MSEdge* const edge) const ;
187 
188 
196 
197 
198 
199 
200 
201 
214  bool moveChecked();
215 
216 
224  SUMOReal gap2pred(const MSVehicle& pred) const {
226  if (gap < 0 && gap > -1.0e-12) {
227  gap = 0;
228  }
229  return gap;
230  }
231 
232 
240  static inline SUMOReal gap(SUMOReal predPos, SUMOReal predLength, SUMOReal pos) {
241  return predPos - predLength - pos;
242  }
243 
244 
245 
247 
248 
266  void workOnMoveReminders(SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed) ;
268 
269 
270 
279  bool moveRegardingCritical(SUMOTime t, const MSLane* const lane, const MSVehicle* const pred,
280  const MSVehicle* const neigh, SUMOReal lengthsInFront) ;
281 
282 
283 
285 
286 
291  return myState.myPos;
292  }
293 
294 
298  SUMOReal getSpeed() const {
299  return myState.mySpeed;
300  }
301 
302 
308  }
310 
311 
312 
314 
315 
323  Position getPosition() const ;
324 
325 
329  MSLane* getLane() const {
330  return myLane;
331  }
332 
333 
337  inline bool isOnRoad() const {
338  return myAmOnNet;
339  }
340 
341 
349  return myWaitingTime;
350  }
351 
352 
360  return STEPS2TIME(myWaitingTime);
361  }
362 
363 
367  SUMOReal getAngle() const ;
369 
370 
371  class Influencer;
372 
373  void setIndividualMaxSpeed(SUMOReal individualMaxSpeed) {
375  myIndividualMaxSpeed = individualMaxSpeed;
376  }
377 
379  myHasIndividualMaxSpeed = false;
380  }
381 
383  myPreDawdleAcceleration = accel;
384  }
385 
386 
388  static bool overlap(const MSVehicle* veh1, const MSVehicle* veh2) {
389  if (veh1->myState.myPos < veh2->myState.myPos) {
390  return veh2->myState.myPos - veh2->getVehicleType().getLengthWithGap() < veh1->myState.myPos;
391  }
392  return veh1->myState.myPos - veh1->getVehicleType().getLengthWithGap() < veh2->myState.myPos;
393  }
394 
395 
398  bool congested() const {
399  return myState.mySpeed < SUMOReal(60) / SUMOReal(3.6);
400  }
401 
402 
414 
421  bool enterLaneAtMove(MSLane* enteredLane, bool onTeleporting = false);
422 
423 
424 
432  void enterLaneAtInsertion(MSLane* enteredLane, SUMOReal pos, SUMOReal speed,
433  MSMoveReminder::Notification notification) ;
434 
435 
440  void enterLaneAtLaneChange(MSLane* enteredLane);
441 
442 
444  void leaveLane(const MSMoveReminder::Notification reason);
445 
446 
447  void vsafeCriticalCont(SUMOTime t, SUMOReal boundVSafe);
448 
449 
450 
453 
456 
460  struct LaneQ {
474  std::vector<MSLane*> bestContinuations;
475  };
476 
495  virtual const std::vector<LaneQ> &getBestLanes(bool forceRebuild = false, MSLane* startLane = 0) const ;
496 
497 
502  const std::vector<MSLane*> &getBestLanesContinuation() const ;
503 
508  const std::vector<MSLane*> &getBestLanesContinuation(const MSLane* const l) const ;
510 
511 
520  void replaceVehicleType(MSVehicleType* type) ;
521 
522 
530  inline const MSCFModel& getCarFollowModel() const {
531  return myType->getCarFollowModel();
532  }
533 
534 
540  return myCFVariables;
541  }
542 
543 
545 
546 
550  struct Stop {
554  const MSLane* lane;
566  bool triggered;
568  bool parking;
570  bool reached;
571  };
572 
573 
580  bool addStop(const SUMOVehicleParameter::Stop& stopPar, SUMOTime untilOffset = 0) ;
581 
582 
586  bool hasStops() const {
587  return !myStops.empty();
588  }
589 
593  bool isStopped() const;
594 
598  bool isParking() const;
600 
601  bool knowsEdgeTest(MSEdge& edge) const;
602  unsigned int getLaneIndex() const;
603 
613  SUMOReal getDistanceToPosition(SUMOReal destPos, const MSEdge* destEdge);
614 
615 
622  SUMOReal processNextStop(SUMOReal currentVelocity) ;
623 
624 
626 
627 
632 
633 
638 
639 
644 
645 
650 
651 
656 
657 
662 
663 
669 
670  void addPerson(MSPerson* person) ;
671 
672 
673 
676 
680  enum Signalling {
711  };
712 
713 
717  void switchOnSignal(int signal) {
718  mySignals |= signal;
719  }
720 
721 
725  void switchOffSignal(int signal) {
726  mySignals &= ~signal;
727  }
728 
729 
733  int getSignals() const {
734  return mySignals;
735  }
736 
737 
742  bool signalSet(int which) const {
743  return (mySignals & which) != 0;
744  }
746 
747 
748 
749 
750 #ifndef NO_TRACI
751 
759 
769  bool addTraciStop(MSLane* lane, SUMOReal pos, SUMOReal radius, SUMOTime duration);
770 
771 
782  class Influencer {
783  public:
785  Influencer();
786 
787 
789  ~Influencer();
790 
791 
795  void setSpeedTimeLine(const std::vector<std::pair<SUMOTime, SUMOReal> > &speedTimeLine);
796 
797 
801  void setLaneTimeLine(const std::vector<std::pair<SUMOTime, unsigned int> > &laneTimeLine);
802 
803 
815  SUMOReal influenceSpeed(SUMOTime currentTime, SUMOReal speed, SUMOReal vSafe, SUMOReal vMin, SUMOReal vMax);
816 
817 
818  ChangeRequest checkForLaneChanges(SUMOTime currentTime, const MSEdge& currentEdge, unsigned int currentLaneIndex);
819 
820 
824  void setConsiderSafeVelocity(bool value);
825 
826 
830  void setConsiderMaxAcceleration(bool value);
831 
832 
836  void setConsiderMaxDeceleration(bool value);
837 
838 
843  return myOriginalSpeed;
844  }
845 
846 
847  private:
849  std::vector<std::pair<SUMOTime, SUMOReal> > mySpeedTimeLine;
850 
852  std::vector<std::pair<SUMOTime, unsigned int> > myLaneTimeLine;
853 
856 
859 
862 
865 
868  };
869 
870 
877 
878 
879 #endif
880 
881 protected:
882 
883  void checkRewindLinkLanes(SUMOReal lengthsInFront) ;
884  SUMOReal getSpaceTillLastStanding(MSLane* l, bool& foundStopped) ;
885 
888 
904  void adaptLaneEntering2MoveReminder(const MSLane& enteredLane) ;
906 
907 
908 
909  void setBlinkerInformation() ;
910 
911 
914 
917 
918 #ifdef _MESSAGES
919 
920  MSMessageEmitter* myLCMsgEmitter;
921  MSMessageEmitter* myBMsgEmitter;
922  MSMessageEmitter* myHBMsgEmitter;
923 #endif
924 
927 
930 
932 
933  mutable const MSEdge* myLastBestLanesEdge;
934  mutable std::vector<std::vector<LaneQ> > myBestLanes;
935  mutable std::vector<LaneQ>::iterator myCurrentLaneInBestLanes;
936  static std::vector<MSLane*> myEmptyLaneVector;
937 
939  std::list<Stop> myStops;
940 
943 
946 
948  std::vector<MSLane*> myFurtherLanes;
949 
952 
954  bool myAmOnNet;
955 
958 
960 
961 protected:
970  DriveProcessItem(MSLink* link, SUMOReal vPass, SUMOReal vWait, bool setRequest,
971  SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal distance) :
972  myLink(link), myVLinkPass(vPass), myVLinkWait(vWait), mySetRequest(setRequest),
973  myArrivalTime(arrivalTime), myArrivalSpeed(arrivalSpeed), myDistance(distance) { };
974  };
975 
976  typedef std::vector< DriveProcessItem > DriveItemVector;
977 
980 
981 
982 private:
985 
988 
989 #ifndef NO_TRACI
990 
992 #endif
993 
994 private:
996  MSVehicle();
997 
999  MSVehicle(const MSVehicle&);
1000 
1002  MSVehicle& operator=(const MSVehicle&);
1003 
1004 
1005 };
1006 
1007 
1008 #endif
1009 
1010 /****************************************************************************/
1011