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