SUMO - Simulation of Urban MObility
MSVehicleContainer.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // vehicles sorted by their departures
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef MSVehicleContainer_h
23 #define MSVehicleContainer_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <vector>
36 #include <iostream>
37 
38 
39 // ===========================================================================
40 // class declarations
41 // ===========================================================================
42 class MSVehicle;
43 
44 
45 // ===========================================================================
46 // class definitions
47 // ===========================================================================
55 public:
57  typedef std::vector<SUMOVehicle*> VehicleVector;
58 
61  typedef std::pair<SUMOTime, VehicleVector> VehicleDepartureVector;
62 
63 public:
65  MSVehicleContainer(size_t capacity = 10);
66 
69 
71  void add(SUMOVehicle* veh);
72 
74  void add(SUMOTime time, const VehicleVector& cont);
75 
77  bool anyWaitingBefore(SUMOTime time) const;
78 
80  const VehicleVector& top();
81 
83  SUMOTime topTime() const;
84 
86  void pop();
87 
89  bool isEmpty() const;
90 
92  size_t size() const;
93 
95  void showArray() const;
96 
98  friend std::ostream& operator << (std::ostream& strm,
99  MSVehicleContainer& cont);
100 
101 private:
104  void addReplacing(const VehicleDepartureVector& cont);
105 
107  bool isFull() const;
108 
111  public:
113  bool operator()(const VehicleDepartureVector& e1,
114  const VehicleDepartureVector& e2) const;
115  };
116 
118  class DepartFinder {
119  public:
121  explicit DepartFinder(SUMOTime time);
122 
124  bool operator()(const VehicleDepartureVector& e) const;
125 
126  private:
129  };
130 
133 
135  typedef std::vector<VehicleDepartureVector> VehicleHeap;
136 
138  VehicleHeap array;
139 
141  void percolateDown(int hole);
142 
143 };
144 
145 
146 #endif
147 
148 /****************************************************************************/
149 
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:80
long long int SUMOTime
Definition: SUMOTime.h:43
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:65
MSVehicleContainer(size_t capacity=10)
Constructor.
size_t size() const
Returns the size of the container.
void add(SUMOVehicle *veh)
Adds a single vehicle.
const VehicleVector & top()
Returns the uppermost vehicle vector.
SUMOTime myTime
the searched departure time
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.
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.