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-2017 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(int capacity = 10);
66 
69 
71  void add(SUMOVehicle* veh);
72 
74  void remove(SUMOVehicle* veh);
75 
77  void add(SUMOTime time, const VehicleVector& cont);
78 
80  bool anyWaitingBefore(SUMOTime time) const;
81 
83  const VehicleVector& top();
84 
86  SUMOTime topTime() const;
87 
89  void pop();
90 
92  bool isEmpty() const;
93 
95  int size() const;
96 
98  void showArray() const;
99 
101  friend std::ostream& operator << (std::ostream& strm,
102  MSVehicleContainer& cont);
103 
104 private:
107  void addReplacing(const VehicleDepartureVector& cont);
108 
110  bool isFull() const;
111 
114  public:
116  bool operator()(const VehicleDepartureVector& e1,
117  const VehicleDepartureVector& e2) const;
118  };
119 
121  class DepartFinder {
122  public:
124  explicit DepartFinder(SUMOTime time);
125 
127  bool operator()(const VehicleDepartureVector& e) const;
128 
129  private:
132  };
133 
136 
138  typedef std::vector<VehicleDepartureVector> VehicleHeap;
139 
141  VehicleHeap array;
142 
144  void percolateDown(int hole);
145 
146 };
147 
148 
149 #endif
150 
151 /****************************************************************************/
152 
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
int size() const
Returns the size of the container.
VehicleHeap array
The vehicle vector heap.
void percolateDown(int hole)
Moves the elements down.
bool isEmpty() const
Returns the information whether the container is empty.
bool anyWaitingBefore(SUMOTime time) const
Returns the information whether any vehicles want to depart before the given time.
bool operator()(const VehicleDepartureVector &e1, const VehicleDepartureVector &e2) const
comparison operator
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:67
void add(SUMOVehicle *veh)
Adds a single vehicle.
void showArray() const
Prints the container (the departure times)
const VehicleVector & top()
Returns the uppermost vehicle vector.
SUMOTime myTime
the searched departure time
MSVehicleContainer(int capacity=10)
Constructor.
SUMOTime topTime() const
Returns the time the uppermost vehicle vector is assigned to.
Sort-criterion for vehicle departure lists.
std::pair< SUMOTime, VehicleVector > VehicleDepartureVector
long long int SUMOTime
Definition: TraCIDefs.h:52
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.