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 
134  VehicleHeap array;
135 
137  void percolateDown(int hole);
138 
139 };
140 
141 
142 #endif
143 
144 /****************************************************************************/
145 
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:35
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:61
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
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.