Eclipse SUMO - Simulation of Urban MObility
NIVissimTrafficDescription.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // -------------------
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
24 #include <string>
25 #include <map>
26 #include <cassert>
29 
30 
31 // ===========================================================================
32 // member function definitions
33 // ===========================================================================
35 
36 
37 // ===========================================================================
38 // member method definitions
39 // ===========================================================================
41  const std::string& name,
42  const NIVissimVehicleClassVector& vehicleTypes)
43  : myName(name), myVehicleTypes(vehicleTypes) {}
44 
45 
47  for (NIVissimVehicleClassVector::iterator i = myVehicleTypes.begin(); i != myVehicleTypes.end(); i++) {
48  delete *i;
49  }
50  myVehicleTypes.clear();
51 }
52 
53 
54 bool
56  const std::string& name,
57  const NIVissimVehicleClassVector& vehicleTypes) {
58  NIVissimTrafficDescription* o = new NIVissimTrafficDescription(name, vehicleTypes);
59  if (!dictionary(id, o)) {
60  delete o;
61  return false;
62  }
63  return true;
64 }
65 
66 
67 bool
69  DictType::iterator i = myDict.find(id);
70  if (i == myDict.end()) {
71  myDict[id] = o;
72  return true;
73  }
74  return false;
75 }
76 
77 
80  DictType::iterator i = myDict.find(id);
81  if (i == myDict.end()) {
82  return nullptr;
83  }
84  return (*i).second;
85 }
86 
87 
88 void
90  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
91  delete (*i).second;
92  }
93  myDict.clear();
94 }
95 
96 
97 
98 
99 double
102  assert(i != 0);
103  return i->meanSpeed();
104 }
105 
106 
107 double
109  double speed = 0;
110  for (NIVissimVehicleClassVector::const_iterator i = myVehicleTypes.begin(); i != myVehicleTypes.end(); i++) {
111  speed += (*i)->getSpeed();
112  }
113  return speed / (double) myVehicleTypes.size();
114 }
115 
116 
117 
118 /****************************************************************************/
119 
std::vector< NIVissimVehicleClass * > NIVissimVehicleClassVector
std::map< int, NIVissimTrafficDescription * > DictType
NIVissimTrafficDescription(const std::string &name, const NIVissimVehicleClassVector &vehicleTypes)
NIVissimVehicleClassVector myVehicleTypes
static bool dictionary(int id, const std::string &name, const NIVissimVehicleClassVector &vehicleTypes)