Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netimport/vissim/tempstructs/NIVissimTrafficDescription.cpp
169684 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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
/****************************************************************************/
14
/// @file NIVissimTrafficDescription.cpp
15
/// @author Daniel Krajzewicz
16
/// @date Sept 2002
17
///
18
// -------------------
19
/****************************************************************************/
20
#include <config.h>
21
22
#include <string>
23
#include <map>
24
#include <cassert>
25
#include "NIVissimVehicleClassVector.h"
26
#include "NIVissimTrafficDescription.h"
27
28
29
// ===========================================================================
30
// member function definitions
31
// ===========================================================================
32
NIVissimTrafficDescription::DictType NIVissimTrafficDescription::myDict;
33
34
35
// ===========================================================================
36
// member method definitions
37
// ===========================================================================
38
NIVissimTrafficDescription::NIVissimTrafficDescription(
39
const std::string& name,
40
const NIVissimVehicleClassVector& vehicleTypes)
41
: myName(name), myVehicleTypes(vehicleTypes) {}
42
43
44
NIVissimTrafficDescription::~NIVissimTrafficDescription() {
45
for (NIVissimVehicleClassVector::iterator i = myVehicleTypes.begin(); i != myVehicleTypes.end(); i++) {
46
delete *i;
47
}
48
myVehicleTypes.clear();
49
}
50
51
52
bool
53
NIVissimTrafficDescription::dictionary(int id,
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
65
bool
66
NIVissimTrafficDescription::dictionary(int id, NIVissimTrafficDescription* o) {
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
76
NIVissimTrafficDescription*
77
NIVissimTrafficDescription::dictionary(int id) {
78
DictType::iterator i = myDict.find(id);
79
if (i == myDict.end()) {
80
return nullptr;
81
}
82
return (*i).second;
83
}
84
85
86
void
87
NIVissimTrafficDescription::clearDict() {
88
for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
89
delete (*i).second;
90
}
91
myDict.clear();
92
}
93
94
95
96
97
double
98
NIVissimTrafficDescription::meanSpeed(int id) {
99
NIVissimTrafficDescription* i = dictionary(id);
100
assert(i != 0);
101
return i->meanSpeed();
102
}
103
104
105
double
106
NIVissimTrafficDescription::meanSpeed() const {
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
/****************************************************************************/
116
117