SUMO - Simulation of Urban MObility
NIVissimTrafficDescription.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // -------------------
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <string>
32 #include <map>
33 #include <cassert>
36 
37 
38 // ===========================================================================
39 // member function definitions
40 // ===========================================================================
42 
43 
44 // ===========================================================================
45 // member method definitions
46 // ===========================================================================
48  const std::string& name,
49  const NIVissimVehicleClassVector& vehicleTypes)
50  : myName(name), myVehicleTypes(vehicleTypes) {}
51 
52 
54  for (NIVissimVehicleClassVector::iterator i = myVehicleTypes.begin(); i != myVehicleTypes.end(); i++) {
55  delete *i;
56  }
57  myVehicleTypes.clear();
58 }
59 
60 
61 bool
63  const std::string& name,
64  const NIVissimVehicleClassVector& vehicleTypes) {
65  NIVissimTrafficDescription* o = new NIVissimTrafficDescription(name, vehicleTypes);
66  if (!dictionary(id, o)) {
67  delete o;
68  return false;
69  }
70  return true;
71 }
72 
73 
74 bool
76  DictType::iterator i = myDict.find(id);
77  if (i == myDict.end()) {
78  myDict[id] = o;
79  return true;
80  }
81  return false;
82 }
83 
84 
87  DictType::iterator i = myDict.find(id);
88  if (i == myDict.end()) {
89  return 0;
90  }
91  return (*i).second;
92 }
93 
94 
95 void
97  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
98  delete(*i).second;
99  }
100  myDict.clear();
101 }
102 
103 
104 
105 
106 double
109  assert(i != 0);
110  return i->meanSpeed();
111 }
112 
113 
114 double
116  double speed = 0;
117  for (NIVissimVehicleClassVector::const_iterator i = myVehicleTypes.begin(); i != myVehicleTypes.end(); i++) {
118  speed += (*i)->getSpeed();
119  }
120  return speed / (double) myVehicleTypes.size();
121 }
122 
123 
124 
125 /****************************************************************************/
126 
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)