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 /****************************************************************************/
16 // vehicles sorted by their departures
17 /****************************************************************************/
18 #ifndef MSVehicleContainer_h
19 #define MSVehicleContainer_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <vector>
28 #include <iostream>
29 
30 
31 // ===========================================================================
32 // class declarations
33 // ===========================================================================
34 class MSVehicle;
35 
36 
37 // ===========================================================================
38 // class definitions
39 // ===========================================================================
47 public:
49  typedef std::vector<SUMOVehicle*> VehicleVector;
50 
53  typedef std::pair<SUMOTime, VehicleVector> VehicleDepartureVector;
54 
55 public:
57  MSVehicleContainer(int capacity = 10);
58 
61 
63  void add(SUMOVehicle* veh);
64 
66  void remove(SUMOVehicle* veh);
67 
69  void add(SUMOTime time, const VehicleVector& cont);
70 
72  bool anyWaitingBefore(SUMOTime time) const;
73 
75  const VehicleVector& top();
76 
78  SUMOTime topTime() const;
79 
81  void pop();
82 
84  bool isEmpty() const;
85 
87  int size() const;
88 
90  void showArray() const;
91 
93  friend std::ostream& operator << (std::ostream& strm,
94  MSVehicleContainer& cont);
95 
96 private:
99  void addReplacing(const VehicleDepartureVector& cont);
100 
102  bool isFull() const;
103 
106  public:
108  bool operator()(const VehicleDepartureVector& e1,
109  const VehicleDepartureVector& e2) const;
110  };
111 
113  class DepartFinder {
114  public:
116  explicit DepartFinder(SUMOTime time);
117 
119  bool operator()(const VehicleDepartureVector& e) const;
120 
121  private:
124  };
125 
128 
130  typedef std::vector<VehicleDepartureVector> VehicleHeap;
131 
134 
136  void percolateDown(int hole);
137 
138 };
139 
140 
141 #endif
142 
143 /****************************************************************************/
144 
MSVehicleContainer::DepartFinder
Searches for the VehicleDepartureVector with the wished depart.
Definition: MSVehicleContainer.h:113
MSVehicleContainer::pop
void pop()
Removes the uppermost vehicle vector.
Definition: MSVehicleContainer.cpp:171
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:60
MSVehicleContainer::currentSize
int currentSize
Number of elements in heap.
Definition: MSVehicleContainer.h:127
MSVehicleContainer::MSVehicleContainer
MSVehicleContainer(int capacity=10)
Constructor.
Definition: MSVehicleContainer.cpp:64
MSVehicleContainer::addReplacing
void addReplacing(const VehicleDepartureVector &cont)
Replaces the existing single departure time vector by the one given.
Definition: MSVehicleContainer.cpp:123
MSVehicleContainer::DepartFinder::operator()
bool operator()(const VehicleDepartureVector &e) const
comparison operator
Definition: MSVehicleContainer.cpp:55
MSVehicleContainer::~MSVehicleContainer
~MSVehicleContainer()
Destructor.
Definition: MSVehicleContainer.cpp:68
MSVehicleContainer::remove
void remove(SUMOVehicle *veh)
Removes a single vehicle.
Definition: MSVehicleContainer.cpp:92
MSVehicleContainer::VehicleDepartureVectorSortCrit::operator()
bool operator()(const VehicleDepartureVector &e1, const VehicleDepartureVector &e2) const
comparison operator
Definition: MSVehicleContainer.cpp:40
MSVehicleContainer::VehicleDepartureVector
std::pair< SUMOTime, VehicleVector > VehicleDepartureVector
Definition: MSVehicleContainer.h:53
MSVehicleContainer::topTime
SUMOTime topTime() const
Returns the time the uppermost vehicle vector is assigned to.
Definition: MSVehicleContainer.cpp:161
MSVehicleContainer::VehicleVector
std::vector< SUMOVehicle * > VehicleVector
definition of a list of vehicles which have the same departure time
Definition: MSVehicleContainer.h:49
MSVehicleContainer::operator<<
friend std::ostream & operator<<(std::ostream &strm, MSVehicleContainer &cont)
Prints the contents of the container.
Definition: MSVehicleContainer.cpp:237
MSVehicleContainer
Definition: MSVehicleContainer.h:46
MSVehicleContainer::DepartFinder::myTime
SUMOTime myTime
the searched departure time
Definition: MSVehicleContainer.h:123
MSVehicleContainer::VehicleHeap
std::vector< VehicleDepartureVector > VehicleHeap
Definition of the heap type.
Definition: MSVehicleContainer.h:130
MSVehicleContainer::array
VehicleHeap array
The vehicle vector heap.
Definition: MSVehicleContainer.h:133
MSVehicleContainer::isEmpty
bool isEmpty() const
Returns the information whether the container is empty.
Definition: MSVehicleContainer.cpp:185
MSVehicleContainer::size
int size() const
Returns the size of the container.
Definition: MSVehicleContainer.cpp:220
MSVehicleContainer::anyWaitingBefore
bool anyWaitingBefore(SUMOTime time) const
Returns the information whether any vehicles want to depart before the given time.
Definition: MSVehicleContainer.cpp:145
MSVehicleContainer::isFull
bool isFull() const
Definition: MSVehicleContainer.cpp:191
MSVehicleContainer::percolateDown
void percolateDown(int hole)
Moves the elements down.
Definition: MSVehicleContainer.cpp:197
config.h
MSVehicleContainer::top
const VehicleVector & top()
Returns the uppermost vehicle vector.
Definition: MSVehicleContainer.cpp:151
MSVehicleContainer::DepartFinder::DepartFinder
DepartFinder(SUMOTime time)
constructor
Definition: MSVehicleContainer.cpp:49
MSVehicleContainer::showArray
void showArray() const
Prints the container (the departure times)
Definition: MSVehicleContainer.cpp:226
MSVehicleContainer::add
void add(SUMOVehicle *veh)
Adds a single vehicle.
Definition: MSVehicleContainer.cpp:74
MSVehicleContainer::VehicleDepartureVectorSortCrit
Sort-criterion for vehicle departure lists.
Definition: MSVehicleContainer.h:105
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79