SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
12 // Copyright (C) 2001-2014 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 #include "MSNet.h"
38 
39 
40 // ===========================================================================
41 // class declarations
42 // ===========================================================================
43 class MSVehicle;
44 
45 
46 // ===========================================================================
47 // class definitions
48 // ===========================================================================
56 public:
58  typedef std::vector<SUMOVehicle*> VehicleVector;
59 
62  typedef std::pair<SUMOTime, VehicleVector> VehicleDepartureVector;
63 
64 public:
66  MSVehicleContainer(size_t capacity = 10);
67 
70 
72  void add(SUMOVehicle* veh);
73 
75  void add(SUMOTime time, const VehicleVector& cont);
76 
78  bool anyWaitingFor(SUMOTime time) const;
79 
81  const VehicleVector& top();
82 
84  SUMOTime topTime() const;
85 
87  void pop();
88 
90  bool isEmpty() const;
91 
93  size_t size() const;
94 
96  void showArray() const;
97 
99  friend std::ostream& operator << (std::ostream& strm,
100  MSVehicleContainer& cont);
101 
102 private:
105  void addReplacing(const VehicleDepartureVector& cont);
106 
108  bool isFull() const;
109 
112  public:
114  bool operator()(const VehicleDepartureVector& e1,
115  const VehicleDepartureVector& e2) const;
116  };
117 
119  class DepartFinder {
120  public:
122  explicit DepartFinder(SUMOTime time);
123 
125  bool operator()(const VehicleDepartureVector& e) const;
126 
127  private:
130  };
131 
134 
136  typedef std::vector<VehicleDepartureVector> VehicleHeap;
137 
140 
142  void percolateDown(int hole);
143 
144 };
145 
146 
147 #endif
148 
149 /****************************************************************************/
150 
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:77
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 &e) const
comparison operator
DepartFinder(SUMOTime time)
constructor
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:63
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
bool anyWaitingFor(SUMOTime time) const
Returns the information whether any vehicles want to depart at the given time.
Sort-criterion for vehicle departure lists.
std::pair< SUMOTime, VehicleVector > VehicleDepartureVector
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.