SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSFrame.cpp
Go to the documentation of this file.
1 /****************************************************************************/
12 // Sets and checks options for microsim; inits global outputs and settings
13 /****************************************************************************/
14 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
15 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
16 /****************************************************************************/
17 //
18 // This file is part of SUMO.
19 // SUMO is free software: you can redistribute it and/or modify
20 // it under the terms of the GNU General Public License as published by
21 // the Free Software Foundation, either version 3 of the License, or
22 // (at your option) any later version.
23 //
24 /****************************************************************************/
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include <iostream>
37 #include <iomanip>
38 #include <fstream>
39 #include <ctime>
41 #include <utils/options/Option.h>
44 #include <utils/common/ToString.h>
46 #include <microsim/MSJunction.h>
47 #include <microsim/MSNet.h>
48 #include <microsim/MSGlobals.h>
53 #include "MSFrame.h"
55 
56 #ifdef CHECK_MEMORY_LEAKS
57 #include <foreign/nvwa/debug_new.h>
58 #endif // CHECK_MEMORY_LEAKS
59 
60 
61 // ===========================================================================
62 // method definitions
63 // ===========================================================================
64 void
67  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");
68  oc.addCallExample("-c munich_config.cfg", "start with a configuration file");
69  oc.addCallExample("--help", "print help");
70 
71  // insert options sub-topics
72  SystemFrame::addConfigurationOptions(oc); // fill this subtopic, too
73  oc.addOptionSubTopic("Input");
74  oc.addOptionSubTopic("Output");
75  oc.addOptionSubTopic("Time");
76  oc.addOptionSubTopic("Processing");
77  SystemFrame::addReportOptions(oc); // fill this subtopic, too
78 
79 
80  // register configuration options
81  // register input options
82  oc.doRegister("net-file", 'n', new Option_FileName());
83  oc.addSynonyme("net-file", "net");
84  oc.addDescription("net-file", "Input", "Load road network description from FILE");
85 
86  oc.doRegister("route-files", 'r', new Option_FileName());
87  oc.addSynonyme("route-files", "routes");
88  oc.addDescription("route-files", "Input", "Load routes descriptions from FILE(s)");
89 
90  oc.doRegister("additional-files", 'a', new Option_FileName());
91  oc.addSynonyme("additional-files", "additional");
92  oc.addDescription("additional-files", "Input", "Load further descriptions from FILE(s)");
93 
94  oc.doRegister("weight-files", 'w', new Option_FileName());
95  oc.addSynonyme("weight-files", "weights");
96  oc.addDescription("weight-files", "Input", "Load edge/lane weights for online rerouting from FILE");
97  oc.doRegister("weight-attribute", 'x', new Option_String("traveltime"));
98  oc.addSynonyme("weight-attribute", "measure", true);
99  oc.addDescription("weight-attribute", "Input", "Name of the xml attribute which gives the edge weight");
100 
101 #ifdef HAVE_MESOSIM
102  oc.doRegister("load-state", new Option_FileName());
103  oc.addDescription("load-state", "Input", "Loads a network state from FILE");
104  oc.doRegister("load-state.offset", new Option_String("0", "TIME"));
105  oc.addDescription("load-state.offset", "Input", "Sets the time offset for vehicle segment exit times.");
106 #endif
107 
108  // register output options
109  oc.doRegister("netstate-dump", new Option_FileName());
110  oc.addSynonyme("netstate-dump", "ndump");
111  oc.addSynonyme("netstate-dump", "netstate");
112  oc.addDescription("netstate-dump", "Output", "Save complete network states into FILE");
113  oc.doRegister("netstate-dump.empty-edges", new Option_Bool(false));
114  oc.addSynonyme("netstate-dump.empty-edges", "netstate.empty-edges");
115  oc.addSynonyme("netstate-dump.empty-edges", "dump-empty-edges", true);
116  oc.addDescription("netstate-dump.empty-edges", "Output", "Write also empty edges completely when dumping");
117 
118  oc.doRegister("summary-output", new Option_FileName());
119  oc.addSynonyme("summary-output", "summary");
120  oc.addSynonyme("summary-output", "emissions-output", true);
121  oc.addSynonyme("summary-output", "emissions", true);
122  oc.addDescription("summary-output", "Output", "Save aggregated vehicle departure info into FILE");
123 
124  oc.doRegister("tripinfo-output", new Option_FileName());
125  oc.addSynonyme("tripinfo-output", "tripinfo");
126  oc.addDescription("tripinfo-output", "Output", "Save single vehicle trip info into FILE");
127 
128  oc.doRegister("vehroute-output", new Option_FileName());
129  oc.addSynonyme("vehroute-output", "vehroutes");
130  oc.addDescription("vehroute-output", "Output", "Save single vehicle route info into FILE");
131 
132  oc.doRegister("vehroute-output.exit-times", new Option_Bool(false));
133  oc.addSynonyme("vehroute-output.exit-times", "vehroutes.exit-times");
134  oc.addDescription("vehroute-output.exit-times", "Output", "Write the exit times for all edges");
135 
136  oc.doRegister("vehroute-output.last-route", new Option_Bool(false));
137  oc.addSynonyme("vehroute-output.last-route", "vehroutes.last-route");
138  oc.addDescription("vehroute-output.last-route", "Output", "Write the last route only");
139 
140  oc.doRegister("vehroute-output.sorted", new Option_Bool(false));
141  oc.addSynonyme("vehroute-output.sorted", "vehroutes.sorted");
142  oc.addDescription("vehroute-output.sorted", "Output", "Sorts the output by departure time");
143 
144 #ifdef HAVE_MESOSIM
145  oc.doRegister("save-state.times", new Option_IntVector(IntVector()));
146  oc.addDescription("save-state.times", "Output", "Use INT[] as times at which a network state written");
147  oc.doRegister("save-state.prefix", new Option_FileName());
148  oc.addDescription("save-state.prefix", "Output", "Prefix for network states");
149  oc.doRegister("save-state.files", new Option_FileName());
150  oc.addDescription("save-state.files", "Output", "Files for network states");
151 #endif
152 
153  // register the simulation settings
154  oc.doRegister("begin", 'b', new Option_String("0", "TIME"));
155  oc.addDescription("begin", "Time", "Defines the begin time; The simulation starts at this time");
156 
157  oc.doRegister("end", 'e', new Option_String("-1", "TIME"));
158  oc.addDescription("end", "Time", "Defines the end time; The simulation ends at this time");
159 
160 #ifdef HAVE_SUBSECOND_TIMESTEPS
161  oc.doRegister("step-length", new Option_String("1", "TIME"));
162  oc.addDescription("step-length", "Time", "Defines the step duration");
163 #endif
164 
165 
166  // register the processing options
167  oc.doRegister("route-steps", 's', new Option_String("200", "TIME"));
168  oc.addDescription("route-steps", "Processing", "Load routes for the next number of seconds ahead");
169 
170 #ifdef HAVE_INTERNAL_LANES
171  oc.doRegister("no-internal-links", new Option_Bool(false));
172  oc.addDescription("no-internal-links", "Processing", "Disable (junction) internal links");
173 #endif
174 
175  oc.doRegister("ignore-accidents", new Option_Bool(false));
176  oc.addDescription("ignore-accidents", "Processing", "Do not check whether accidents occure more deeply");
177 
178  oc.doRegister("ignore-route-errors", new Option_Bool(false));
179  oc.addDescription("ignore-route-errors", "Processing", "Do not check whether routes are connected");
180 
181  oc.doRegister("max-num-vehicles", new Option_Integer(-1));
182  oc.addSynonyme("max-num-vehicles", "too-many-vehicles", true);
183  oc.addDescription("max-num-vehicles", "Processing", "Quit simulation if this number of vehicles is exceeded");
184 
185  oc.doRegister("incremental-dua-step", new Option_Integer());
186  oc.addDescription("incremental-dua-step", "Processing", "Perform the simulation as a step in incremental DUA");
187  oc.doRegister("incremental-dua-base", new Option_Integer(10));
188  oc.addDescription("incremental-dua-base", "Processing", "Base value for incremental DUA");
189  oc.doRegister("scale", new Option_Float());
190  oc.addDescription("scale", "Processing", "Scale demand by the given factor (0..1)");
191 
192  oc.doRegister("time-to-teleport", new Option_String("300", "TIME"));
193  oc.addDescription("time-to-teleport", "Processing", "Specify how long a vehicle may wait until being teleported, defaults to 300, non-positive values disable teleporting");
194 
195  oc.doRegister("max-depart-delay", new Option_String("-1", "TIME"));
196  oc.addDescription("max-depart-delay", "Processing", "How long vehicles wait for departure before being skipped, defaults to -1 which means vehicles are never skipped");
197 
198  oc.doRegister("sloppy-insert", new Option_Bool(false));
199  oc.addDescription("sloppy-insert", "Processing", "Whether insertion on an edge shall not be repeated in same step once failed.");
200 
201  oc.doRegister("lanechange.allow-swap", new Option_Bool(false));
202  oc.addDescription("lanechange.allow-swap", "Processing", "Whether blocking vehicles trying to change lanes may be swapped.");
203 
204 
205  // devices
208 
209 
210  // register report options
211  oc.doRegister("no-duration-log", new Option_Bool(false));
212  oc.addDescription("no-duration-log", "Report", "Disable performance reports for individual simulation steps");
213 
214  oc.doRegister("no-step-log", new Option_Bool(false));
215  oc.addDescription("no-step-log", "Report", "Disable console output of current simulation step");
216 
217 
218 #ifndef NO_TRACI
219  //remote port 0 if not used
220  oc.addOptionSubTopic("TraCI Server");
221  oc.doRegister("remote-port", new Option_Integer(0));
222  oc.addDescription("remote-port", "TraCI Server", "Enables TraCI Server if set");
223 #ifdef HAVE_PYTHON
224  oc.doRegister("python-script", new Option_String());
225  oc.addDescription("python-script", "TraCI Server", "Runs TraCI script with embedded python");
226 #endif
227 #endif
228  //
229 #ifdef HAVE_MESOSIM
230  oc.addOptionSubTopic("Mesoscopic");
231  oc.doRegister("mesosim", new Option_Bool(false));
232  oc.addDescription("mesosim", "Mesoscopic", "Enables mesoscopic simulation");
233  oc.doRegister("meso-edgelength", new Option_Float(98.0f));
234  oc.addDescription("meso-edgelength", "Mesoscopic", "Length of an edge segment in mesoscopic simulation");
235  oc.doRegister("meso-tauff", new Option_String("1.4", "TIME"));
236  oc.addDescription("meso-tauff", "Mesoscopic", "Factor for calculating the free-free headway time");
237  oc.doRegister("meso-taufj", new Option_String("1.4", "TIME"));
238  oc.addDescription("meso-taufj", "Mesoscopic", "Factor for calculating the free-jam headway time");
239  oc.doRegister("meso-taujf", new Option_String("2", "TIME"));
240  oc.addDescription("meso-taujf", "Mesoscopic", "Factor for calculating the jam-free headway time");
241  oc.doRegister("meso-taujj", new Option_String("2", "TIME"));
242  oc.addDescription("meso-taujj", "Mesoscopic", "Factor for calculating the jam-jam headway time");
243  oc.doRegister("meso-jam-threshold", new Option_Float(0.29f));
244  oc.addDescription("meso-jam-threshold", "Mesoscopic", "Minimum percentage of occupied space to consider a segment jammed");
245  oc.doRegister("meso-multi-queue", new Option_Bool(false));
246  oc.addDescription("meso-multi-queue", "Mesoscopic", "Enable multiple queues at edge ends");
247  oc.doRegister("meso-junction-control", new Option_Bool(false));
248  oc.addDescription("meso-junction-control", "Mesoscopic", "Enable mesoscopic traffic light and priority junction handling");
249  oc.doRegister("meso-recheck", new Option_String("0", "TIME"));
250  oc.addDescription("meso-recheck", "Mesoscopic", "Time interval for rechecking insertion into the next segment after failure");
251 #endif
252 
253  // add rand options
255 
256  // add GUI options
257  // the reason that we include them in vanilla sumo as well is to make reusing config files easy
258  oc.addOptionSubTopic("GUI Only");
259  oc.doRegister("gui-settings-file", new Option_FileName());
260  oc.addDescription("gui-settings-file", "GUI Only", "Load visualisation settings from FILE");
261 
262  oc.doRegister("quit-on-end", 'Q', new Option_Bool(false));
263  oc.addDescription("quit-on-end", "GUI Only", "Quits the GUI when the simulation stops");
264 
265  oc.doRegister("game", 'G', new Option_Bool(false));
266  oc.addDescription("game", "GUI Only", "Start the GUI in gaming mode");
267 
268  oc.doRegister("start", 'S', new Option_Bool(false));
269  oc.addDescription("start", "GUI Only", "Start the simulation after loading");
270 
271  oc.doRegister("disable-textures", 'T', new Option_Bool(false));
272  oc.addDescription("disable-textures", "GUI Only", "Do not load background pictures");
273 
274 }
275 
276 
277 void
279  // standard outputs
280  OutputDevice::createDeviceByOption("netstate-dump", "sumo-netstate");
281  OutputDevice::createDeviceByOption("summary-output", "summary");
282  OutputDevice::createDeviceByOption("tripinfo-output", "tripinfos");
284 }
285 
286 
287 bool
290  bool ok = true;
291  if (!oc.isSet("net-file")) {
292  WRITE_ERROR("No network file (-n) specified.");
293  ok = false;
294  }
295  if (oc.isSet("incremental-dua-step") && oc.isSet("incremental-dua-base")) {
296  WRITE_WARNING("The options 'incremental-dua-step' and 'incremental-dua-base' are deprecated, use 'scale' instead.");
297  if (oc.getInt("incremental-dua-step") > oc.getInt("incremental-dua-base")) {
298  WRITE_ERROR("Invalid dua step.");
299  ok = false;
300  }
301  }
302  if (!oc.isDefault("scale")) {
303  if (oc.getFloat("scale") < 0. || oc.getFloat("scale") > 1.) {
304  WRITE_ERROR("Invalid scaling factor.");
305  ok = false;
306  }
307  }
308  if (oc.getBool("vehroute-output.exit-times") && !oc.isSet("vehroute-output")) {
309  WRITE_ERROR("A vehroute-output file is needed for exit times.");
310  ok = false;
311  }
312  return ok;
313 }
314 
315 
316 void
318  // pre-initialise the network
319  // set whether empty edges shall be printed on dump
320  MSGlobals::gOmitEmptyEdgesOnDump = !oc.getBool("netstate-dump.empty-edges");
321 #ifdef HAVE_INTERNAL_LANES
322  // set whether internal lanes shall be used
323  MSGlobals::gUsingInternalLanes = !oc.getBool("no-internal-links");
324 #else
326 #endif
327  // set the grid lock time
328  MSGlobals::gTimeToGridlock = string2time(oc.getString("time-to-teleport")) < 0 ? 0 : string2time(oc.getString("time-to-teleport"));
329  MSGlobals::gCheck4Accidents = !oc.getBool("ignore-accidents");
330  MSGlobals::gCheckRoutes = !oc.getBool("ignore-route-errors");
331 #ifdef HAVE_MESOSIM
332  MSGlobals::gStateLoaded = oc.isSet("load-state");
333  MSGlobals::gUseMesoSim = oc.getBool("mesosim");
334 #endif
335 
336 #ifdef HAVE_SUBSECOND_TIMESTEPS
337  DELTA_T = string2time(oc.getString("step-length"));
338 #endif
339 }
340 
341 
342 
343 /****************************************************************************/
344