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 
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 
207 
208 
209 
210 
223  bool moveChecked();
224 
225 
233  SUMOReal gap2pred(const MSVehicle& pred) const {
235  if (gap < 0 && gap > -1.0e-12) {
236  gap = 0;
237  }
238  return gap;
239  }
240 
241 
249  static inline SUMOReal gap(SUMOReal predPos, SUMOReal predLength, SUMOReal pos) {
250  return predPos - predLength - pos;
251  }
252 
253 
254 
256 
257 
275  void workOnMoveReminders(SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed);
277 
278 
279 
287  void move(SUMOTime t, MSLane* lane, MSVehicle* pred, MSVehicle* neigh, SUMOReal lengthsInFront);
288 
290 
291 
296  return myState.myPos;
297  }
298 
299 
303  SUMOReal getSpeed() const {
304  return myState.mySpeed;
305  }
306 
307 
312  return myAcceleration;
313  }
315 
316 
317 
319 
320 
328  Position getPosition() const;
329 
330 
334  MSLane* getLane() const {
335  return myLane;
336  }
337 
338 
342  inline bool isOnRoad() const {
343  return myAmOnNet;
344  }
345 
346 
354  return myWaitingTime;
355  }
356 
357 
365  return STEPS2TIME(myWaitingTime);
366  }
367 
368 
372  SUMOReal getAngle() const;
374 
375 
376  class Influencer;
377 
379  static bool overlap(const MSVehicle* veh1, const MSVehicle* veh2) {
380  if (veh1->myState.myPos < veh2->myState.myPos) {
381  return veh2->myState.myPos - veh2->getVehicleType().getLengthWithGap() < veh1->myState.myPos;
382  }
383  return veh1->myState.myPos - veh1->getVehicleType().getLengthWithGap() < veh2->myState.myPos;
384  }
385 
386 
389  bool congested() const {
390  return myState.mySpeed < SUMOReal(60) / SUMOReal(3.6);
391  }
392 
393 
405 
412  bool enterLaneAtMove(MSLane* enteredLane, bool onTeleporting = false);
413 
414 
415 
423  void enterLaneAtInsertion(MSLane* enteredLane, SUMOReal pos, SUMOReal speed,
424  MSMoveReminder::Notification notification);
425 
426 
431  void enterLaneAtLaneChange(MSLane* enteredLane);
432 
433 
435  void leaveLane(const MSMoveReminder::Notification reason);
436 
437 
438 
439 
440 
443 
446 
450  struct LaneQ {
464  std::vector<MSLane*> bestContinuations;
465  };
466 
485  virtual const std::vector<LaneQ>& getBestLanes(bool forceRebuild = false, MSLane* startLane = 0) const;
486 
487 
492  const std::vector<MSLane*>& getBestLanesContinuation() const;
493 
498  const std::vector<MSLane*>& getBestLanesContinuation(const MSLane* const l) const;
500 
501 
510  void replaceVehicleType(MSVehicleType* type);
511 
512 
520  inline const MSCFModel& getCarFollowModel() const {
521  return myType->getCarFollowModel();
522  }
523 
524 
530  return myCFVariables;
531  }
532 
533 
535 
536 
540  struct Stop {
544  const MSLane* lane;
556  bool triggered;
558  bool parking;
560  bool reached;
561  };
562 
563 
570  bool addStop(const SUMOVehicleParameter::Stop& stopPar, SUMOTime untilOffset = 0);
571 
572 
576  bool hasStops() const {
577  return !myStops.empty();
578  }
579 
583  bool isStopped() const;
584 
588  bool isParking() const;
590 
591  bool knowsEdgeTest(MSEdge& edge) const;
592  unsigned int getLaneIndex() const;
593 
603  SUMOReal getDistanceToPosition(SUMOReal destPos, const MSEdge* destEdge);
604 
605 
612  SUMOReal processNextStop(SUMOReal currentVelocity);
613 
614 
616 
617 
622 
623 
628 
629 
634 
635 
640 
641 
646 
647 
652 
653 
659 
660 
661 
663 
664 
668  void addPerson(MSPerson* person);
669 
670 
674  unsigned int getPersonNumber() const;
675 
676 
679 
683  enum Signalling {
714  };
715 
716 
720  void switchOnSignal(int signal) {
721  mySignals |= signal;
722  }
723 
724 
728  void switchOffSignal(int signal) {
729  mySignals &= ~signal;
730  }
731 
732 
736  int getSignals() const {
737  return mySignals;
738  }
739 
740 
745  bool signalSet(int which) const {
746  return (mySignals & which) != 0;
747  }
749 
750 
751 
752 
753 #ifndef NO_TRACI
754 
762 
772  bool addTraciStop(MSLane* lane, SUMOReal pos, SUMOReal radius, SUMOTime duration);
773 
774 
785  class Influencer {
786  public:
788  Influencer();
789 
790 
792  ~Influencer();
793 
794 
798  void setSpeedTimeLine(const std::vector<std::pair<SUMOTime, SUMOReal> >& speedTimeLine);
799 
800 
804  void setLaneTimeLine(const std::vector<std::pair<SUMOTime, unsigned int> >& laneTimeLine);
805 
806 
818  SUMOReal influenceSpeed(SUMOTime currentTime, SUMOReal speed, SUMOReal vSafe, SUMOReal vMin, SUMOReal vMax);
819 
820 
821  ChangeRequest checkForLaneChanges(SUMOTime currentTime, const MSEdge& currentEdge, unsigned int currentLaneIndex);
822 
823 
827  void setConsiderSafeVelocity(bool value);
828 
829 
833  void setConsiderMaxAcceleration(bool value);
834 
835 
839  void setConsiderMaxDeceleration(bool value);
840 
841 
846  return myOriginalSpeed;
847  }
848 
849  private:
851  std::vector<std::pair<SUMOTime, SUMOReal> > mySpeedTimeLine;
852 
854  std::vector<std::pair<SUMOTime, unsigned int> > myLaneTimeLine;
855 
858 
861 
864 
867 
870  };
871 
872 
879 
880 
881 #endif
882 
883 protected:
884 
885  void checkRewindLinkLanes(SUMOReal lengthsInFront);
886  SUMOReal getSpaceTillLastStanding(MSLane* l, bool& foundStopped);
887 
890 
906  void adaptLaneEntering2MoveReminder(const MSLane& enteredLane);
908 
909 
910 
911  void setBlinkerInformation();
912 
913 
916 
919 
920 #ifdef _MESSAGES
921 
922  MSMessageEmitter* myLCMsgEmitter;
923  MSMessageEmitter* myBMsgEmitter;
924  MSMessageEmitter* myHBMsgEmitter;
925 #endif
926 
929 
932 
934 
935  mutable const MSEdge* myLastBestLanesEdge;
936  mutable std::vector<std::vector<LaneQ> > myBestLanes;
937  mutable std::vector<LaneQ>::iterator myCurrentLaneInBestLanes;
938  static std::vector<MSLane*> myEmptyLaneVector;
939 
941  std::list<Stop> myStops;
942 
945 
948 
950  std::vector<MSLane*> myFurtherLanes;
951 
954 
956  bool myAmOnNet;
957 
960 
962 
963 protected:
973  DriveProcessItem(MSLink* link, SUMOReal vPass, SUMOReal vWait, bool setRequest,
974  SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal distance) :
975  myLink(link), myVLinkPass(vPass), myVLinkWait(vWait), mySetRequest(setRequest),
976  myArrivalTime(arrivalTime), myArrivalSpeed(arrivalSpeed), myDistance(distance),
977  accelV(-1) { };
979  if (accelV < 0) {
980  accelV = v;
981  } else {
982  accelV = MIN2(accelV, v);
983  }
984  }
986  return accelV < 0 ? myVLinkPass : accelV;
987  }
988  };
989 
990  typedef std::vector< DriveProcessItem > DriveItemVector;
991 
994 
995 
996 private:
997  /* @brief The vehicle's knowledge about edge efforts/travel times; @see MSEdgeWeightsStorage
998  * @note member is initialized on first access */
1000 
1003 
1004 #ifndef NO_TRACI
1005 
1007 #endif
1008 
1009 private:
1011  MSVehicle();
1012 
1014  MSVehicle(const MSVehicle&);
1015 
1017  MSVehicle& operator=(const MSVehicle&);
1018 
1020 
1021 };
1022 
1023 
1024 #endif
1025 
1026 /****************************************************************************/
1027