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.sourceforge.net/
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>
47 #include "MSLinkCont.h"
48 #include "MSMoveReminder.h"
49 
50 
51 // ===========================================================================
52 // class declarations
53 // ===========================================================================
54 class MSEdge;
55 class MSVehicle;
56 class MSLaneChanger;
57 class MSLink;
58 class GUILaneWrapper;
59 class MSVehicleTransfer;
60 class OutputDevice;
61 
62 
63 // ===========================================================================
64 // class definitions
65 // ===========================================================================
73 class MSLane : public Named, public Parameterised {
74 public:
76  friend class MSLaneChanger;
77 
78  friend class GUILaneWrapper;
79 
80  friend class MSXMLRawOut;
81 
82  friend class MSQueueExport;
83 
84 
87  struct VehPosition : public std::binary_function < const MSVehicle*, SUMOReal, bool > {
89  bool operator()(const MSVehicle* cmp, SUMOReal pos) const;
90  };
91 
92 public:
105  MSLane(const std::string& id, SUMOReal maxSpeed, SUMOReal length, MSEdge* const edge,
106  unsigned int numericalID, const PositionVector& shape, SUMOReal width,
107  SVCPermissions permissions);
108 
109 
111  virtual ~MSLane();
112 
113 
114 
117 
125  void addLink(MSLink* link);
127 
128 
129 
132 
139  virtual void addMoveReminder(MSMoveReminder* rem);
140 
141 
145  inline const std::vector< MSMoveReminder* >& getMoveReminders() const {
146  return myMoveReminders;
147  }
149 
150 
151 
154 
170  bool insertVehicle(MSVehicle& v);
171 
172 
190  virtual bool isInsertionSuccess(MSVehicle* vehicle, SUMOReal speed, SUMOReal pos,
191  bool recheckNextLanes,
193 
194  bool pWagGenericInsertion(MSVehicle& veh, SUMOReal speed, SUMOReal maxPos, SUMOReal minPos);
195  bool pWagSimpleInsertion(MSVehicle& veh, SUMOReal speed, SUMOReal maxPos, SUMOReal minPos);
196  bool maxSpeedGapInsertion(MSVehicle& veh, SUMOReal mspeed);
197 
205  bool freeInsertion(MSVehicle& veh, SUMOReal speed,
207 
208 
216  void forceVehicleInsertion(MSVehicle* veh, SUMOReal pos);
218 
219 
220 
223 
235  SUMOReal setPartialOccupation(MSVehicle* v, SUMOReal leftVehicleLength);
236 
237 
242 
243 
248  return myInlappingVehicle;
249  }
250 
251 
256  return myInlappingVehicleEnd;
257  }
258 
259 
268  std::pair<MSVehicle*, SUMOReal> getLastVehicleInformation() const;
270 
271 
272 
275 
279  unsigned int getVehicleNumber() const {
280  return (unsigned int) myVehicles.size();
281  }
282 
283 
290  virtual const std::deque< MSVehicle* >& getVehiclesSecure() const {
291  return myVehicles;
292  }
293 
294 
297  virtual void releaseVehicles() const { }
299 
300 
301 
304 
305 
309  size_t getNumericalID() const {
310  return myNumericalID;
311  }
312 
313 
317  const PositionVector& getShape() const {
318  return myShape;
319  }
320 
321  /* @brief fit the given lane position to a visibly suitable geometry position
322  * (lane length might differ from geometry length */
324  return lanePos * myLengthGeometryFactor;
325  }
326 
327  /* @brief fit the given geomtry position to a valid lane position
328  * (lane length might differ from geometry length */
330  return geometryPos / myLengthGeometryFactor;
331  }
332 
337  SUMOReal getVehicleMaxSpeed(const SUMOVehicle* const veh) const {
338  return myMaxSpeed * veh->getChosenSpeedFactor();
339  }
340 
341 
346  return myMaxSpeed;
347  }
348 
349 
353  SUMOReal getLength() const {
354  return myLength;
355  }
356 
357 
362  return myPermissions;
363  }
364 
365 
369  SUMOReal getWidth() const {
370  return myWidth;
371  }
373 
374 
375 
378 
386  virtual bool planMovements(SUMOTime t);
387 
396  virtual bool executeMovements(SUMOTime t, std::vector<MSLane*>& into);
397 
399  virtual bool integrateNewVehicle(SUMOTime t);
401 
402 
403 
405  virtual void detectCollisions(SUMOTime timestep, int stage);
406 
407 
410  virtual bool appropriate(const MSVehicle* veh);
411 
412 
414  const MSLinkCont& getLinkCont() const;
415 
416 
418  bool empty() const {
419  assert(myVehBuffer.size() == 0);
420  return myVehicles.empty();
421  }
422 
423  void setMaxSpeed(SUMOReal val) {
424  myMaxSpeed = val;
425  }
426 
427  void setLength(SUMOReal val) {
428  myLength = val;
429  }
430 
431 
435  MSEdge& getEdge() const {
436  return *myEdge;
437  }
438 
442  static bool dictionary(std::string id, MSLane* lane);
443 
446  static MSLane* dictionary(std::string id);
447 
449  static void clear();
450 
451  static size_t dictSize() {
452  return myDict.size();
453  }
454 
455  static void insertIDs(std::vector<std::string>& into);
456 
458  typedef std::deque< MSVehicle* > VehCont;
459 
464  virtual MSLinkCont::const_iterator succLinkSec(const SUMOVehicle& veh,
465  unsigned int nRouteSuccs,
466  const MSLane& succLinkSource,
467  const std::vector<MSLane*>& conts) const;
468 
469 
472  bool isLinkEnd(MSLinkCont::const_iterator& i) const;
473 
476  bool isLinkEnd(MSLinkCont::iterator& i);
477 
479  virtual MSVehicle* getLastVehicle() const;
480  virtual const MSVehicle* getFirstVehicle() const;
481 
482 
483 
484 
485  // valid for gui-version only
486  virtual GUILaneWrapper* buildLaneWrapper(unsigned int index);
487 
488  virtual MSVehicle* removeVehicle(MSVehicle* remVehicle);
489 
492 
493 
494 
495  void leftByLaneChange(MSVehicle* v);
497 
498 
499  MSLane* getLeftLane() const;
500  MSLane* getRightLane() const;
501 
502  inline void setPermissions(SVCPermissions permissions) {
503  myPermissions = permissions;
504  }
505 
506 
507  inline bool allowsVehicleClass(SUMOVehicleClass vclass) const {
508  return (myPermissions & vclass) == vclass;
509  }
510 
511  void addIncomingLane(MSLane* lane, MSLink* viaLink);
512 
513 
518  };
519 
520  const std::vector<IncomingLaneInfo>& getIncomingLanes() const {
521  return myIncomingLanes;
522  }
523 
524 
525  void addApproachingLane(MSLane* lane);
526  bool isApproachedFrom(MSEdge* const edge);
527  bool isApproachedFrom(MSEdge* const edge, MSLane* const lane);
528 
529 
530 
531  std::pair<MSVehicle* const, SUMOReal> getFollowerOnConsecutive(SUMOReal dist, SUMOReal seen,
532  SUMOReal leaderSpeed, SUMOReal backOffset, SUMOReal predMaxDecel) const;
533 
534 
536  SUMOReal getMissingRearGap(SUMOReal dist, SUMOReal backOffset,
537  SUMOReal leaderSpeed, SUMOReal leaderMaxDecel) const;
538 
539 
562  std::pair<MSVehicle* const, SUMOReal> getLeaderOnConsecutive(SUMOReal dist, SUMOReal seen,
563  SUMOReal speed, const MSVehicle& veh, const std::vector<MSLane*>& bestLaneConts) const;
564 
565 
567 
568 
570 
571 
575  SUMOReal getMeanSpeed() const;
576 
577 
581  SUMOReal getOccupancy() const;
582 
583 
587  SUMOReal getVehLenSum() const;
588 
589 
594 
595 
600 
601 
606 
607 
612 
613 
618 
619 
624 
625 
631 
632 
633 protected:
635  virtual void swapAfterLaneChange(SUMOTime t);
636 
647  virtual void incorporateVehicle(MSVehicle* veh, SUMOReal pos, SUMOReal speed,
648  const MSLane::VehCont::iterator& at,
650 
651 
652 protected:
655 
664 
667 
670 
673 
676 
680 
681 
683  std::vector<MSVehicle*> myVehBuffer;
684 
687 
688  std::vector<IncomingLaneInfo> myIncomingLanes;
690 
691 
694 
697 
700 
701 
704 
708 
709  std::map<MSEdge*, std::vector<MSLane*> > myApproachingLanes;
710 
711  // precomputed myShape.length / myLength
713 
715  typedef std::map< std::string, MSLane* > DictType;
716 
718  static DictType myDict;
719 
720 private:
722  std::vector< MSMoveReminder* > myMoveReminders;
723 
724 
730  public:
732  explicit vehicle_position_sorter() { }
733 
734 
740  int operator()(MSVehicle* v1, MSVehicle* v2) const;
741 
742  };
743 
748  public:
750  explicit by_connections_to_sorter(const MSEdge* const e);
751 
753  int operator()(const MSEdge* const e1, const MSEdge* const e2) const;
754 
755  private:
756  by_connections_to_sorter& operator=(const by_connections_to_sorter&); // just to avoid a compiler warning
757  private:
758  const MSEdge* const myEdge;
760  };
761 
765  class edge_finder {
766  public:
768  bool operator()(const IncomingLaneInfo& ili) const {
769  return &(ili.lane->getEdge()) == myEdge;
770  }
771  private:
772  edge_finder& operator=(const edge_finder&); // just to avoid a compiler warning
773  private:
774  const MSEdge* const myEdge;
775  };
776 
777 private:
779  MSLane(const MSLane&);
780 
782  MSLane& operator=(const MSLane&);
783 
784 
785 };
786 
787 
788 #endif
789 
790 /****************************************************************************/
791