Eclipse SUMO - Simulation of Urban MObility
MSVehicleContainer.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // vehicles sorted by their departures
18 /****************************************************************************/
19 #ifndef MSVehicleContainer_h
20 #define MSVehicleContainer_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <vector>
29 #include <iostream>
30 
31 
32 // ===========================================================================
33 // class declarations
34 // ===========================================================================
35 class MSVehicle;
36 
37 
38 // ===========================================================================
39 // class definitions
40 // ===========================================================================
48 public:
50  typedef std::vector<SUMOVehicle*> VehicleVector;
51 
54  typedef std::pair<SUMOTime, VehicleVector> VehicleDepartureVector;
55 
56 public:
58  MSVehicleContainer(int capacity = 10);
59 
62 
64  void add(SUMOVehicle* veh);
65 
67  void remove(SUMOVehicle* veh);
68 
70  void add(SUMOTime time, const VehicleVector& cont);
71 
73  bool anyWaitingBefore(SUMOTime time) const;
74 
76  const VehicleVector& top();
77 
79  SUMOTime topTime() const;
80 
82  void pop();
83 
85  bool isEmpty() const;
86 
88  int size() const;
89 
91  void showArray() const;
92 
94  friend std::ostream& operator << (std::ostream& strm,
95  MSVehicleContainer& cont);
96 
97 private:
100  void addReplacing(const VehicleDepartureVector& cont);
101 
103  bool isFull() const;
104 
107  public:
109  bool operator()(const VehicleDepartureVector& e1,
110  const VehicleDepartureVector& e2) const;
111  };
112 
114  class DepartFinder {
115  public:
117  explicit DepartFinder(SUMOTime time);
118 
120  bool operator()(const VehicleDepartureVector& e) const;
121 
122  private:
125  };
126 
129 
131  typedef std::vector<VehicleDepartureVector> VehicleHeap;
132 
135 
137  void percolateDown(int hole);
138 
139 };
140 
141 
142 #endif
143 
144 /****************************************************************************/
145 
MSVehicleContainer::DepartFinder
Searches for the VehicleDepartureVector with the wished depart.
Definition: MSVehicleContainer.h:114
MSVehicleContainer::pop
void pop()
Removes the uppermost vehicle vector.
Definition: MSVehicleContainer.cpp:172
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:35
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:61
MSVehicleContainer::currentSize
int currentSize
Number of elements in heap.
Definition: MSVehicleContainer.h:128
MSVehicleContainer::MSVehicleContainer
MSVehicleContainer(int capacity=10)
Constructor.
Definition: MSVehicleContainer.cpp:65
MSVehicleContainer::addReplacing
void addReplacing(const VehicleDepartureVector &cont)
Replaces the existing single departure time vector by the one given.
Definition: MSVehicleContainer.cpp:124
MSVehicleContainer::DepartFinder::operator()
bool operator()(const VehicleDepartureVector &e) const
comparison operator
Definition: MSVehicleContainer.cpp:56
MSVehicleContainer::~MSVehicleContainer
~MSVehicleContainer()
Destructor.
Definition: MSVehicleContainer.cpp:69
MSVehicleContainer::remove
void remove(SUMOVehicle *veh)
Removes a single vehicle.
Definition: MSVehicleContainer.cpp:93
MSVehicleContainer::VehicleDepartureVectorSortCrit::operator()
bool operator()(const VehicleDepartureVector &e1, const VehicleDepartureVector &e2) const
comparison operator
Definition: MSVehicleContainer.cpp:41
MSVehicleContainer::VehicleDepartureVector
std::pair< SUMOTime, VehicleVector > VehicleDepartureVector
Definition: MSVehicleContainer.h:54
MSVehicleContainer::topTime
SUMOTime topTime() const
Returns the time the uppermost vehicle vector is assigned to.
Definition: MSVehicleContainer.cpp:162
MSVehicleContainer::VehicleVector
std::vector< SUMOVehicle * > VehicleVector
definition of a list of vehicles which have the same departure time
Definition: MSVehicleContainer.h:50
MSVehicleContainer::operator<<
friend std::ostream & operator<<(std::ostream &strm, MSVehicleContainer &cont)
Prints the contents of the container.
Definition: MSVehicleContainer.cpp:238
MSVehicleContainer
Definition: MSVehicleContainer.h:47
MSVehicleContainer::DepartFinder::myTime
SUMOTime myTime
the searched departure time
Definition: MSVehicleContainer.h:124
MSVehicleContainer::VehicleHeap
std::vector< VehicleDepartureVector > VehicleHeap
Definition of the heap type.
Definition: MSVehicleContainer.h:131
MSVehicleContainer::array
VehicleHeap array
The vehicle vector heap.
Definition: MSVehicleContainer.h:134
MSVehicleContainer::isEmpty
bool isEmpty() const
Returns the information whether the container is empty.
Definition: MSVehicleContainer.cpp:186
MSVehicleContainer::size
int size() const
Returns the size of the container.
Definition: MSVehicleContainer.cpp:221
MSVehicleContainer::anyWaitingBefore
bool anyWaitingBefore(SUMOTime time) const
Returns the information whether any vehicles want to depart before the given time.
Definition: MSVehicleContainer.cpp:146
MSVehicleContainer::isFull
bool isFull() const
Definition: MSVehicleContainer.cpp:192
MSVehicleContainer::percolateDown
void percolateDown(int hole)
Moves the elements down.
Definition: MSVehicleContainer.cpp:198
config.h
MSVehicleContainer::top
const VehicleVector & top()
Returns the uppermost vehicle vector.
Definition: MSVehicleContainer.cpp:152
MSVehicleContainer::DepartFinder::DepartFinder
DepartFinder(SUMOTime time)
constructor
Definition: MSVehicleContainer.cpp:50
MSVehicleContainer::showArray
void showArray() const
Prints the container (the departure times)
Definition: MSVehicleContainer.cpp:227
MSVehicleContainer::add
void add(SUMOVehicle *veh)
Adds a single vehicle.
Definition: MSVehicleContainer.cpp:75
MSVehicleContainer::VehicleDepartureVectorSortCrit
Sort-criterion for vehicle departure lists.
Definition: MSVehicleContainer.h:106
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80