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>
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 MSVehicleTransfer;
59 class MSVehicleControl;
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 MSXMLRawOut;
79 
80  friend class MSQueueExport;
81 
82 
84  typedef std::vector< MSVehicle* > VehCont;
85 
88  struct VehPosition : public std::binary_function < const MSVehicle*, SUMOReal, bool > {
90  bool operator()(const MSVehicle* cmp, SUMOReal pos) const;
91  };
92 
93 public:
106  MSLane(const std::string& id, SUMOReal maxSpeed, SUMOReal length, MSEdge* const edge,
107  unsigned int numericalID, const PositionVector& shape, SUMOReal width,
108  SVCPermissions permissions);
109 
110 
112  virtual ~MSLane();
113 
114 
115 
118 
126  void addLink(MSLink* link);
128 
129 
130 
133 
140  virtual void addMoveReminder(MSMoveReminder* rem);
141 
142 
146  inline const std::vector< MSMoveReminder* >& getMoveReminders() const {
147  return myMoveReminders;
148  }
150 
151 
152 
155 
171  bool insertVehicle(MSVehicle& v);
172 
173 
191  virtual bool isInsertionSuccess(MSVehicle* vehicle, SUMOReal speed, SUMOReal pos,
192  bool recheckNextLanes,
194 
195  bool pWagGenericInsertion(MSVehicle& veh, SUMOReal speed, SUMOReal maxPos, SUMOReal minPos);
196  bool pWagSimpleInsertion(MSVehicle& veh, SUMOReal speed, SUMOReal maxPos, SUMOReal minPos);
197  bool maxSpeedGapInsertion(MSVehicle& veh, SUMOReal mspeed);
198 
206  bool freeInsertion(MSVehicle& veh, SUMOReal speed,
208 
209 
217  void forceVehicleInsertion(MSVehicle* veh, SUMOReal pos);
219 
220 
221 
224 
236  SUMOReal setPartialOccupation(MSVehicle* v, SUMOReal leftVehicleLength);
237 
238 
243 
244 
249  return myInlappingVehicle;
250  }
251 
252 
257  return myInlappingVehicleEnd;
258  }
259 
260 
269  std::pair<MSVehicle*, SUMOReal> getLastVehicleInformation() const;
271 
272 
273 
276 
280  unsigned int getVehicleNumber() const {
281  return (unsigned int) myVehicles.size();
282  }
283 
284 
291  virtual const VehCont& getVehiclesSecure() const {
292  return myVehicles;
293  }
294 
295 
298  virtual void releaseVehicles() const { }
300 
301 
302 
305 
306 
310  inline size_t getNumericalID() const {
311  return myNumericalID;
312  }
313 
314 
318  inline const PositionVector& getShape() const {
319  return myShape;
320  }
321 
322  /* @brief fit the given lane position to a visibly suitable geometry position
323  * (lane length might differ from geometry length) */
325  return lanePos * myLengthGeometryFactor;
326  }
327 
328  /* @brief fit the given lane position to a visibly suitable geometry position
329  * and return the coordinates */
330  inline const Position geometryPositionAtOffset(SUMOReal offset) const {
332  }
333 
334  /* @brief fit the given geomtry position to a valid lane position
335  * (lane length might differ from geometry length) */
337  return geometryPos / myLengthGeometryFactor;
338  }
339 
344  inline SUMOReal getVehicleMaxSpeed(const SUMOVehicle* const veh) const {
345  return myMaxSpeed * veh->getChosenSpeedFactor();
346  }
347 
348 
352  inline SUMOReal getSpeedLimit() const {
353  return myMaxSpeed;
354  }
355 
356 
360  inline SUMOReal getLength() const {
361  return myLength;
362  }
363 
364 
369  return myPermissions;
370  }
371 
372 
376  SUMOReal getWidth() const {
377  return myWidth;
378  }
380 
381 
382 
385 
393  virtual void planMovements(const SUMOTime t);
394 
403  virtual bool executeMovements(SUMOTime t, std::vector<MSLane*>& into);
404 
406  virtual bool integrateNewVehicle(SUMOTime t);
408 
409 
410 
412  virtual void detectCollisions(SUMOTime timestep, int stage);
413 
414 
417  virtual bool appropriate(const MSVehicle* veh);
418 
419 
421  const MSLinkCont& getLinkCont() const;
422 
423 
425  bool empty() const {
426  assert(myVehBuffer.size() == 0);
427  return myVehicles.empty();
428  }
429 
430  void setMaxSpeed(SUMOReal val) {
431  myMaxSpeed = val;
432  }
433 
434  void setLength(SUMOReal val) {
435  myLength = val;
436  }
437 
438 
442  MSEdge& getEdge() const {
443  return *myEdge;
444  }
445 
449  static bool dictionary(std::string id, MSLane* lane);
450 
453  static MSLane* dictionary(std::string id);
454 
456  static void clear();
457 
458  static size_t dictSize() {
459  return myDict.size();
460  }
461 
462  static void insertIDs(std::vector<std::string>& into);
463 
468  virtual MSLinkCont::const_iterator succLinkSec(const SUMOVehicle& veh,
469  unsigned int nRouteSuccs,
470  const MSLane& succLinkSource,
471  const std::vector<MSLane*>& conts) const;
472 
473 
476  bool isLinkEnd(MSLinkCont::const_iterator& i) const;
477 
480  bool isLinkEnd(MSLinkCont::iterator& i);
481 
483  virtual MSVehicle* getLastVehicle() const;
484  virtual const MSVehicle* getFirstVehicle() const;
485 
486 
487 
488 
490  virtual MSVehicle* removeVehicle(MSVehicle* remVehicle, MSMoveReminder::Notification notification);
491 
494 
495 
496 
497  void leftByLaneChange(MSVehicle* v);
499 
500 
504  MSLane* getParallelLane(int offset) const;
505 
506 
507  inline void setPermissions(SVCPermissions permissions) {
508  myPermissions = permissions;
509  }
510 
511 
512  inline bool allowsVehicleClass(SUMOVehicleClass vclass) const {
513  return (myPermissions & vclass) == vclass;
514  }
515 
516  void addIncomingLane(MSLane* lane, MSLink* viaLink);
517 
518 
523  };
524 
525  const std::vector<IncomingLaneInfo>& getIncomingLanes() const {
526  return myIncomingLanes;
527  }
528 
529 
530  void addApproachingLane(MSLane* lane);
531  bool isApproachedFrom(MSEdge* const edge);
532  bool isApproachedFrom(MSEdge* const edge, MSLane* const lane);
533 
534 
535 
536  std::pair<MSVehicle* const, SUMOReal> getFollowerOnConsecutive(SUMOReal dist, SUMOReal seen,
537  SUMOReal leaderSpeed, SUMOReal backOffset, SUMOReal predMaxDecel) const;
538 
539 
541  SUMOReal getMissingRearGap(SUMOReal dist, SUMOReal backOffset,
542  SUMOReal leaderSpeed, SUMOReal leaderMaxDecel) const;
543 
544 
567  std::pair<MSVehicle* const, SUMOReal> getLeaderOnConsecutive(SUMOReal dist, SUMOReal seen,
568  SUMOReal speed, const MSVehicle& veh, const std::vector<MSLane*>& bestLaneConts) const;
569 
570 
572 
573 
575 
576 
580  SUMOReal getMeanSpeed() const;
581 
582 
586  SUMOReal getOccupancy() const;
587 
588 
592  SUMOReal getVehLenSum() const;
593 
594 
599 
600 
605 
606 
611 
612 
617 
618 
623 
624 
629 
630 
636 
637 
640 
648  void saveState(OutputDevice& out);
649 
661  void loadState(std::vector<std::string>& vehIDs, MSVehicleControl& vc);
663 
664 
665 
666 protected:
668  virtual void swapAfterLaneChange(SUMOTime t);
669 
680  virtual void incorporateVehicle(MSVehicle* veh, SUMOReal pos, SUMOReal speed,
681  const MSLane::VehCont::iterator& at,
683 
684 
685 protected:
688 
697 
700 
703 
706 
709 
713 
714 
716  std::vector<MSVehicle*> myVehBuffer;
717 
720 
721  std::vector<IncomingLaneInfo> myIncomingLanes;
723 
724 
727 
730 
733 
734 
738 
739  std::map<MSEdge*, std::vector<MSLane*> > myApproachingLanes;
740 
741  // precomputed myShape.length / myLength
743 
745  typedef std::map< std::string, MSLane* > DictType;
746 
748  static DictType myDict;
749 
750 private:
752  std::vector< MSMoveReminder* > myMoveReminders;
753 
754 
760  public:
762  explicit vehicle_position_sorter() { }
763 
764 
770  int operator()(MSVehicle* v1, MSVehicle* v2) const;
771 
772  };
773 
778  public:
780  explicit by_connections_to_sorter(const MSEdge* const e);
781 
783  int operator()(const MSEdge* const e1, const MSEdge* const e2) const;
784 
785  private:
786  by_connections_to_sorter& operator=(const by_connections_to_sorter&); // just to avoid a compiler warning
787  private:
788  const MSEdge* const myEdge;
790  };
791 
795  class edge_finder {
796  public:
798  bool operator()(const IncomingLaneInfo& ili) const {
799  return &(ili.lane->getEdge()) == myEdge;
800  }
801  private:
802  edge_finder& operator=(const edge_finder&); // just to avoid a compiler warning
803  private:
804  const MSEdge* const myEdge;
805  };
806 
807 private:
809  MSLane(const MSLane&);
810 
812  MSLane& operator=(const MSLane&);
813 
814 
815 };
816 
817 
818 #endif
819 
820 /****************************************************************************/
821