Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSVehicleContainer.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 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
29
30
31// ===========================================================================
32// class declarations
33// ===========================================================================
34class SUMOVehicle;
35
36
37// ===========================================================================
38// class definitions
39// ===========================================================================
47public:
49 typedef std::vector<SUMOVehicle*> VehicleVector;
50
53 typedef std::pair<SUMOTime, VehicleVector> VehicleDepartureVector;
54
55public:
57 MSVehicleContainer(int capacity = 10);
58
61
63 void add(SUMOVehicle* veh);
64
66 void remove(SUMOVehicle* veh);
67
69 void add(SUMOTime time, const VehicleVector& cont);
70
72 bool anyWaitingBefore(SUMOTime time) const;
73
75 const VehicleVector& top();
76
78 SUMOTime topTime() const;
79
81 void pop();
82
84 bool isEmpty() const;
85
87 int size() const;
88
90 void showArray() const;
91
93 friend std::ostream& operator << (std::ostream& strm,
94 MSVehicleContainer& cont);
95
97 void clearState();
98
99private:
102 void addReplacing(const VehicleDepartureVector& cont);
103
105 bool isFull() const;
106
109 public:
111 bool operator()(const VehicleDepartureVector& e1,
112 const VehicleDepartureVector& e2) const;
113 };
114
117 public:
119 explicit DepartFinder(SUMOTime time);
120
122 bool operator()(const VehicleDepartureVector& e) const;
123
124 private:
127 };
128
131
133 typedef std::vector<VehicleDepartureVector> VehicleHeap;
134
137
139 void percolateDown(int hole);
140
141};
long long int SUMOTime
Definition GUI.h:36
Searches for the VehicleDepartureVector with the wished depart.
bool operator()(const VehicleDepartureVector &e) const
comparison operator
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)
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.
Definition SUMOVehicle.h:62