|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // ------------------- 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 /****************************************************************************/ 00012 // 00013 // This program is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU General Public License as published by 00015 // the Free Software Foundation; either version 2 of the License, or 00016 // (at your option) any later version. 00017 // 00018 /****************************************************************************/ 00019 00020 00021 // =========================================================================== 00022 // included modules 00023 // =========================================================================== 00024 #ifdef _MSC_VER 00025 #include <windows_config.h> 00026 #else 00027 #include <config.h> 00028 #endif 00029 00030 #include <string> 00031 #include <map> 00032 #include <cassert> 00033 #include "NIVissimVehicleClassVector.h" 00034 #include "NIVissimTrafficDescription.h" 00035 00036 #ifdef CHECK_MEMORY_LEAKS 00037 #include <foreign/nvwa/debug_new.h> 00038 #endif // CHECK_MEMORY_LEAKS 00039 00040 00041 // =========================================================================== 00042 // member function definitions 00043 // =========================================================================== 00044 NIVissimTrafficDescription::DictType NIVissimTrafficDescription::myDict; 00045 00046 00047 // =========================================================================== 00048 // member method definitions 00049 // =========================================================================== 00050 NIVissimTrafficDescription::NIVissimTrafficDescription( 00051 int id, const std::string& name, 00052 const NIVissimVehicleClassVector& vehicleTypes) 00053 : myID(id), myName(name), myVehicleTypes(vehicleTypes) {} 00054 00055 00056 NIVissimTrafficDescription::~NIVissimTrafficDescription() { 00057 for (NIVissimVehicleClassVector::iterator i=myVehicleTypes.begin(); i!=myVehicleTypes.end(); i++) { 00058 delete *i; 00059 } 00060 myVehicleTypes.clear(); 00061 } 00062 00063 00064 bool 00065 NIVissimTrafficDescription::dictionary(int id, 00066 const std::string& name, 00067 const NIVissimVehicleClassVector& vehicleTypes) { 00068 NIVissimTrafficDescription* o = new NIVissimTrafficDescription(id, name, vehicleTypes); 00069 if (!dictionary(id, o)) { 00070 delete o; 00071 return false; 00072 } 00073 return true; 00074 } 00075 00076 00077 bool 00078 NIVissimTrafficDescription::dictionary(int id, NIVissimTrafficDescription* o) { 00079 DictType::iterator i=myDict.find(id); 00080 if (i==myDict.end()) { 00081 myDict[id] = o; 00082 return true; 00083 } 00084 return false; 00085 } 00086 00087 00088 NIVissimTrafficDescription* 00089 NIVissimTrafficDescription::dictionary(int id) { 00090 DictType::iterator i=myDict.find(id); 00091 if (i==myDict.end()) { 00092 return 0; 00093 } 00094 return (*i).second; 00095 } 00096 00097 00098 void 00099 NIVissimTrafficDescription::clearDict() { 00100 for (DictType::iterator i=myDict.begin(); i!=myDict.end(); i++) { 00101 delete(*i).second; 00102 } 00103 myDict.clear(); 00104 } 00105 00106 00107 00108 00109 SUMOReal 00110 NIVissimTrafficDescription::meanSpeed(int id) { 00111 NIVissimTrafficDescription* i = dictionary(id); 00112 assert(i!=0); 00113 return i->meanSpeed(); 00114 } 00115 00116 00117 SUMOReal 00118 NIVissimTrafficDescription::meanSpeed() const { 00119 SUMOReal speed = 0; 00120 for (NIVissimVehicleClassVector::const_iterator i=myVehicleTypes.begin(); i!=myVehicleTypes.end(); i++) { 00121 speed += (*i)->getSpeed(); 00122 } 00123 return speed / (SUMOReal) myVehicleTypes.size(); 00124 } 00125 00126 00127 00128 /****************************************************************************/ 00129