SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSLane.h
Go to the documentation of this file.
1 /****************************************************************************/
13 // Representation of a lane in the micro simulation
14 /****************************************************************************/
15 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
16 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
17 /****************************************************************************/
18 //
19 // This file is part of SUMO.
20 // SUMO is free software: you can redistribute it and/or modify
21 // it under the terms of the GNU General Public License as published by
22 // the Free Software Foundation, either version 3 of the License, or
23 // (at your option) any later version.
24 //
25 /****************************************************************************/
26 #ifndef MSLane_h
27 #define MSLane_h
28 
29 
30 // ===========================================================================
31 // included modules
32 // ===========================================================================
33 #ifdef _MSC_VER
34 #include <windows_config.h>
35 #else
36 #include <config.h>
37 #endif
38 
39 #include <vector>
40 #include <deque>
41 #include <cassert>
42 #include <utils/common/Named.h>
48 #include "MSLinkCont.h"
49 #include "MSMoveReminder.h"
50 #ifndef NO_TRACI
52 #endif
53 
54 
55 // ===========================================================================
56 // class declarations
57 // ===========================================================================
58 class MSEdge;
59 class MSVehicle;
60 class MSLaneChanger;
61 class MSLink;
62 class MSVehicleTransfer;
63 class MSVehicleControl;
64 class OutputDevice;
65 
66 
67 // ===========================================================================
68 // class definitions
69 // ===========================================================================
77 class MSLane : public Named, public Parameterised {
78 public:
80  friend class MSLaneChanger;
81 
82  friend class MSXMLRawOut;
83 
84  friend class MSQueueExport;
85 
86 
88  typedef std::vector< MSVehicle* > VehCont;
89 
92  struct VehPosition : public std::binary_function < const MSVehicle*, SUMOReal, bool > {
94  bool operator()(const MSVehicle* cmp, SUMOReal pos) const;
95  };
96 
97 public:
110  MSLane(const std::string& id, SUMOReal maxSpeed, SUMOReal length, MSEdge* const edge,
111  unsigned int numericalID, const PositionVector& shape, SUMOReal width,
112  SVCPermissions permissions);
113 
114 
116  virtual ~MSLane();
117 
118 
119 
122 
130  void addLink(MSLink* link);
132 
133 
134 
137 
144  virtual void addMoveReminder(MSMoveReminder* rem);
145 
146 
150  inline const std::vector< MSMoveReminder* >& getMoveReminders() const {
151  return myMoveReminders;
152  }
154 
155 
156 
159 
175  bool insertVehicle(MSVehicle& v);
176 
177 
195  virtual bool isInsertionSuccess(MSVehicle* vehicle, SUMOReal speed, SUMOReal pos,
196  bool recheckNextLanes,
198 
199  bool checkFailure(MSVehicle* aVehicle, SUMOReal& speed, SUMOReal& dist, const SUMOReal nspeed, const bool patchSpeed, const std::string errorMsg) const;
200  bool pWagGenericInsertion(MSVehicle& veh, SUMOReal speed, SUMOReal maxPos, SUMOReal minPos);
201  bool pWagSimpleInsertion(MSVehicle& veh, SUMOReal speed, SUMOReal maxPos, SUMOReal minPos);
202  bool maxSpeedGapInsertion(MSVehicle& veh, SUMOReal mspeed);
203 
211  bool freeInsertion(MSVehicle& veh, SUMOReal speed,
213 
214 
222  void forceVehicleInsertion(MSVehicle* veh, SUMOReal pos);
224 
225 
226 
229 
241  SUMOReal setPartialOccupation(MSVehicle* v, SUMOReal leftVehicleLength);
242 
243 
248 
249 
254  return myInlappingVehicle;
255  }
256 
257 
262  return myInlappingVehicleEnd;
263  }
264 
265 
274  std::pair<MSVehicle*, SUMOReal> getLastVehicleInformation() const;
276 
277 
278 
281 
285  unsigned int getVehicleNumber() const {
286  return (unsigned int) myVehicles.size();
287  }
288 
289 
296  virtual const VehCont& getVehiclesSecure() const {
297  return myVehicles;
298  }
299 
300 
303  virtual void releaseVehicles() const { }
305 
306 
307 
310 
311 
315  inline size_t getNumericalID() const {
316  return myNumericalID;
317  }
318 
319 
323  inline const PositionVector& getShape() const {
324  return myShape;
325  }
326 
329  return myLengthGeometryFactor;
330  }
331 
332  /* @brief fit the given lane position to a visibly suitable geometry position
333  * (lane length might differ from geometry length) */
335  return lanePos * myLengthGeometryFactor;
336  }
337 
338  /* @brief fit the given lane position to a visibly suitable geometry position
339  * and return the coordinates */
340  inline const Position geometryPositionAtOffset(SUMOReal offset) const {
342  }
343 
344  /* @brief fit the given geomtry position to a valid lane position
345  * (lane length might differ from geometry length) */
347  return geometryPos / myLengthGeometryFactor;
348  }
349 
354  inline SUMOReal getVehicleMaxSpeed(const SUMOVehicle* const veh) const {
355  return myMaxSpeed * veh->getChosenSpeedFactor();
356  }
357 
358 
362  inline SUMOReal getSpeedLimit() const {
363  return myMaxSpeed;
364  }
365 
366 
370  inline SUMOReal getLength() const {
371  return myLength;
372  }
373 
374 
379  return myPermissions;
380  }
381 
382 
386  SUMOReal getWidth() const {
387  return myWidth;
388  }
390 
392  int getCrossingIndex() const;
393 
394 
397 
405  virtual void planMovements(const SUMOTime t);
406 
415  virtual bool executeMovements(SUMOTime t, std::vector<MSLane*>& into);
416 
418  virtual bool integrateNewVehicle(SUMOTime t);
420 
421 
422 
424  virtual void detectCollisions(SUMOTime timestep, const std::string& stage);
425 
426 
429  virtual bool appropriate(const MSVehicle* veh);
430 
431 
433  const MSLinkCont& getLinkCont() const;
434 
435 
437  bool empty() const {
438  assert(myVehBuffer.size() == 0);
439  return myVehicles.empty();
440  }
441 
442  void setMaxSpeed(SUMOReal val) {
443  myMaxSpeed = val;
444  }
445 
446  void setLength(SUMOReal val) {
447  myLength = val;
448  }
449 
450 
454  MSEdge& getEdge() const {
455  return *myEdge;
456  }
457 
458 
462  const MSEdge* getInternalFollower() const;
463 
464 
467 
478  static bool dictionary(const std::string& id, MSLane* lane);
479 
480 
487  static MSLane* dictionary(const std::string& id);
488 
489 
491  static void clear();
492 
493 
497  static size_t dictSize() {
498  return myDict.size();
499  }
500 
501 
505  static void insertIDs(std::vector<std::string>& into);
506 
507 
512  template<class RTREE>
513  static void fill(RTREE& into);
515 
516 
517 
522  static MSLinkCont::const_iterator succLinkSec(const SUMOVehicle& veh,
523  unsigned int nRouteSuccs,
524  const MSLane& succLinkSource,
525  const std::vector<MSLane*>& conts);
526 
527 
530  bool isLinkEnd(MSLinkCont::const_iterator& i) const;
531 
534  bool isLinkEnd(MSLinkCont::iterator& i);
535 
537  virtual MSVehicle* getLastVehicle() const;
538  virtual const MSVehicle* getFirstVehicle() const;
539 
540 
541 
542 
543  /* @brief remove the vehicle from this lane
544  * @param[notify] whether moveReminders of the vehicle shall be triggered
545  */
546  virtual MSVehicle* removeVehicle(MSVehicle* remVehicle, MSMoveReminder::Notification notification, bool notify = true);
547 
550 
551 
552 
553  void leftByLaneChange(MSVehicle* v);
555 
556 
560  MSLane* getParallelLane(int offset) const;
561 
562 
563  inline void setPermissions(SVCPermissions permissions) {
564  myPermissions = permissions;
565  }
566 
567 
568  inline bool allowsVehicleClass(SUMOVehicleClass vclass) const {
569  return (myPermissions & vclass) == vclass;
570  }
571 
572  void addIncomingLane(MSLane* lane, MSLink* viaLink);
573 
574 
579  };
580 
581  const std::vector<IncomingLaneInfo>& getIncomingLanes() const {
582  return myIncomingLanes;
583  }
584 
585 
586  void addApproachingLane(MSLane* lane);
587  bool isApproachedFrom(MSEdge* const edge);
588  bool isApproachedFrom(MSEdge* const edge, MSLane* const lane);
589 
590 
591 
592  std::pair<MSVehicle* const, SUMOReal> getFollowerOnConsecutive(SUMOReal dist,
593  SUMOReal leaderSpeed, SUMOReal backOffset, SUMOReal predMaxDecel) const;
594 
595 
597  SUMOReal getMissingRearGap(SUMOReal dist, SUMOReal backOffset,
598  SUMOReal leaderSpeed, SUMOReal leaderMaxDecel) const;
599 
600 
623  std::pair<MSVehicle* const, SUMOReal> getLeaderOnConsecutive(SUMOReal dist, SUMOReal seen,
624  SUMOReal speed, const MSVehicle& veh, const std::vector<MSLane*>& bestLaneConts) const;
625 
626 
628 
631 
633  std::vector<const MSLane*> getOutgoingLanes() const;
634 
636 
637 
641  SUMOReal getMeanSpeed() const;
642 
646  SUMOReal getWaitingSeconds() const;
647 
648 
653 
654 
658  SUMOReal getNettoOccupancy() const;
659 
660 
665 
666 
670  SUMOReal getCO2Emissions() const;
671 
672 
676  SUMOReal getCOEmissions() const;
677 
678 
682  SUMOReal getPMxEmissions() const;
683 
684 
688  SUMOReal getNOxEmissions() const;
689 
690 
694  SUMOReal getHCEmissions() const;
695 
696 
701 
702 
708 
709 
712 
720  void saveState(OutputDevice& out);
721 
733  void loadState(std::vector<std::string>& vehIDs, MSVehicleControl& vc);
735 
736 
737 #ifndef NO_TRACI
738 
745  void visit(const TraCIServerAPI_Lane::StoringVisitor& cont) const {
746  cont.add(this);
747  }
748 #endif
749 
750 protected:
752  virtual void swapAfterLaneChange(SUMOTime t);
753 
764  virtual void incorporateVehicle(MSVehicle* veh, SUMOReal pos, SUMOReal speed,
765  const MSLane::VehCont::iterator& at,
767 
768 
769 protected:
772 
781 
784 
787 
790 
793 
797 
798 
800  std::vector<MSVehicle*> myVehBuffer;
801 
804 
805  std::vector<IncomingLaneInfo> myIncomingLanes;
807 
808 
811 
814 
817 
820 
821 
825 
826  std::map<MSEdge*, std::vector<MSLane*> > myApproachingLanes;
827 
828  // precomputed myShape.length / myLength
830 
832  typedef std::map< std::string, MSLane* > DictType;
833 
835  static DictType myDict;
836 
837 private:
839  std::vector< MSMoveReminder* > myMoveReminders;
840 
841 
847  public:
849  explicit vehicle_position_sorter() { }
850 
851 
857  int operator()(MSVehicle* v1, MSVehicle* v2) const;
858 
859  };
860 
865  public:
867  explicit by_connections_to_sorter(const MSEdge* const e);
868 
870  int operator()(const MSEdge* const e1, const MSEdge* const e2) const;
871 
872  private:
873  by_connections_to_sorter& operator=(const by_connections_to_sorter&); // just to avoid a compiler warning
874  private:
875  const MSEdge* const myEdge;
877  };
878 
882  class edge_finder {
883  public:
885  bool operator()(const IncomingLaneInfo& ili) const {
886  return &(ili.lane->getEdge()) == myEdge;
887  }
888  private:
889  edge_finder& operator=(const edge_finder&); // just to avoid a compiler warning
890  private:
891  const MSEdge* const myEdge;
892  };
893 
894 private:
896  MSLane(const MSLane&);
897 
899  MSLane& operator=(const MSLane&);
900 
901 
902 };
903 
904 
905 #endif
906 
907 /****************************************************************************/
908