SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00011 // The car-following model and parameter 00012 /****************************************************************************/ 00013 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00014 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00015 /****************************************************************************/ 00016 // 00017 // This file is part of SUMO. 00018 // SUMO is free software: you can redistribute it and/or modify 00019 // it under the terms of the GNU General Public License as published by 00020 // the Free Software Foundation, either version 3 of the License, or 00021 // (at your option) any later version. 00022 // 00023 /****************************************************************************/ 00024 00025 00026 // =========================================================================== 00027 // included modules 00028 // =========================================================================== 00029 #ifdef _MSC_VER 00030 #include <windows_config.h> 00031 #else 00032 #include <config.h> 00033 #endif 00034 00035 #include <cassert> 00036 #include <utils/iodevices/BinaryInputDevice.h> 00037 #include <utils/common/FileHelpers.h> 00038 #include <utils/common/RandHelper.h> 00039 #include <utils/common/SUMOVTypeParameter.h> 00040 #include "MSNet.h" 00041 #include "cfmodels/MSCFModel_IDM.h" 00042 #include "cfmodels/MSCFModel_Kerner.h" 00043 #include "cfmodels/MSCFModel_Krauss.h" 00044 #include "cfmodels/MSCFModel_KraussOrig1.h" 00045 #include "cfmodels/MSCFModel_PWag2009.h" 00046 #include "cfmodels/MSCFModel_Wiedemann.h" 00047 #include "MSVehicleType.h" 00048 00049 #ifdef CHECK_MEMORY_LEAKS 00050 #include <foreign/nvwa/debug_new.h> 00051 #endif // CHECK_MEMORY_LEAKS 00052 00053 00054 // =========================================================================== 00055 // method definitions 00056 // =========================================================================== 00057 MSVehicleType::MSVehicleType(const std::string& id, const SUMOReal length, 00058 const SUMOReal minGap, const SUMOReal maxSpeed, const SUMOReal prob, 00059 const SUMOReal speedFactor, const SUMOReal speedDev, 00060 const SUMOVehicleClass vclass, 00061 const SUMOEmissionClass emissionClass, 00062 const SUMOReal guiWidth, const SUMOReal height, 00063 const SUMOVehicleShape shape, const std::string osgFile, 00064 const std::string& lcModel, 00065 const RGBColor& c) 00066 : myID(id), myLength(length), 00067 myMinGap(minGap), myMaxSpeed(maxSpeed), 00068 myDefaultProbability(prob), mySpeedFactor(speedFactor), 00069 mySpeedDev(speedDev), myLaneChangeModel(lcModel), 00070 myEmissionClass(emissionClass), myColor(c), 00071 myVehicleClass(vclass), myWidth(guiWidth), 00072 myHeight(height), myShape(shape), myOSGFile(osgFile), 00073 myOriginalType(0) { 00074 assert(myLength > 0); 00075 assert(getMaxSpeed() > 0); 00076 } 00077 00078 00079 MSVehicleType::~MSVehicleType() { 00080 delete myCarFollowModel; 00081 } 00082 00083 00084 void 00085 MSVehicleType::saveState(std::ostream& os) { 00086 FileHelpers::writeString(os, myID); 00087 FileHelpers::writeFloat(os, myLength); 00088 FileHelpers::writeFloat(os, myMinGap); 00089 FileHelpers::writeFloat(os, getMaxSpeed()); 00090 FileHelpers::writeInt(os, (int) myVehicleClass); 00091 FileHelpers::writeInt(os, (int) myEmissionClass); 00092 FileHelpers::writeInt(os, (int) myShape); 00093 FileHelpers::writeFloat(os, myWidth); 00094 FileHelpers::writeFloat(os, myDefaultProbability); 00095 FileHelpers::writeFloat(os, mySpeedFactor); 00096 FileHelpers::writeFloat(os, mySpeedDev); 00097 FileHelpers::writeFloat(os, myColor.red()); 00098 FileHelpers::writeFloat(os, myColor.green()); 00099 FileHelpers::writeFloat(os, myColor.blue()); 00100 FileHelpers::writeInt(os, myCarFollowModel->getModelID()); 00101 FileHelpers::writeString(os, myLaneChangeModel); 00102 //myCarFollowModel->saveState(os); 00103 } 00104 00105 00106 // ------------ Setter methods 00107 void 00108 MSVehicleType::setLength(const SUMOReal& length) { 00109 assert(myOriginalType != 0); 00110 if (length < 0) { 00111 myLength = myOriginalType->myLength; 00112 } else { 00113 myLength = length; 00114 } 00115 } 00116 00117 00118 void 00119 MSVehicleType::setMinGap(const SUMOReal& minGap) { 00120 assert(myOriginalType != 0); 00121 if (minGap < 0) { 00122 myMinGap = myOriginalType->myMinGap; 00123 } else { 00124 myMinGap = minGap; 00125 } 00126 } 00127 00128 00129 void 00130 MSVehicleType::setMaxSpeed(const SUMOReal& maxSpeed) { 00131 assert(myOriginalType != 0); 00132 if (maxSpeed < 0) { 00133 myMaxSpeed = myOriginalType->myMaxSpeed; 00134 } else { 00135 myMaxSpeed = maxSpeed; 00136 } 00137 } 00138 00139 00140 void 00141 MSVehicleType::setVClass(SUMOVehicleClass vclass) { 00142 myVehicleClass = vclass; 00143 } 00144 00145 00146 void 00147 MSVehicleType::setDefaultProbability(const SUMOReal& prob) { 00148 assert(myOriginalType != 0); 00149 if (prob < 0) { 00150 myDefaultProbability = myOriginalType->myDefaultProbability; 00151 } else { 00152 myDefaultProbability = prob; 00153 } 00154 } 00155 00156 00157 void 00158 MSVehicleType::setSpeedFactor(const SUMOReal& factor) { 00159 assert(myOriginalType != 0); 00160 if (factor < 0) { 00161 mySpeedFactor = myOriginalType->mySpeedFactor; 00162 } else { 00163 mySpeedFactor = factor; 00164 } 00165 } 00166 00167 00168 void 00169 MSVehicleType::setSpeedDeviation(const SUMOReal& dev) { 00170 assert(myOriginalType != 0); 00171 if (dev < 0) { 00172 mySpeedDev = myOriginalType->mySpeedDev; 00173 } else { 00174 mySpeedDev = dev; 00175 } 00176 } 00177 00178 00179 void 00180 MSVehicleType::setEmissionClass(SUMOEmissionClass eclass) { 00181 myEmissionClass = eclass; 00182 } 00183 00184 00185 void 00186 MSVehicleType::setColor(const RGBColor& color) { 00187 myColor = color; 00188 } 00189 00190 00191 void 00192 MSVehicleType::setWidth(const SUMOReal& width) { 00193 assert(myOriginalType != 0); 00194 if (width < 0) { 00195 myWidth = myOriginalType->myWidth; 00196 } else { 00197 myWidth = width; 00198 } 00199 } 00200 00201 00202 void 00203 MSVehicleType::setShape(SUMOVehicleShape shape) { 00204 myShape = shape; 00205 } 00206 00207 00208 00209 // ------------ Static methods for building vehicle types 00210 MSVehicleType* 00211 MSVehicleType::build(SUMOVTypeParameter& from) { 00212 MSVehicleType* vtype = new MSVehicleType( 00213 from.id, from.length, from.minGap, from.maxSpeed, 00214 from.defaultProbability, from.speedFactor, from.speedDev, from.vehicleClass, from.emissionClass, 00215 from.width, from.height, from.shape, from.osgFile, from.lcModel, from.color); 00216 MSCFModel* model = 0; 00217 switch (from.cfModel) { 00218 case SUMO_TAG_CF_IDM: 00219 model = new MSCFModel_IDM(vtype, 00220 from.get(SUMO_ATTR_ACCEL, DEFAULT_VEH_ACCEL), 00221 from.get(SUMO_ATTR_DECEL, DEFAULT_VEH_DECEL), 00222 from.get(SUMO_ATTR_TAU, DEFAULT_VEH_TAU), 00223 from.get(SUMO_ATTR_CF_IDM_DELTA, 4.), 00224 from.get(SUMO_ATTR_CF_IDM_STEPPING, .25)); 00225 break; 00226 case SUMO_TAG_CF_IDMM: 00227 model = new MSCFModel_IDM(vtype, 00228 from.get(SUMO_ATTR_ACCEL, DEFAULT_VEH_ACCEL), 00229 from.get(SUMO_ATTR_DECEL, DEFAULT_VEH_DECEL), 00230 from.get(SUMO_ATTR_TAU, DEFAULT_VEH_TAU), 00231 from.get(SUMO_ATTR_CF_IDMM_ADAPT_FACTOR, 1.8), 00232 from.get(SUMO_ATTR_CF_IDMM_ADAPT_TIME, 600.), 00233 from.get(SUMO_ATTR_CF_IDM_STEPPING, .25)); 00234 break; 00235 case SUMO_TAG_CF_BKERNER: 00236 model = new MSCFModel_Kerner(vtype, 00237 from.get(SUMO_ATTR_ACCEL, DEFAULT_VEH_ACCEL), 00238 from.get(SUMO_ATTR_DECEL, DEFAULT_VEH_DECEL), 00239 from.get(SUMO_ATTR_TAU, DEFAULT_VEH_TAU), 00240 from.get(SUMO_ATTR_K, .5), 00241 from.get(SUMO_ATTR_CF_KERNER_PHI, 5.)); 00242 break; 00243 case SUMO_TAG_CF_KRAUSS_ORIG1: 00244 model = new MSCFModel_KraussOrig1(vtype, 00245 from.get(SUMO_ATTR_ACCEL, DEFAULT_VEH_ACCEL), 00246 from.get(SUMO_ATTR_DECEL, DEFAULT_VEH_DECEL), 00247 from.get(SUMO_ATTR_SIGMA, DEFAULT_VEH_SIGMA), 00248 from.get(SUMO_ATTR_TAU, DEFAULT_VEH_TAU)); 00249 break; 00250 case SUMO_TAG_CF_PWAGNER2009: 00251 model = new MSCFModel_PWag2009(vtype, 00252 from.get(SUMO_ATTR_ACCEL, DEFAULT_VEH_ACCEL), 00253 from.get(SUMO_ATTR_DECEL, DEFAULT_VEH_DECEL), 00254 from.get(SUMO_ATTR_SIGMA, DEFAULT_VEH_SIGMA), 00255 from.get(SUMO_ATTR_TAU, DEFAULT_VEH_TAU), 00256 from.get(SUMO_ATTR_CF_PWAGNER2009_TAULAST, 0.3), 00257 from.get(SUMO_ATTR_CF_PWAGNER2009_APPROB, 0.5)); 00258 break; 00259 case SUMO_TAG_CF_WIEDEMANN: 00260 model = new MSCFModel_Wiedemann(vtype, 00261 from.get(SUMO_ATTR_ACCEL, DEFAULT_VEH_ACCEL), 00262 from.get(SUMO_ATTR_DECEL, DEFAULT_VEH_DECEL), 00263 from.get(SUMO_ATTR_CF_WIEDEMANN_SECURITY, 0.5), 00264 from.get(SUMO_ATTR_CF_WIEDEMANN_ESTIMATION, 0.5)); 00265 break; 00266 case SUMO_TAG_CF_KRAUSS: 00267 default: 00268 model = new MSCFModel_Krauss(vtype, 00269 from.get(SUMO_ATTR_ACCEL, DEFAULT_VEH_ACCEL), 00270 from.get(SUMO_ATTR_DECEL, DEFAULT_VEH_DECEL), 00271 from.get(SUMO_ATTR_SIGMA, DEFAULT_VEH_SIGMA), 00272 from.get(SUMO_ATTR_TAU, DEFAULT_VEH_TAU)); 00273 break; 00274 } 00275 vtype->myCarFollowModel = model; 00276 return vtype; 00277 } 00278 00279 00280 MSVehicleType* 00281 MSVehicleType::build(const std::string& id, const MSVehicleType* from) { 00282 MSVehicleType* vtype = new MSVehicleType( 00283 id, from->myLength, from->myMinGap, from->myMaxSpeed, 00284 from->myDefaultProbability, from->mySpeedFactor, from->mySpeedDev, from->myVehicleClass, from->myEmissionClass, 00285 from->myWidth, from->myHeight, from->myShape, from->myOSGFile, from->myLaneChangeModel, from->myColor); 00286 vtype->myCarFollowModel = from->myCarFollowModel->duplicate(vtype); 00287 vtype->myOriginalType = from->myOriginalType != 0 ? from->myOriginalType : from; 00288 return vtype; 00289 } 00290 00291 00292 /****************************************************************************/ 00293