Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NIVissimTrafficDescription.cpp
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/****************************************************************************/
18// -------------------
19/****************************************************************************/
20#include <config.h>
21
22#include <string>
23#include <map>
24#include <cassert>
27
28
29// ===========================================================================
30// member function definitions
31// ===========================================================================
33
34
35// ===========================================================================
36// member method definitions
37// ===========================================================================
39 const std::string& name,
40 const NIVissimVehicleClassVector& vehicleTypes)
41 : myName(name), myVehicleTypes(vehicleTypes) {}
42
43
45 for (NIVissimVehicleClassVector::iterator i = myVehicleTypes.begin(); i != myVehicleTypes.end(); i++) {
46 delete *i;
47 }
48 myVehicleTypes.clear();
49}
50
51
52bool
54 const std::string& name,
55 const NIVissimVehicleClassVector& vehicleTypes) {
56 NIVissimTrafficDescription* o = new NIVissimTrafficDescription(name, vehicleTypes);
57 if (!dictionary(id, o)) {
58 delete o;
59 return false;
60 }
61 return true;
62}
63
64
65bool
67 DictType::iterator i = myDict.find(id);
68 if (i == myDict.end()) {
69 myDict[id] = o;
70 return true;
71 }
72 return false;
73}
74
75
78 DictType::iterator i = myDict.find(id);
79 if (i == myDict.end()) {
80 return nullptr;
81 }
82 return (*i).second;
83}
84
85
86void
88 for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
89 delete (*i).second;
90 }
91 myDict.clear();
92}
93
94
95
96
97double
100 assert(i != 0);
101 return i->meanSpeed();
102}
103
104
105double
107 double speed = 0;
108 for (NIVissimVehicleClassVector::const_iterator i = myVehicleTypes.begin(); i != myVehicleTypes.end(); i++) {
109 speed += (*i)->getSpeed();
110 }
111 return speed / (double) myVehicleTypes.size();
112}
113
114
115/****************************************************************************/
std::vector< NIVissimVehicleClass * > NIVissimVehicleClassVector
static bool dictionary(int id, const std::string &name, const NIVissimVehicleClassVector &vehicleTypes)
NIVissimTrafficDescription(const std::string &name, const NIVissimVehicleClassVector &vehicleTypes)
std::map< int, NIVissimTrafficDescription * > DictType
NIVissimVehicleClassVector myVehicleTypes