MSVehicleType.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // The car-following model and parameter
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright 2001-2010 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 "MSVehicleType.h"
00031 #include "MSNet.h"
00032 #include "cfmodels/MSCFModel_IDM.h"
00033 #include "cfmodels/MSCFModel_Kerner.h"
00034 #include "cfmodels/MSCFModel_Krauss.h"
00035 #include "cfmodels/MSCFModel_KraussOrig1.h"
00036 #include "cfmodels/MSCFModel_PWag2009.h"
00037 #include <cassert>
00038 #include <utils/iodevices/BinaryInputDevice.h>
00039 #include <utils/common/FileHelpers.h>
00040 #include <utils/common/RandHelper.h>
00041 #include <utils/common/SUMOVTypeParameter.h>
00042 
00043 #ifdef CHECK_MEMORY_LEAKS
00044 #include <foreign/nvwa/debug_new.h>
00045 #endif // CHECK_MEMORY_LEAKS
00046 
00047 
00048 // ===========================================================================
00049 // method definitions
00050 // ===========================================================================
00051 MSVehicleType::MSVehicleType(const std::string &id, SUMOReal length,
00052                              SUMOReal maxSpeed, SUMOReal prob,
00053                              SUMOReal speedFactor, SUMOReal speedDev,
00054                              SUMOVehicleClass vclass,
00055                              SUMOEmissionClass emissionClass,
00056                              SUMOVehicleShape shape,
00057                              SUMOReal guiWidth, SUMOReal guiOffset,
00058                              int cfModel, const std::string &lcModel,
00059                              const RGBColor &c) throw()
00060         : myID(id), myLength(length), myMaxSpeed(maxSpeed),
00061         myDefaultProbability(prob), mySpeedFactor(speedFactor),
00062         mySpeedDev(speedDev), myVehicleClass(vclass),
00063         myLaneChangeModel(lcModel),
00064         myEmissionClass(emissionClass), myColor(c),
00065         myWidth(guiWidth), myOffset(guiOffset), myShape(shape) {
00066     assert(myLength > 0);
00067     assert(getMaxSpeed() > 0);
00068 }
00069 
00070 
00071 MSVehicleType::~MSVehicleType() throw() {}
00072 
00073 
00074 void
00075 MSVehicleType::saveState(std::ostream &os) {
00076     FileHelpers::writeString(os, myID);
00077     FileHelpers::writeFloat(os, myLength);
00078     FileHelpers::writeFloat(os, getMaxSpeed());
00079     FileHelpers::writeInt(os, (int) myVehicleClass);
00080     FileHelpers::writeInt(os, (int) myEmissionClass);
00081     FileHelpers::writeInt(os, (int) myShape);
00082     FileHelpers::writeFloat(os, myWidth);
00083     FileHelpers::writeFloat(os, myOffset);
00084     FileHelpers::writeFloat(os, myDefaultProbability);
00085     FileHelpers::writeFloat(os, mySpeedFactor);
00086     FileHelpers::writeFloat(os, mySpeedDev);
00087     FileHelpers::writeFloat(os, myColor.red());
00088     FileHelpers::writeFloat(os, myColor.green());
00089     FileHelpers::writeFloat(os, myColor.blue());
00090     FileHelpers::writeInt(os, myCarFollowModel->getModelID());
00091     FileHelpers::writeString(os, myLaneChangeModel);
00092     //myCarFollowModel->saveState(os);
00093 }
00094 
00095 
00096 SUMOReal
00097 MSVehicleType::get(const std::map<std::string, SUMOReal> &from, const std::string &name, SUMOReal defaultValue) throw() {
00098     std::map<std::string, SUMOReal>::const_iterator i = from.find(name);
00099     if (i==from.end()) {
00100         return defaultValue;
00101     }
00102     return (*i).second;
00103 }
00104 
00105 
00106 MSVehicleType *
00107 MSVehicleType::build(SUMOVTypeParameter &from) throw(ProcessError) {
00108     MSVehicleType *vtype = new MSVehicleType(
00109         from.id, from.length, from.maxSpeed,
00110         from.defaultProbability, from.speedFactor, from.speedDev, from.vehicleClass, from.emissionClass,
00111         from.shape, from.width, from.offset, from.cfModel, from.lcModel, from.color);
00112     MSCFModel *model = 0;
00113     switch (from.cfModel) {
00114     case SUMO_TAG_CF_IDM:
00115         model = new MSCFModel_IDM(vtype,
00116                                   get(from.cfParameter, "accel", DEFAULT_VEH_ACCEL),
00117                                   get(from.cfParameter, "decel", DEFAULT_VEH_DECEL),
00118                                   get(from.cfParameter, "timeHeadWay", 1.5),
00119                                   get(from.cfParameter, "minGap", 5.),
00120                                   get(from.cfParameter, "tau", DEFAULT_VEH_TAU));
00121         break;
00122     case SUMO_TAG_CF_BKERNER:
00123         model = new MSCFModel_Kerner(vtype,
00124                                      get(from.cfParameter, "accel", DEFAULT_VEH_ACCEL),
00125                                      get(from.cfParameter, "decel", DEFAULT_VEH_DECEL),
00126                                      get(from.cfParameter, "tau", DEFAULT_VEH_TAU),
00127                                      get(from.cfParameter, "k", .5),
00128                                      get(from.cfParameter, "phi", 5.));
00129         break;
00130     case SUMO_TAG_CF_KRAUSS_ORIG1:
00131         model = new MSCFModel_KraussOrig1(vtype,
00132                                           get(from.cfParameter, "accel", DEFAULT_VEH_ACCEL),
00133                                           get(from.cfParameter, "decel", DEFAULT_VEH_DECEL),
00134                                           get(from.cfParameter, "sigma", DEFAULT_VEH_SIGMA),
00135                                           get(from.cfParameter, "tau", DEFAULT_VEH_TAU));
00136         break;
00137     case SUMO_TAG_CF_PWAGNER2009:
00138         model = new MSCFModel_PWag2009(vtype,
00139                                        get(from.cfParameter, "accel", DEFAULT_VEH_ACCEL),
00140                                        get(from.cfParameter, "decel", DEFAULT_VEH_DECEL),
00141                                        get(from.cfParameter, "sigma", DEFAULT_VEH_SIGMA),
00142                                        get(from.cfParameter, "tau", DEFAULT_VEH_TAU));
00143         break;
00144     case SUMO_TAG_CF_KRAUSS:
00145     default:
00146         model = new MSCFModel_Krauss(vtype,
00147                                      get(from.cfParameter, "accel", DEFAULT_VEH_ACCEL),
00148                                      get(from.cfParameter, "decel", DEFAULT_VEH_DECEL),
00149                                      get(from.cfParameter, "sigma", DEFAULT_VEH_SIGMA),
00150                                      get(from.cfParameter, "tau", DEFAULT_VEH_TAU));
00151         break;
00152     }
00153     vtype->myCarFollowModel = model;
00154     return vtype;
00155 }
00156 
00157 
00158 /****************************************************************************/
00159 

Generated on Wed May 5 00:06:32 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6