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