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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // vehicles sorted by their departures
20 /****************************************************************************/
21 #ifndef MSVehicleContainer_h
22 #define MSVehicleContainer_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <vector>
35 #include <iostream>
36 
37 
38 // ===========================================================================
39 // class declarations
40 // ===========================================================================
41 class MSVehicle;
42 
43 
44 // ===========================================================================
45 // class definitions
46 // ===========================================================================
54 public:
56  typedef std::vector<SUMOVehicle*> VehicleVector;
57 
60  typedef std::pair<SUMOTime, VehicleVector> VehicleDepartureVector;
61 
62 public:
64  MSVehicleContainer(int capacity = 10);
65 
68 
70  void add(SUMOVehicle* veh);
71 
73  void remove(SUMOVehicle* veh);
74 
76  void add(SUMOTime time, const VehicleVector& cont);
77 
79  bool anyWaitingBefore(SUMOTime time) const;
80 
82  const VehicleVector& top();
83 
85  SUMOTime topTime() const;
86 
88  void pop();
89 
91  bool isEmpty() const;
92 
94  int size() const;
95 
97  void showArray() const;
98 
100  friend std::ostream& operator << (std::ostream& strm,
101  MSVehicleContainer& cont);
102 
103 private:
106  void addReplacing(const VehicleDepartureVector& cont);
107 
109  bool isFull() const;
110 
113  public:
115  bool operator()(const VehicleDepartureVector& e1,
116  const VehicleDepartureVector& e2) const;
117  };
118 
120  class DepartFinder {
121  public:
123  explicit DepartFinder(SUMOTime time);
124 
126  bool operator()(const VehicleDepartureVector& e) const;
127 
128  private:
131  };
132 
135 
137  typedef std::vector<VehicleDepartureVector> VehicleHeap;
138 
140  VehicleHeap array;
141 
143  void percolateDown(int hole);
144 
145 };
146 
147 
148 #endif
149 
150 /****************************************************************************/
151 
friend std::ostream & operator<<(std::ostream &strm, MSVehicleContainer &cont)
Prints the contents of the container.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
VehicleHeap array
The vehicle vector heap.
SUMOTime topTime() const
Returns the time the uppermost vehicle vector is assigned to.
void percolateDown(int hole)
Moves the elements down.
bool operator()(const VehicleDepartureVector &e1, const VehicleDepartureVector &e2) const
comparison operator
bool isEmpty() const
Returns the information whether the container is empty.
std::vector< SUMOVehicle * > VehicleVector
definition of a list of vehicles which have the same departure time
int currentSize
Number of elements in heap.
void pop()
Removes the uppermost vehicle vector.
std::vector< VehicleDepartureVector > VehicleHeap
Definition of the heap type.
Representation of a vehicle.
Definition: SUMOVehicle.h:66
void add(SUMOVehicle *veh)
Adds a single vehicle.
const VehicleVector & top()
Returns the uppermost vehicle vector.
SUMOTime myTime
the searched departure time
MSVehicleContainer(int capacity=10)
Constructor.
int size() const
Returns the size of the container.
Sort-criterion for vehicle departure lists.
std::pair< SUMOTime, VehicleVector > VehicleDepartureVector
bool anyWaitingBefore(SUMOTime time) const
Returns the information whether any vehicles want to depart before the given time.
long long int SUMOTime
Definition: TraCIDefs.h:51
void showArray() const
Prints the container (the departure times)
void addReplacing(const VehicleDepartureVector &cont)
Replaces the existing single departure time vector by the one given.
Searches for the VehicleDepartureVector with the wished depart.
~MSVehicleContainer()
Destructor.