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-2013 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 
327  /* @brief fit the given lane position to a visibly suitable geometry position
328  * (lane length might differ from geometry length) */
330  return lanePos * myLengthGeometryFactor;
331  }
332 
333  /* @brief fit the given lane position to a visibly suitable geometry position
334  * and return the coordinates */
335  inline const Position geometryPositionAtOffset(SUMOReal offset) const {
337  }
338 
339  /* @brief fit the given geomtry position to a valid lane position
340  * (lane length might differ from geometry length) */
342  return geometryPos / myLengthGeometryFactor;
343  }
344 
349  inline SUMOReal getVehicleMaxSpeed(const SUMOVehicle* const veh) const {
350  return myMaxSpeed * veh->getChosenSpeedFactor();
351  }
352 
353 
357  inline SUMOReal getSpeedLimit() const {
358  return myMaxSpeed;
359  }
360 
361 
365  inline SUMOReal getLength() const {
366  return myLength;
367  }
368 
369 
374  return myPermissions;
375  }
376 
377 
381  SUMOReal getWidth() const {
382  return myWidth;
383  }
385 
386 
387 
390 
398  virtual void planMovements(const SUMOTime t);
399 
408  virtual bool executeMovements(SUMOTime t, std::vector<MSLane*>& into);
409 
411  virtual bool integrateNewVehicle(SUMOTime t);
413 
414 
415 
417  virtual void detectCollisions(SUMOTime timestep, int stage);
418 
419 
422  virtual bool appropriate(const MSVehicle* veh);
423 
424 
426  const MSLinkCont& getLinkCont() const;
427 
428 
430  bool empty() const {
431  assert(myVehBuffer.size() == 0);
432  return myVehicles.empty();
433  }
434 
435  void setMaxSpeed(SUMOReal val) {
436  myMaxSpeed = val;
437  }
438 
439  void setLength(SUMOReal val) {
440  myLength = val;
441  }
442 
443 
447  MSEdge& getEdge() const {
448  return *myEdge;
449  }
450 
451 
452 
455 
466  static bool dictionary(const std::string& id, MSLane* lane);
467 
468 
475  static MSLane* dictionary(const std::string& id);
476 
477 
479  static void clear();
480 
481 
485  static size_t dictSize() {
486  return myDict.size();
487  }
488 
489 
493  static void insertIDs(std::vector<std::string>& into);
494 
495 
500  template<class RTREE>
501  static void fill(RTREE& into);
503 
504 
505 
510  virtual MSLinkCont::const_iterator succLinkSec(const SUMOVehicle& veh,
511  unsigned int nRouteSuccs,
512  const MSLane& succLinkSource,
513  const std::vector<MSLane*>& conts) const;
514 
515 
518  bool isLinkEnd(MSLinkCont::const_iterator& i) const;
519 
522  bool isLinkEnd(MSLinkCont::iterator& i);
523 
525  virtual MSVehicle* getLastVehicle() const;
526  virtual const MSVehicle* getFirstVehicle() const;
527 
528 
529 
530 
532  virtual MSVehicle* removeVehicle(MSVehicle* remVehicle, MSMoveReminder::Notification notification);
533 
536 
537 
538 
539  void leftByLaneChange(MSVehicle* v);
541 
542 
546  MSLane* getParallelLane(int offset) const;
547 
548 
549  inline void setPermissions(SVCPermissions permissions) {
550  myPermissions = permissions;
551  }
552 
553 
554  inline bool allowsVehicleClass(SUMOVehicleClass vclass) const {
555  return (myPermissions & vclass) == vclass;
556  }
557 
558  void addIncomingLane(MSLane* lane, MSLink* viaLink);
559 
560 
565  };
566 
567  const std::vector<IncomingLaneInfo>& getIncomingLanes() const {
568  return myIncomingLanes;
569  }
570 
571 
572  void addApproachingLane(MSLane* lane);
573  bool isApproachedFrom(MSEdge* const edge);
574  bool isApproachedFrom(MSEdge* const edge, MSLane* const lane);
575 
576 
577 
578  std::pair<MSVehicle* const, SUMOReal> getFollowerOnConsecutive(SUMOReal dist, SUMOReal seen,
579  SUMOReal leaderSpeed, SUMOReal backOffset, SUMOReal predMaxDecel) const;
580 
581 
583  SUMOReal getMissingRearGap(SUMOReal dist, SUMOReal backOffset,
584  SUMOReal leaderSpeed, SUMOReal leaderMaxDecel) const;
585 
586 
609  std::pair<MSVehicle* const, SUMOReal> getLeaderOnConsecutive(SUMOReal dist, SUMOReal seen,
610  SUMOReal speed, const MSVehicle& veh, const std::vector<MSLane*>& bestLaneConts) const;
611 
612 
614 
615 
617 
618 
622  SUMOReal getMeanSpeed() const;
623 
627  SUMOReal getWaitingSeconds() const;
628 
629 
634 
635 
639  SUMOReal getNettoOccupancy() const;
640 
641 
646 
647 
652 
653 
658 
659 
664 
665 
670 
671 
676 
677 
682 
683 
689 
690 
693 
701  void saveState(OutputDevice& out);
702 
714  void loadState(std::vector<std::string>& vehIDs, MSVehicleControl& vc);
716 
717 
718 #ifndef NO_TRACI
719 
726  void visit(const TraCIServerAPI_Lane::StoringVisitor& cont) const {
727  cont.add(this);
728  }
729 #endif
730 
731 protected:
733  virtual void swapAfterLaneChange(SUMOTime t);
734 
745  virtual void incorporateVehicle(MSVehicle* veh, SUMOReal pos, SUMOReal speed,
746  const MSLane::VehCont::iterator& at,
748 
749 
750 protected:
753 
762 
765 
768 
771 
774 
778 
779 
781  std::vector<MSVehicle*> myVehBuffer;
782 
785 
786  std::vector<IncomingLaneInfo> myIncomingLanes;
788 
789 
792 
795 
798 
801 
802 
806 
807  std::map<MSEdge*, std::vector<MSLane*> > myApproachingLanes;
808 
809  // precomputed myShape.length / myLength
811 
813  typedef std::map< std::string, MSLane* > DictType;
814 
816  static DictType myDict;
817 
818 private:
820  std::vector< MSMoveReminder* > myMoveReminders;
821 
822 
828  public:
830  explicit vehicle_position_sorter() { }
831 
832 
838  int operator()(MSVehicle* v1, MSVehicle* v2) const;
839 
840  };
841 
846  public:
848  explicit by_connections_to_sorter(const MSEdge* const e);
849 
851  int operator()(const MSEdge* const e1, const MSEdge* const e2) const;
852 
853  private:
854  by_connections_to_sorter& operator=(const by_connections_to_sorter&); // just to avoid a compiler warning
855  private:
856  const MSEdge* const myEdge;
858  };
859 
863  class edge_finder {
864  public:
866  bool operator()(const IncomingLaneInfo& ili) const {
867  return &(ili.lane->getEdge()) == myEdge;
868  }
869  private:
870  edge_finder& operator=(const edge_finder&); // just to avoid a compiler warning
871  private:
872  const MSEdge* const myEdge;
873  };
874 
875 private:
877  MSLane(const MSLane&);
878 
880  MSLane& operator=(const MSLane&);
881 
882 
883 };
884 
885 
886 #endif
887 
888 /****************************************************************************/
889