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 /****************************************************************************/
12 // Representation of a lane in the micro simulation
13 /****************************************************************************/
14 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
15 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
16 /****************************************************************************/
17 //
18 // This file is part of SUMO.
19 // SUMO is free software: you can redistribute it and/or modify
20 // it under the terms of the GNU General Public License as published by
21 // the Free Software Foundation, either version 3 of the License, or
22 // (at your option) any later version.
23 //
24 /****************************************************************************/
25 #ifndef MSLane_h
26 #define MSLane_h
27 
28 
29 // ===========================================================================
30 // included modules
31 // ===========================================================================
32 #ifdef _MSC_VER
33 #include <windows_config.h>
34 #else
35 #include <config.h>
36 #endif
37 
38 #include <vector>
39 #include <deque>
40 #include <cassert>
41 #include <utils/common/Named.h>
44 #include "MSLinkCont.h"
45 #include "MSMoveReminder.h"
46 
47 
48 // ===========================================================================
49 // class declarations
50 // ===========================================================================
51 class MSEdge;
52 class MSVehicle;
53 class MSLaneChanger;
54 class MSLink;
55 class GUILaneWrapper;
56 class MSVehicleTransfer;
57 class OutputDevice;
58 
59 
60 // ===========================================================================
61 // class definitions
62 // ===========================================================================
70 class MSLane : public Named {
71 public:
73  friend class MSLaneChanger;
74 
75  friend class GUILaneWrapper;
76 
77  friend class MSXMLRawOut;
78 
81  struct VehPosition : public std::binary_function < const MSVehicle*, SUMOReal, bool > {
83  bool operator()(const MSVehicle* cmp, SUMOReal pos) const;
84  };
85 
86 public:
99  MSLane(const std::string& id, SUMOReal maxSpeed, SUMOReal length, MSEdge* const edge,
100  unsigned int numericalID, const PositionVector& shape, SUMOReal width,
101  SVCPermissions permissions);
102 
103 
105  virtual ~MSLane() ;
106 
107 
108 
111 
120  void initialize(MSLinkCont* succs);
121 
129  void addLink(MSLink* link);
131 
132 
133 
136 
143  virtual void addMoveReminder(MSMoveReminder* rem) ;
144 
145 
149  inline const std::vector< MSMoveReminder* > &getMoveReminders() const {
150  return myMoveReminders;
151  }
153 
154 
155 
158 
174  bool insertVehicle(MSVehicle& v) ;
175 
176 
194  virtual bool isInsertionSuccess(MSVehicle* vehicle, SUMOReal speed, SUMOReal pos,
195  bool recheckNextLanes,
197 
198  bool pWagGenericInsertion(MSVehicle& veh, SUMOReal speed, SUMOReal maxPos, SUMOReal minPos) ;
199  bool pWagSimpleInsertion(MSVehicle& veh, SUMOReal speed, SUMOReal maxPos, SUMOReal minPos) ;
200  bool maxSpeedGapInsertion(MSVehicle& veh, SUMOReal mspeed) ;
201 
209  bool freeInsertion(MSVehicle& veh, SUMOReal speed,
211 
212 
220  void forceVehicleInsertion(MSVehicle* veh, SUMOReal pos) ;
222 
223 
224 
227 
239  SUMOReal setPartialOccupation(MSVehicle* v, SUMOReal leftVehicleLength) ;
240 
241 
246 
247 
252  return myInlappingVehicle;
253  }
254 
255 
260  return myInlappingVehicleEnd;
261  }
262 
263 
272  std::pair<MSVehicle*, SUMOReal> getLastVehicleInformation() const ;
274 
275 
276 
279 
283  unsigned int getVehicleNumber() const {
284  return (unsigned int) myVehicles.size();
285  }
286 
287 
294  virtual const std::deque< MSVehicle* > &getVehiclesSecure() const {
295  return myVehicles;
296  }
297 
298 
301  virtual void releaseVehicles() const { }
303 
304 
305 
308 
309 
313  size_t getNumericalID() const {
314  return myNumericalID;
315  }
316 
317 
321  const PositionVector& getShape() const {
322  return myShape;
323  }
324 
325 
330  return myMaxSpeed;
331  }
332 
333 
337  SUMOReal getLength() const {
338  return myLength;
339  }
340 
341 
346  return myPermissions;
347  }
348 
349 
353  SUMOReal getWidth() const {
354  return myWidth;
355  }
357 
358 
359 
362 
363  virtual bool moveCritical(SUMOTime t);
364 
367  virtual bool setCritical(SUMOTime t, std::vector<MSLane*> &into);
368 
370  virtual bool integrateNewVehicle(SUMOTime t);
372 
373 
374 
376  virtual void detectCollisions(SUMOTime timestep);
377 
378 
381  virtual bool appropriate(const MSVehicle* veh);
382 
383 
385  const MSLinkCont& getLinkCont() const;
386 
387 
389  bool empty() const {
390  assert(myVehBuffer.size() == 0);
391  return myVehicles.empty();
392  }
393 
394  void setMaxSpeed(SUMOReal val) {
395  myMaxSpeed = val;
396  }
397 
398  void setLength(SUMOReal val) {
399  myLength = val;
400  }
401 
402 
406  MSEdge& getEdge() const {
407  return *myEdge;
408  }
409 
413  static bool dictionary(std::string id, MSLane* lane);
414 
417  static MSLane* dictionary(std::string id);
418 
420  static void clear();
421 
422  static size_t dictSize() {
423  return myDict.size();
424  }
425 
426  static void insertIDs(std::vector<std::string> &into) ;
427 
429  typedef std::deque< MSVehicle* > VehCont;
430 
435  virtual MSLinkCont::const_iterator succLinkSec(const SUMOVehicle& veh,
436  unsigned int nRouteSuccs,
437  const MSLane& succLinkSource,
438  const std::vector<MSLane*> &conts) const;
439 
440 
443  bool isLinkEnd(MSLinkCont::const_iterator& i) const;
444 
447  bool isLinkEnd(MSLinkCont::iterator& i);
448 
450  virtual MSVehicle* getLastVehicle() const;
451  virtual const MSVehicle* getFirstVehicle() const;
452 
453 
454 
455 
456  // valid for gui-version only
457  virtual GUILaneWrapper* buildLaneWrapper(unsigned int index);
458 
459  virtual MSVehicle* removeVehicle(MSVehicle* remVehicle);
460 
463 
464 
465 
466  void leftByLaneChange(MSVehicle* v);
468 
469 
470  MSLane* getLeftLane() const;
471  MSLane* getRightLane() const;
472 
473  inline void setPermissions(SVCPermissions permissions) {
474  myPermissions = permissions;
475  }
476 
477 
478  inline bool allowsVehicleClass(SUMOVehicleClass vclass) const {
479  return (myPermissions & vclass) == vclass;
480  }
481 
482  void addIncomingLane(MSLane* lane, MSLink* viaLink);
483 
484 
489  };
490 
491  const std::vector<IncomingLaneInfo> &getIncomingLanes() const {
492  return myIncomingLanes;
493  }
494 
495 
496  void addApproachingLane(MSLane* lane);
497  bool isApproachedFrom(MSEdge* const edge);
498  bool isApproachedFrom(MSEdge* const edge, MSLane* const lane);
499 
500 
501 
502  std::pair<MSVehicle* const, SUMOReal> getFollowerOnConsecutive(SUMOReal dist, SUMOReal seen,
503  SUMOReal leaderSpeed, SUMOReal backOffset, SUMOReal predMaxDecel) const;
504 
505 
528  std::pair<MSVehicle* const, SUMOReal> getLeaderOnConsecutive(SUMOReal dist, SUMOReal seen,
529  SUMOReal speed, const MSVehicle& veh, const std::vector<MSLane*> &bestLaneConts) const ;
530 
531 
533 
534 
536 
537 
541  SUMOReal getMeanSpeed() const ;
542 
543 
547  SUMOReal getOccupancy() const ;
548 
549 
553  SUMOReal getVehLenSum() const ;
554 
555 
560 
561 
566 
567 
572 
573 
578 
579 
584 
585 
590 
591 
597 
598 
599 protected:
601  virtual void swapAfterLaneChange(SUMOTime t);
602 
613  virtual void incorporateVehicle(MSVehicle* veh, SUMOReal pos, SUMOReal speed,
614  const MSLane::VehCont::iterator& at,
616 
617 
618 protected:
621 
630 
633 
636 
639 
642 
646 
647 
652  std::vector<MSVehicle*> myVehBuffer;
653 
656 
657  std::vector<IncomingLaneInfo> myIncomingLanes;
659 
660 
663 
666 
669 
670 
673 
677 
678  std::map<MSEdge*, std::vector<MSLane*> > myApproachingLanes;
679 
680 
681 
683  typedef std::map< std::string, MSLane* > DictType;
684 
686  static DictType myDict;
687 
688 private:
690  std::vector< MSMoveReminder* > myMoveReminders;
691 
692 
698  public:
700  explicit vehicle_position_sorter() { }
701 
702 
708  int operator()(MSVehicle* v1, MSVehicle* v2) const;
709 
710  };
711 
716  public:
718  explicit by_connections_to_sorter(const MSEdge* const e);
719 
721  int operator()(const MSEdge* const e1, const MSEdge* const e2) const;
722 
723  private:
724  by_connections_to_sorter& operator=(const by_connections_to_sorter&); // just to avoid a compiler warning
725  private:
726  const MSEdge* const myEdge;
728  };
729 
733  class edge_finder {
734  public:
736  bool operator()(const IncomingLaneInfo& ili) const {
737  return &(ili.lane->getEdge()) == myEdge;
738  }
739  private:
740  edge_finder& operator=(const edge_finder&); // just to avoid a compiler warning
741  private:
742  const MSEdge* const myEdge;
743  };
744 
745 private:
747  MSLane(const MSLane&);
748 
750  MSLane& operator=(const MSLane&);
751 
752 
753 };
754 
755 
756 #endif
757 
758 /****************************************************************************/
759