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-2012 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 geomety 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 geomety 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 
379  virtual bool moveCritical(SUMOTime t);
380 
383  virtual bool setCritical(SUMOTime t, std::vector<MSLane*>& into);
384 
386  virtual bool integrateNewVehicle(SUMOTime t);
388 
389 
390 
392  virtual void detectCollisions(SUMOTime timestep);
393 
394 
397  virtual bool appropriate(const MSVehicle* veh);
398 
399 
401  const MSLinkCont& getLinkCont() const;
402 
403 
405  bool empty() const {
406  assert(myVehBuffer.size() == 0);
407  return myVehicles.empty();
408  }
409 
410  void setMaxSpeed(SUMOReal val) {
411  myMaxSpeed = val;
412  }
413 
414  void setLength(SUMOReal val) {
415  myLength = val;
416  }
417 
418 
422  MSEdge& getEdge() const {
423  return *myEdge;
424  }
425 
429  static bool dictionary(std::string id, MSLane* lane);
430 
433  static MSLane* dictionary(std::string id);
434 
436  static void clear();
437 
438  static size_t dictSize() {
439  return myDict.size();
440  }
441 
442  static void insertIDs(std::vector<std::string>& into);
443 
445  typedef std::deque< MSVehicle* > VehCont;
446 
451  virtual MSLinkCont::const_iterator succLinkSec(const SUMOVehicle& veh,
452  unsigned int nRouteSuccs,
453  const MSLane& succLinkSource,
454  const std::vector<MSLane*>& conts) const;
455 
456 
459  bool isLinkEnd(MSLinkCont::const_iterator& i) const;
460 
463  bool isLinkEnd(MSLinkCont::iterator& i);
464 
466  virtual MSVehicle* getLastVehicle() const;
467  virtual const MSVehicle* getFirstVehicle() const;
468 
469 
470 
471 
472  // valid for gui-version only
473  virtual GUILaneWrapper* buildLaneWrapper(unsigned int index);
474 
475  virtual MSVehicle* removeVehicle(MSVehicle* remVehicle);
476 
479 
480 
481 
482  void leftByLaneChange(MSVehicle* v);
484 
485 
486  MSLane* getLeftLane() const;
487  MSLane* getRightLane() const;
488 
489  inline void setPermissions(SVCPermissions permissions) {
490  myPermissions = permissions;
491  }
492 
493 
494  inline bool allowsVehicleClass(SUMOVehicleClass vclass) const {
495  return (myPermissions & vclass) == vclass;
496  }
497 
498  void addIncomingLane(MSLane* lane, MSLink* viaLink);
499 
500 
505  };
506 
507  const std::vector<IncomingLaneInfo>& getIncomingLanes() const {
508  return myIncomingLanes;
509  }
510 
511 
512  void addApproachingLane(MSLane* lane);
513  bool isApproachedFrom(MSEdge* const edge);
514  bool isApproachedFrom(MSEdge* const edge, MSLane* const lane);
515 
516 
517 
518  std::pair<MSVehicle* const, SUMOReal> getFollowerOnConsecutive(SUMOReal dist, SUMOReal seen,
519  SUMOReal leaderSpeed, SUMOReal backOffset, SUMOReal predMaxDecel) const;
520 
521 
523  SUMOReal getMissingRearGap(SUMOReal dist, SUMOReal backOffset,
524  SUMOReal leaderSpeed, SUMOReal leaderMaxDecel) const;
525 
526 
549  std::pair<MSVehicle* const, SUMOReal> getLeaderOnConsecutive(SUMOReal dist, SUMOReal seen,
550  SUMOReal speed, const MSVehicle& veh, const std::vector<MSLane*>& bestLaneConts) const;
551 
552 
554 
555 
557 
558 
562  SUMOReal getMeanSpeed() const;
563 
564 
568  SUMOReal getOccupancy() const;
569 
570 
574  SUMOReal getVehLenSum() const;
575 
576 
581 
582 
587 
588 
593 
594 
599 
600 
605 
606 
611 
612 
618 
619 
620 protected:
622  virtual void swapAfterLaneChange(SUMOTime t);
623 
634  virtual void incorporateVehicle(MSVehicle* veh, SUMOReal pos, SUMOReal speed,
635  const MSLane::VehCont::iterator& at,
637 
638 
639 protected:
642 
651 
654 
657 
660 
663 
667 
668 
673  std::vector<MSVehicle*> myVehBuffer;
674 
677 
678  std::vector<IncomingLaneInfo> myIncomingLanes;
680 
681 
684 
687 
690 
691 
694 
698 
699  std::map<MSEdge*, std::vector<MSLane*> > myApproachingLanes;
700 
701  // precomputed myShape.length / myLength
703 
705  typedef std::map< std::string, MSLane* > DictType;
706 
708  static DictType myDict;
709 
710 private:
712  std::vector< MSMoveReminder* > myMoveReminders;
713 
714 
720  public:
722  explicit vehicle_position_sorter() { }
723 
724 
730  int operator()(MSVehicle* v1, MSVehicle* v2) const;
731 
732  };
733 
738  public:
740  explicit by_connections_to_sorter(const MSEdge* const e);
741 
743  int operator()(const MSEdge* const e1, const MSEdge* const e2) const;
744 
745  private:
746  by_connections_to_sorter& operator=(const by_connections_to_sorter&); // just to avoid a compiler warning
747  private:
748  const MSEdge* const myEdge;
750  };
751 
755  class edge_finder {
756  public:
758  bool operator()(const IncomingLaneInfo& ili) const {
759  return &(ili.lane->getEdge()) == myEdge;
760  }
761  private:
762  edge_finder& operator=(const edge_finder&); // just to avoid a compiler warning
763  private:
764  const MSEdge* const myEdge;
765  };
766 
767 private:
769  MSLane(const MSLane&);
770 
772  MSLane& operator=(const MSLane&);
773 
774 
775 };
776 
777 
778 #endif
779 
780 /****************************************************************************/
781