SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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-2015 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 #ifdef CHECK_MEMORY_LEAKS
38 #include <foreign/nvwa/debug_new.h>
39 #endif // CHECK_MEMORY_LEAKS
40 
41 
42 // ===========================================================================
43 // member function definitions
44 // ===========================================================================
46 
47 
48 // ===========================================================================
49 // member method definitions
50 // ===========================================================================
52  const std::string& name,
53  const NIVissimVehicleClassVector& vehicleTypes)
54  : myName(name), myVehicleTypes(vehicleTypes) {}
55 
56 
58  for (NIVissimVehicleClassVector::iterator i = myVehicleTypes.begin(); i != myVehicleTypes.end(); i++) {
59  delete *i;
60  }
61  myVehicleTypes.clear();
62 }
63 
64 
65 bool
67  const std::string& name,
68  const NIVissimVehicleClassVector& vehicleTypes) {
69  NIVissimTrafficDescription* o = new NIVissimTrafficDescription(name, vehicleTypes);
70  if (!dictionary(id, o)) {
71  delete o;
72  return false;
73  }
74  return true;
75 }
76 
77 
78 bool
80  DictType::iterator i = myDict.find(id);
81  if (i == myDict.end()) {
82  myDict[id] = o;
83  return true;
84  }
85  return false;
86 }
87 
88 
91  DictType::iterator i = myDict.find(id);
92  if (i == myDict.end()) {
93  return 0;
94  }
95  return (*i).second;
96 }
97 
98 
99 void
101  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
102  delete(*i).second;
103  }
104  myDict.clear();
105 }
106 
107 
108 
109 
110 SUMOReal
113  assert(i != 0);
114  return i->meanSpeed();
115 }
116 
117 
118 SUMOReal
120  SUMOReal speed = 0;
121  for (NIVissimVehicleClassVector::const_iterator i = myVehicleTypes.begin(); i != myVehicleTypes.end(); i++) {
122  speed += (*i)->getSpeed();
123  }
124  return speed / (SUMOReal) myVehicleTypes.size();
125 }
126 
127 
128 
129 /****************************************************************************/
130 
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)
#define SUMOReal
Definition: config.h:218