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-2022 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
20// vehicles sorted by their departures
21/****************************************************************************/
22#pragma once
23#include <config.h>
24
25#include <vector>
26#include <iostream>
27
28
29// ===========================================================================
30// class declarations
31// ===========================================================================
32class MSVehicle;
33
34
35// ===========================================================================
36// class definitions
37// ===========================================================================
45public:
47 typedef std::vector<SUMOVehicle*> VehicleVector;
48
51 typedef std::pair<SUMOTime, VehicleVector> VehicleDepartureVector;
52
53public:
55 MSVehicleContainer(int capacity = 10);
56
59
61 void add(SUMOVehicle* veh);
62
64 void remove(SUMOVehicle* veh);
65
67 void add(SUMOTime time, const VehicleVector& cont);
68
70 bool anyWaitingBefore(SUMOTime time) const;
71
73 const VehicleVector& top();
74
76 SUMOTime topTime() const;
77
79 void pop();
80
82 bool isEmpty() const;
83
85 int size() const;
86
88 void showArray() const;
89
91 friend std::ostream& operator << (std::ostream& strm,
92 MSVehicleContainer& cont);
93
95 void clearState();
96
97private:
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
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
135
137 void percolateDown(int hole);
138
139};
long long int SUMOTime
Definition: GUI.h:36
Searches for the VehicleDepartureVector with the wished depart.
bool operator()(const VehicleDepartureVector &e) const
comparison operator
DepartFinder(SUMOTime time)
constructor
SUMOTime myTime
the searched departure time
Sort-criterion for vehicle departure lists.
bool operator()(const VehicleDepartureVector &e1, const VehicleDepartureVector &e2) const
comparison operator
bool anyWaitingBefore(SUMOTime time) const
Returns the information whether any vehicles want to depart before the given time.
std::pair< SUMOTime, VehicleVector > VehicleDepartureVector
void remove(SUMOVehicle *veh)
Removes a single vehicle.
void percolateDown(int hole)
Moves the elements down.
void add(SUMOVehicle *veh)
Adds a single vehicle.
void addReplacing(const VehicleDepartureVector &cont)
Replaces the existing single departure time vector by the one given.
int size() const
Returns the size of the container.
void pop()
Removes the uppermost vehicle vector.
int currentSize
Number of elements in heap.
void showArray() const
Prints the container (the departure times)
MSVehicleContainer(int capacity=10)
Constructor.
VehicleHeap array
The vehicle vector heap.
SUMOTime topTime() const
Returns the time the uppermost vehicle vector is assigned to.
friend std::ostream & operator<<(std::ostream &strm, MSVehicleContainer &cont)
Prints the contents of the container.
~MSVehicleContainer()
Destructor.
std::vector< SUMOVehicle * > VehicleVector
definition of a list of vehicles which have the same departure time
void clearState()
Remove all vehicles before quick-loading state.
bool isEmpty() const
Returns the information whether the container is empty.
std::vector< VehicleDepartureVector > VehicleHeap
Definition of the heap type.
const VehicleVector & top()
Returns the uppermost vehicle vector.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
Representation of a vehicle.
Definition: SUMOVehicle.h:60