SUMO - Simulation of Urban MObility

SUMOVehicleParameter.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Structure representing possible vehicle 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 "SUMOVehicleParameter.h"
00031 #include <utils/common/ToString.h>
00032 #include <utils/common/TplConvert.h>
00033 #include <utils/common/MsgHandler.h>
00034 #include <utils/iodevices/OutputDevice.h>
00035 #include <utils/options/OptionsCont.h>
00036 
00037 #ifdef CHECK_MEMORY_LEAKS
00038 #include <foreign/nvwa/debug_new.h>
00039 #endif // CHECK_MEMORY_LEAKS
00040 
00041 
00042 // ===========================================================================
00043 // member method definitions
00044 // ===========================================================================
00045 SUMOVehicleParameter::SUMOVehicleParameter() throw()
00046     : vtypeid(DEFAULT_VTYPE_ID), color(RGBColor::DEFAULT_COLOR),
00047       depart(-1), departProcedure(DEPART_GIVEN),
00048       departLane(0), departLaneProcedure(DEPART_LANE_DEFAULT),
00049       departPos(0), departPosProcedure(DEPART_POS_DEFAULT),
00050       departSpeed(-1), departSpeedProcedure(DEPART_SPEED_DEFAULT),
00051       arrivalLane(0), arrivalLaneProcedure(ARRIVAL_LANE_DEFAULT),
00052       arrivalPos(0), arrivalPosProcedure(ARRIVAL_POS_DEFAULT),
00053       arrivalSpeed(-1), arrivalSpeedProcedure(ARRIVAL_SPEED_DEFAULT),
00054       repetitionNumber(-1), repetitionsDone(-1), repetitionOffset(-1),
00055       line(), fromTaz(), toTaz(), setParameter(0) {
00056 }
00057 
00058 
00059 bool
00060 SUMOVehicleParameter::defaultOptionOverrides(const OptionsCont& oc, const std::string& optionName) const throw() {
00061     return oc.isSet(optionName) && oc.getBool("defaults-override");
00062 }
00063 
00064 
00065 void
00066 SUMOVehicleParameter::writeAs(const std::string& xmlElem, OutputDevice& dev,
00067                               const OptionsCont& oc) const throw(IOError) {
00068     dev.openTag(xmlElem) << " id=\"" << id << "\"";
00069     if (wasSet(VEHPARS_VTYPE_SET)) {
00070         dev << " type=\"" << vtypeid << "\"";
00071     }
00072     dev << " depart=\"" << time2string(depart) << "\"";
00073 
00074     // optional parameter
00075     //  departlane
00076     if (wasSet(VEHPARS_DEPARTLANE_SET) && !defaultOptionOverrides(oc, "departlane")) {
00077         std::string val;
00078         switch (departLaneProcedure) {
00079         case DEPART_LANE_GIVEN:
00080             val = toString(departLane);
00081             break;
00082         case DEPART_LANE_RANDOM:
00083             val = "random";
00084             break;
00085         case DEPART_LANE_FREE:
00086             val = "free";
00087             break;
00088         case DEPART_LANE_ALLOWED_FREE:
00089             val = "allowed";
00090             break;
00091         case DEPART_LANE_BEST_FREE:
00092             val = "best";
00093             break;
00094         case DEPART_LANE_DEFAULT:
00095         default:
00096             break;
00097         }
00098         dev << " departLane=\"" << val << "\"";
00099     } else if (oc.isSet("departlane")) {
00100         dev << " departLane=\"" << oc.getString("departlane") << "\"";
00101     }
00102     //  departpos
00103     if (wasSet(VEHPARS_DEPARTPOS_SET) && !defaultOptionOverrides(oc, "departpos")) {
00104         std::string val;
00105         switch (departPosProcedure) {
00106         case DEPART_POS_GIVEN:
00107             val = toString(departPos);
00108             break;
00109         case DEPART_POS_RANDOM:
00110             val = "random";
00111             break;
00112         case DEPART_POS_RANDOM_FREE:
00113             val = "random_free";
00114             break;
00115         case DEPART_POS_FREE:
00116             val = "free";
00117             break;
00118         case DEPART_POS_PWAG_SIMPLE:
00119             val = "pwagSimple";
00120             break;
00121         case DEPART_POS_PWAG_GENERIC:
00122             val = "pwagGeneric";
00123             break;
00124         case DEPART_POS_MAX_SPEED_GAP:
00125             val = "maxSpeedGap";
00126             break;
00127         case DEPART_POS_BASE:
00128             val = "base";
00129             break;
00130         case DEPART_POS_DEFAULT:
00131         default:
00132             break;
00133         }
00134         dev << " departPos=\"" << val << "\"";
00135     } else if (oc.isSet("departpos")) {
00136         dev << " departPos=\"" << oc.getString("departpos") << "\"";
00137     }
00138     //  departspeed
00139     if (wasSet(VEHPARS_DEPARTSPEED_SET) && !defaultOptionOverrides(oc, "departspeed")) {
00140         std::string val;
00141         switch (departSpeedProcedure) {
00142         case DEPART_SPEED_GIVEN:
00143             val = toString(departSpeed);
00144             break;
00145         case DEPART_SPEED_RANDOM:
00146             val = "random";
00147             break;
00148         case DEPART_SPEED_MAX:
00149             val = "max";
00150             break;
00151         case DEPART_SPEED_DEFAULT:
00152         default:
00153             break;
00154         }
00155         dev << " departSpeed=\"" << val << "\"";
00156     } else if (oc.isSet("departspeed")) {
00157         dev << " departSpeed=\"" << oc.getString("departspeed") << "\"";
00158     }
00159 
00160     //  arrivallane
00161     if (wasSet(VEHPARS_ARRIVALLANE_SET) && !defaultOptionOverrides(oc, "arrivallane")) {
00162         std::string val;
00163         switch (arrivalLaneProcedure) {
00164         case ARRIVAL_LANE_GIVEN:
00165             val = toString(arrivalLane);
00166             break;
00167         case ARRIVAL_LANE_CURRENT:
00168             val = "current";
00169             break;
00170         case ARRIVAL_LANE_DEFAULT:
00171         default:
00172             break;
00173         }
00174         dev << " arrivalLane=\"" << val << "\"";
00175     } else if (oc.isSet("arrivallane")) {
00176         dev << " arrivalLane=\"" << oc.getString("arrivallane") << "\"";
00177     }
00178     //  arrivalpos
00179     if (wasSet(VEHPARS_ARRIVALPOS_SET) && !defaultOptionOverrides(oc, "arrivalpos")) {
00180         std::string val;
00181         switch (arrivalPosProcedure) {
00182         case ARRIVAL_POS_GIVEN:
00183             val = toString(arrivalPos);
00184             break;
00185         case ARRIVAL_POS_RANDOM:
00186             val = "random";
00187             break;
00188         case ARRIVAL_POS_MAX:
00189             val = "max";
00190             break;
00191         case ARRIVAL_POS_DEFAULT:
00192         default:
00193             break;
00194         }
00195         dev << " arrivalPos=\"" << val << "\"";
00196     } else if (oc.isSet("arrivalpos")) {
00197         dev << " arrivalPos=\"" << oc.getString("arrivalpos") << "\"";
00198     }
00199     //  arrivalspeed
00200     if (wasSet(VEHPARS_ARRIVALSPEED_SET) && !defaultOptionOverrides(oc, "arrivalspeed")) {
00201         std::string val;
00202         switch (arrivalSpeedProcedure) {
00203         case ARRIVAL_SPEED_GIVEN:
00204             val = toString(arrivalSpeed);
00205             break;
00206         case ARRIVAL_SPEED_CURRENT:
00207             val = "current";
00208             break;
00209         case ARRIVAL_SPEED_DEFAULT:
00210         default:
00211             break;
00212         }
00213         dev << " arrivalSpeed=\"" << val << "\"";
00214     } else if (oc.isSet("arrivalspeed")) {
00215         dev << " arrivalSpeed=\"" << oc.getString("arrivalspeed") << "\"";
00216     }
00217 
00218     // color
00219     if (wasSet(VEHPARS_COLOR_SET)) {
00220         dev << " color=\"" << color << "\"";
00221     }
00222     // repetition values
00223     if (wasSet(VEHPARS_PERIODNUM_SET)) {
00224         dev << " repno=\"" << repetitionNumber << "\"";
00225     }
00226     if (wasSet(VEHPARS_PERIODFREQ_SET)) {
00227 #ifdef HAVE_SUBSECOND_TIMESTEPS
00228         dev << " period=\"" << time2string(repetitionOffset) << "\"";
00229 #else
00230         dev << " period=\"" << repetitionOffset << "\"";
00231 #endif
00232     }
00233     if (wasSet(VEHPARS_LINE_SET)) {
00234         dev << " line=\"" << line << "\"";
00235     }
00236     if (wasSet(VEHPARS_TAZ_SET)) {
00237         dev << " fromTaz=\"" << fromTaz << "\" toTaz=\"" << toTaz << "\"";
00238     }
00239     dev << ">\n";
00240 }
00241 
00242 
00243 bool
00244 SUMOVehicleParameter::departlaneValidate(const std::string& val) throw() {
00245     if (val=="random"||val=="free"||val=="departlane"||val=="allowed"||val=="best") {
00246         return true;
00247     }
00248     try {
00249         TplConvert<char>::_2int(val.c_str());
00250         return true;
00251     } catch (NumberFormatException&) {
00252     } catch (EmptyData&) {
00253     }
00254     WRITE_ERROR("Invalid departlane definition;\n must be one of (\"departlane\", \"random\", \"free\", \"allowed\", \"best\", or an int>0)");
00255     return false;
00256 }
00257 
00258 
00259 bool
00260 SUMOVehicleParameter::departposValidate(const std::string& val) throw() {
00261     if (val=="random"||val=="free"||val=="random_free"||val=="base"||val=="pwagSimple"||val=="pwagGeneric"||val=="maxSpeedGap") {
00262         return true;
00263     }
00264     try {
00265         TplConvert<char>::_2SUMOReal(val.c_str());
00266         return true;
00267     } catch (NumberFormatException&) {
00268     } catch (EmptyData&) {
00269     }
00270     WRITE_ERROR("Invalid departpos definition;\n must be one of (\"random\", \"random_free\", \"free\", \"base\", \"pwagSimple\", \"pwagGeneric\", \"maxSpeedGap\", or a float)");
00271     return false;
00272 }
00273 
00274 
00275 bool
00276 SUMOVehicleParameter::departspeedValidate(const std::string& val) throw() {
00277     if (val=="random"||val=="max") {
00278         return true;
00279     }
00280     try {
00281         TplConvert<char>::_2SUMOReal(val.c_str());
00282         return true;
00283     } catch (NumberFormatException&) {
00284     } catch (EmptyData&) {
00285     }
00286     WRITE_ERROR("Invalid departspeed definition;\n must be one of (\"random\", \"max\", or a float>0)");
00287     return false;
00288 }
00289 
00290 
00291 bool
00292 SUMOVehicleParameter::arrivallaneValidate(const std::string& val) throw() {
00293     if (val=="current") {
00294         return true;
00295     }
00296     try {
00297         TplConvert<char>::_2int(val.c_str());
00298         return true;
00299     } catch (NumberFormatException&) {
00300     } catch (EmptyData&) {
00301     }
00302     WRITE_ERROR("Invalid arrivallane definition;\n must be one of (\"current\", or int>0)");
00303     return false;
00304 }
00305 
00306 
00307 bool
00308 SUMOVehicleParameter::arrivalposValidate(const std::string& val) throw() {
00309     if (val=="random"||val=="max") {
00310         return true;
00311     }
00312     try {
00313         TplConvert<char>::_2SUMOReal(val.c_str());
00314         return true;
00315     } catch (NumberFormatException&) {
00316     } catch (EmptyData&) {
00317     }
00318     WRITE_ERROR("Invalid arrivalpos definition;\n must be one of (\"random\", \"max\", or a float)");
00319     return false;
00320 }
00321 
00322 
00323 bool
00324 SUMOVehicleParameter::arrivalspeedValidate(const std::string& val) throw() {
00325     if (val=="current") {
00326         return true;
00327     }
00328     try {
00329         TplConvert<char>::_2SUMOReal(val.c_str());
00330         return true;
00331     } catch (NumberFormatException&) {
00332     } catch (EmptyData&) {
00333     }
00334     WRITE_ERROR("Invalid arrivalspeed definition;\n must be one of (\"current\", or a float>0)");
00335     return false;
00336 }
00337 
00338 
00339 /****************************************************************************/
00340 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines