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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // -------------------
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include <string>
31 #include <map>
32 #include <cassert>
35 
36 
37 // ===========================================================================
38 // member function definitions
39 // ===========================================================================
41 
42 
43 // ===========================================================================
44 // member method definitions
45 // ===========================================================================
47  const std::string& name,
48  const NIVissimVehicleClassVector& vehicleTypes)
49  : myName(name), myVehicleTypes(vehicleTypes) {}
50 
51 
53  for (NIVissimVehicleClassVector::iterator i = myVehicleTypes.begin(); i != myVehicleTypes.end(); i++) {
54  delete *i;
55  }
56  myVehicleTypes.clear();
57 }
58 
59 
60 bool
62  const std::string& name,
63  const NIVissimVehicleClassVector& vehicleTypes) {
64  NIVissimTrafficDescription* o = new NIVissimTrafficDescription(name, vehicleTypes);
65  if (!dictionary(id, o)) {
66  delete o;
67  return false;
68  }
69  return true;
70 }
71 
72 
73 bool
75  DictType::iterator i = myDict.find(id);
76  if (i == myDict.end()) {
77  myDict[id] = o;
78  return true;
79  }
80  return false;
81 }
82 
83 
86  DictType::iterator i = myDict.find(id);
87  if (i == myDict.end()) {
88  return 0;
89  }
90  return (*i).second;
91 }
92 
93 
94 void
96  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
97  delete(*i).second;
98  }
99  myDict.clear();
100 }
101 
102 
103 
104 
105 double
108  assert(i != 0);
109  return i->meanSpeed();
110 }
111 
112 
113 double
115  double speed = 0;
116  for (NIVissimVehicleClassVector::const_iterator i = myVehicleTypes.begin(); i != myVehicleTypes.end(); i++) {
117  speed += (*i)->getSpeed();
118  }
119  return speed / (double) myVehicleTypes.size();
120 }
121 
122 
123 
124 /****************************************************************************/
125 
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)