SUMO - Simulation of Urban MObility

MSFrame.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Sets and checks options for microsim; inits global outputs and settings
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 <iostream>
00031 #include <iomanip>
00032 #include <fstream>
00033 #include <ctime>
00034 #include <utils/options/OptionsCont.h>
00035 #include <utils/options/Option.h>
00036 #include <utils/common/MsgHandler.h>
00037 #include <utils/common/UtilExceptions.h>
00038 #include <utils/common/ToString.h>
00039 #include <utils/iodevices/OutputDevice.h>
00040 #include <microsim/MSJunction.h>
00041 #include <microsim/MSNet.h>
00042 #include <microsim/MSGlobals.h>
00043 #include <microsim/devices/MSDevice_Vehroutes.h>
00044 #include <microsim/devices/MSDevice_Routing.h>
00045 #include <microsim/devices/MSDevice_HBEFA.h>
00046 #include <utils/common/RandHelper.h>
00047 #include "MSFrame.h"
00048 #include <utils/common/SystemFrame.h>
00049 
00050 #ifdef CHECK_MEMORY_LEAKS
00051 #include <foreign/nvwa/debug_new.h>
00052 #endif // CHECK_MEMORY_LEAKS
00053 
00054 
00055 // ===========================================================================
00056 // method definitions
00057 // ===========================================================================
00058 void
00059 MSFrame::fillOptions() {
00060     OptionsCont& oc = OptionsCont::getOptions();
00061     oc.addCallExample("-b 0 -e 1000 -n net.xml -r routes.xml");
00062     oc.addCallExample("-c munich_config.cfg");
00063     oc.addCallExample("--help");
00064 
00065     // insert options sub-topics
00066     SystemFrame::addConfigurationOptions(oc); // fill this subtopic, too
00067     oc.addOptionSubTopic("Input");
00068     oc.addOptionSubTopic("Output");
00069     oc.addOptionSubTopic("Time");
00070     oc.addOptionSubTopic("Processing");
00071     SystemFrame::addReportOptions(oc); // fill this subtopic, too
00072 
00073 
00074     // register configuration options
00075     //  register input options
00076     oc.doRegister("net-file", 'n', new Option_FileName());
00077     oc.addSynonyme("net-file", "net");
00078     oc.addDescription("net-file", "Input", "Load road network description from FILE");
00079 
00080     oc.doRegister("route-files", 'r', new Option_FileName());
00081     oc.addSynonyme("route-files", "routes");
00082     oc.addDescription("route-files", "Input", "Load routes descriptions from FILE(s)");
00083 
00084     oc.doRegister("additional-files", 'a', new Option_FileName());
00085     oc.addSynonyme("additional-files", "additional");
00086     oc.addDescription("additional-files", "Input", "Load further descriptions from FILE(s)");
00087 
00088     oc.doRegister("weight-files", 'w', new Option_FileName());
00089     oc.addSynonyme("weight-files", "weights");
00090     oc.addDescription("weight-files", "Input", "Load edge/lane weights for online rerouting from FILE");
00091     oc.doRegister("weight-attribute", 'x', new Option_String("traveltime"));
00092     oc.addSynonyme("weight-attribute", "measure", true);
00093     oc.addDescription("weight-attribute", "Input", "Name of the xml attribute which gives the edge weight");
00094 
00095 #ifdef HAVE_MESOSIM
00096     oc.doRegister("load-state", new Option_FileName());
00097     oc.addDescription("load-state", "Input", "Loads a network state from FILE");
00098     oc.doRegister("load-state.offset", new Option_String("0", "TIME"));
00099     oc.addDescription("load-state.offset", "Input", "Sets the time offset for vehicle segment exit times.");
00100 #endif
00101 
00102     //  register output options
00103     oc.doRegister("netstate-dump", new Option_FileName());
00104     oc.addSynonyme("netstate-dump", "ndump");
00105     oc.addSynonyme("netstate-dump", "netstate");
00106     oc.addDescription("netstate-dump", "Output", "Save complete network states into FILE");
00107     oc.doRegister("netstate-dump.empty-edges", new Option_Bool(false));
00108     oc.addSynonyme("netstate-dump.empty-edges", "netstate.empty-edges");
00109     oc.addSynonyme("netstate-dump.empty-edges", "dump-empty-edges", true);
00110     oc.addDescription("netstate-dump.empty-edges", "Output", "Write also empty edges completely when dumping");
00111 
00112     oc.doRegister("summary-output", new Option_FileName());
00113     oc.addSynonyme("summary-output", "summary");
00114     oc.addSynonyme("summary-output", "emissions-output", true);
00115     oc.addSynonyme("summary-output", "emissions", true);
00116     oc.addDescription("summary-output", "Output", "Save aggregated vehicle departure info into FILE");
00117 
00118     oc.doRegister("tripinfo-output", new Option_FileName());
00119     oc.addSynonyme("tripinfo-output", "tripinfo");
00120     oc.addDescription("tripinfo-output", "Output", "Save single vehicle trip info into FILE");
00121 
00122     oc.doRegister("vehroute-output", new Option_FileName());
00123     oc.addSynonyme("vehroute-output", "vehroutes");
00124     oc.addDescription("vehroute-output", "Output", "Save single vehicle route info into FILE");
00125 
00126     oc.doRegister("vehroute-output.exit-times", new Option_Bool(false));
00127     oc.addSynonyme("vehroute-output.exit-times", "vehroutes.exit-times");
00128     oc.addDescription("vehroute-output.exit-times", "Output", "Write the exit times for all edges");
00129 
00130     oc.doRegister("vehroute-output.last-route", new Option_Bool(false));
00131     oc.addSynonyme("vehroute-output.last-route", "vehroutes.last-route");
00132     oc.addDescription("vehroute-output.last-route", "Output", "Write the last route only");
00133 
00134     oc.doRegister("vehroute-output.sorted", new Option_Bool(false));
00135     oc.addSynonyme("vehroute-output.sorted", "vehroutes.sorted");
00136     oc.addDescription("vehroute-output.sorted", "Output", "Sorts the output by departure time");
00137 
00138 #ifdef HAVE_MESOSIM
00139     oc.doRegister("save-state.times", new Option_IntVector(IntVector()));
00140     oc.addDescription("save-state.times", "Output", "Use INT[] as times at which a network state written");
00141     oc.doRegister("save-state.prefix", new Option_FileName());
00142     oc.addDescription("save-state.prefix", "Output", "Prefix for network states");
00143     oc.doRegister("save-state.files", new Option_FileName());
00144     oc.addDescription("save-state.files", "Output", "Files for network states");
00145 #endif
00146 
00147     // register the simulation settings
00148     oc.doRegister("begin", 'b', new Option_String("0", "TIME"));
00149     oc.addDescription("begin", "Time", "Defines the begin time; The simulation starts at this time");
00150 
00151     oc.doRegister("end", 'e', new Option_String("-1", "TIME"));
00152     oc.addDescription("end", "Time", "Defines the end time; The simulation ends at this time");
00153 
00154 #ifdef HAVE_SUBSECOND_TIMESTEPS
00155     oc.doRegister("step-length", new Option_String("1", "TIME"));
00156     oc.addDescription("step-length", "Time", "Defines the step duration");
00157 #endif
00158 
00159 
00160     // register the processing options
00161     oc.doRegister("route-steps", 's', new Option_Integer(200));
00162     oc.addDescription("route-steps", "Processing", "Load routes for the next INT steps ahead");
00163 
00164 #ifdef HAVE_INTERNAL_LANES
00165     oc.doRegister("no-internal-links", new Option_Bool(false));
00166     oc.addDescription("no-internal-links", "Processing", "Disable (junction) internal links");
00167 #endif
00168 
00169     oc.doRegister("ignore-accidents", new Option_Bool(false));
00170     oc.addDescription("ignore-accidents", "Processing", "Do not check whether accidents occure more deeply");
00171 
00172     oc.doRegister("ignore-route-errors", new Option_Bool(false));
00173     oc.addDescription("ignore-route-errors", "Processing", "Do not check whether routes are connected");
00174 
00175     oc.doRegister("max-num-vehicles", new Option_Integer(-1));
00176     oc.addSynonyme("max-num-vehicles", "too-many-vehicles", true);
00177     oc.addDescription("max-num-vehicles", "Processing", "Quit simulation if this number of vehicles is exceeded");
00178 
00179     oc.doRegister("incremental-dua-step", new Option_Integer());
00180     oc.addDescription("incremental-dua-step", "Processing", "Perform the simulation as a step in incremental DUA");
00181     oc.doRegister("incremental-dua-base", new Option_Integer(10));
00182     oc.addDescription("incremental-dua-base", "Processing", "Base value for incremental DUA");
00183     oc.doRegister("scale", new Option_Float());
00184     oc.addDescription("scale", "Processing", "Scale demand by the given factor (0..1)");
00185 
00186     oc.doRegister("time-to-teleport", new Option_String("300", "TIME"));
00187     oc.addDescription("time-to-teleport", "Processing", "Specify how long a vehicle may wait until being teleported, defaults to 300, non-positive values disable teleporting");
00188 
00189     oc.doRegister("max-depart-delay", new Option_String("-1", "TIME"));
00190     oc.addDescription("max-depart-delay", "Processing", "How long vehicles wait for departure before being skipped, defaults to -1 which means vehicles are never skipped");
00191 
00192     oc.doRegister("sloppy-insert", new Option_Bool(false));
00193     oc.addDescription("sloppy-insert", "Processing", "Whether insertion on an edge shall not be repeated in same step once failed.");
00194 
00195     oc.doRegister("lanechange.allow-swap", new Option_Bool(false));
00196     oc.addDescription("lanechange.allow-swap", "Processing", "Whether blocking vehicles trying to change lanes may be swapped.");
00197 
00198 
00199     // devices
00200     MSDevice_Routing::insertOptions();
00201     MSDevice_HBEFA::insertOptions();
00202 
00203 
00204     // register report options
00205     oc.doRegister("no-duration-log", new Option_Bool(false));
00206     oc.addDescription("no-duration-log", "Report", "Disable performance reports for individual simulation steps");
00207 
00208     oc.doRegister("no-step-log", new Option_Bool(false));
00209     oc.addDescription("no-step-log", "Report", "Disable console output of current simulation step");
00210 
00211 
00212 #ifndef NO_TRACI
00213     //remote port 0 if not used
00214     oc.addOptionSubTopic("TraCI Server");
00215     oc.doRegister("remote-port", new Option_Integer(0));
00216     oc.addDescription("remote-port", "TraCI Server", "Enables TraCI Server if set");
00217 #ifdef HAVE_PYTHON
00218     oc.doRegister("python-script", new Option_String());
00219     oc.addDescription("python-script", "TraCI Server", "Runs TraCI script with embedded python");
00220 #endif
00221 #endif
00222     //
00223 #ifdef HAVE_MESOSIM
00224     oc.addOptionSubTopic("Mesoscopic");
00225     oc.doRegister("mesosim", new Option_Bool(false));
00226     oc.addDescription("mesosim", "Mesoscopic", "Enables mesoscopic simulation");
00227     oc.doRegister("meso-edgelength", new Option_Float(98.0f));
00228     oc.addDescription("meso-edgelength", "Mesoscopic", "Length of an edge segment in mesoscopic simulation");
00229     oc.doRegister("meso-tauff", new Option_String("1.4", "TIME"));
00230     oc.addDescription("meso-tauff", "Mesoscopic", "Factor for calculating the free-free headway time");
00231     oc.doRegister("meso-taufj", new Option_String("1.4", "TIME"));
00232     oc.addDescription("meso-taufj", "Mesoscopic", "Factor for calculating the free-jam headway time");
00233     oc.doRegister("meso-taujf", new Option_String("2", "TIME"));
00234     oc.addDescription("meso-taujf", "Mesoscopic", "Factor for calculating the jam-free headway time");
00235     oc.doRegister("meso-taujj", new Option_String("2", "TIME"));
00236     oc.addDescription("meso-taujj", "Mesoscopic", "Factor for calculating the jam-jam headway time");
00237     oc.doRegister("meso-jam-threshold", new Option_Float(0.29f));
00238     oc.addDescription("meso-jam-threshold", "Mesoscopic", "Minimum percentage of occupied space to consider a segment jammed");
00239     oc.doRegister("meso-multi-queue", new Option_Bool(false));
00240     oc.addDescription("meso-multi-queue", "Mesoscopic", "Enable multiple queues at edge ends");
00241     oc.doRegister("meso-junction-control", new Option_Bool(false));
00242     oc.addDescription("meso-junction-control", "Mesoscopic", "Enable mesoscopic traffic light and priority junction handling");
00243     oc.doRegister("meso-recheck", new Option_String("0", "TIME"));
00244     oc.addDescription("meso-recheck", "Mesoscopic", "Time interval for rechecking insertion into the next segment after failure");
00245 #endif
00246 
00247     // add rand options
00248     RandHelper::insertRandOptions();
00249 
00250     oc.addOptionSubTopic("GUI Only");
00251     oc.doRegister("gui-settings-file", new Option_FileName());
00252     oc.addDescription("gui-settings-file", "GUI Only", "Load visualisation settings from FILE");
00253 
00254 }
00255 
00256 
00257 void
00258 MSFrame::buildStreams() throw(IOError) {
00259     // standard outputs
00260     OutputDevice::createDeviceByOption("netstate-dump", "sumo-netstate");
00261     OutputDevice::createDeviceByOption("summary-output", "summary");
00262     OutputDevice::createDeviceByOption("tripinfo-output", "tripinfos");
00263     MSDevice_Vehroutes::init();
00264 }
00265 
00266 
00267 bool
00268 MSFrame::checkOptions() {
00269     OptionsCont& oc = OptionsCont::getOptions();
00270     bool ok = true;
00271     if (!oc.isSet("net-file")) {
00272         WRITE_ERROR("No network file (-n) specified.");
00273         ok = false;
00274     }
00275     if (oc.isSet("incremental-dua-step") && oc.isSet("incremental-dua-base")) {
00276         WRITE_WARNING("The options 'incremental-dua-step' and 'incremental-dua-base' are deprecated, use 'scale' instead.");
00277         if (oc.getInt("incremental-dua-step") > oc.getInt("incremental-dua-base")) {
00278             WRITE_ERROR("Invalid dua step.");
00279             ok = false;
00280         }
00281     }
00282     if (!oc.isDefault("scale")) {
00283         if (oc.getFloat("scale") < 0. || oc.getFloat("scale") > 1.) {
00284             WRITE_ERROR("Invalid scaling factor.");
00285             ok = false;
00286         }
00287     }
00288     if (oc.getBool("vehroute-output.exit-times") && !oc.isSet("vehroute-output")) {
00289         WRITE_ERROR("A vehroute-output file is needed for exit times.");
00290         ok = false;
00291     }
00292     return ok;
00293 }
00294 
00295 
00296 void
00297 MSFrame::setMSGlobals(OptionsCont& oc) {
00298     // pre-initialise the network
00299     // set whether empty edges shall be printed on dump
00300     MSGlobals::gOmitEmptyEdgesOnDump = !oc.getBool("netstate-dump.empty-edges");
00301 #ifdef HAVE_INTERNAL_LANES
00302     // set whether internal lanes shall be used
00303     MSGlobals::gUsingInternalLanes = !oc.getBool("no-internal-links");
00304 #else
00305     MSGlobals::gUsingInternalLanes = false;
00306 #endif
00307     // set the grid lock time
00308     MSGlobals::gTimeToGridlock = string2time(oc.getString("time-to-teleport"))<0 ? 0 : string2time(oc.getString("time-to-teleport"));
00309     MSGlobals::gCheck4Accidents = !oc.getBool("ignore-accidents");
00310     MSGlobals::gCheckRoutes = !oc.getBool("ignore-route-errors");
00311 #ifdef HAVE_MESOSIM
00312     MSGlobals::gStateLoaded = oc.isSet("load-state");
00313     MSGlobals::gUseMesoSim = oc.getBool("mesosim");
00314 #endif
00315     for (unsigned int i = 0; i < 1000; i++) {
00316         unsigned int num = i;
00317         unsigned int den = 1000;
00318         while (num % 2 == 0 && den % 2 == 0) {
00319             num /= 2;
00320             den /= 2;
00321         }
00322         while (num % 5 == 0 && den % 5 == 0) {
00323             num /= 5;
00324             den /= 5;
00325         }
00326         MSGlobals::gFractions[SUMOReal(i)/1000.] = std::make_pair(num, den);
00327     }
00328 
00329 #ifdef HAVE_SUBSECOND_TIMESTEPS
00330     DELTA_T = string2time(oc.getString("step-length"));
00331 #endif
00332 }
00333 
00334 
00335 
00336 /****************************************************************************/
00337 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines