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