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 /****************************************************************************/
13 // Sets and checks options for microsim; inits global outputs and settings
14 /****************************************************************************/
15 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
16 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
17 /****************************************************************************/
18 //
19 // This file is part of SUMO.
20 // SUMO is free software: you can redistribute it and/or modify
21 // it under the terms of the GNU General Public License as published by
22 // the Free Software Foundation, either version 3 of the License, or
23 // (at your option) any later version.
24 //
25 /****************************************************************************/
26 
27 
28 // ===========================================================================
29 // included modules
30 // ===========================================================================
31 #ifdef _MSC_VER
32 #include <windows_config.h>
33 #else
34 #include <config.h>
35 #endif
36 
37 #include <iostream>
38 #include <iomanip>
39 #include <fstream>
40 #include <ctime>
42 #include <utils/options/Option.h>
45 #include <utils/common/ToString.h>
48 #include <microsim/MSJunction.h>
49 #include <microsim/MSRoute.h>
50 #include <microsim/MSNet.h>
51 #include <microsim/MSGlobals.h>
56 #include "MSFrame.h"
58 
59 #ifdef CHECK_MEMORY_LEAKS
60 #include <foreign/nvwa/debug_new.h>
61 #endif // CHECK_MEMORY_LEAKS
62 
63 
64 // ===========================================================================
65 // method definitions
66 // ===========================================================================
67 void
70  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");
71  oc.addCallExample("-c munich_config.cfg", "start with a configuration file");
72  oc.addCallExample("--help", "print help");
73 
74  // insert options sub-topics
75  SystemFrame::addConfigurationOptions(oc); // fill this subtopic, too
76  oc.addOptionSubTopic("Input");
77  oc.addOptionSubTopic("Output");
78  oc.addOptionSubTopic("Time");
79  oc.addOptionSubTopic("Processing");
80  SystemFrame::addReportOptions(oc); // fill this subtopic, too
81 
82 
83  // register configuration options
84  // register input options
85  oc.doRegister("net-file", 'n', new Option_FileName());
86  oc.addSynonyme("net-file", "net");
87  oc.addDescription("net-file", "Input", "Load road network description from FILE");
88 
89  oc.doRegister("route-files", 'r', new Option_FileName());
90  oc.addSynonyme("route-files", "routes");
91  oc.addDescription("route-files", "Input", "Load routes descriptions from FILE(s)");
92 
93  oc.doRegister("additional-files", 'a', new Option_FileName());
94  oc.addSynonyme("additional-files", "additional");
95  oc.addDescription("additional-files", "Input", "Load further descriptions from FILE(s)");
96 
97  oc.doRegister("weight-files", 'w', new Option_FileName());
98  oc.addSynonyme("weight-files", "weights");
99  oc.addDescription("weight-files", "Input", "Load edge/lane weights for online rerouting from FILE");
100  oc.doRegister("weight-attribute", 'x', new Option_String("traveltime"));
101  oc.addSynonyme("weight-attribute", "measure", true);
102  oc.addDescription("weight-attribute", "Input", "Name of the xml attribute which gives the edge weight");
103 
104 #ifdef HAVE_INTERNAL
105  oc.doRegister("load-state", new Option_FileName());
106  oc.addDescription("load-state", "Input", "Loads a network state from FILE");
107  oc.doRegister("load-state.offset", new Option_String("0", "TIME"));
108  oc.addDescription("load-state.offset", "Input", "Sets the time offset for vehicle segment exit times.");
109 #endif
110 
111  // register output options
112  oc.doRegister("netstate-dump", new Option_FileName());
113  oc.addSynonyme("netstate-dump", "ndump");
114  oc.addSynonyme("netstate-dump", "netstate");
115  oc.addDescription("netstate-dump", "Output", "Save complete network states into FILE");
116  oc.doRegister("netstate-dump.empty-edges", new Option_Bool(false));
117  oc.addSynonyme("netstate-dump.empty-edges", "netstate.empty-edges");
118  oc.addSynonyme("netstate-dump.empty-edges", "dump-empty-edges", true);
119  oc.addDescription("netstate-dump.empty-edges", "Output", "Write also empty edges completely when dumping");
120 
121 
122  oc.doRegister("emission-output", new Option_FileName());
123  oc.addDescription("emission-output", "Output", "Save the emission values of each vehicle");
124  oc.doRegister("fcd-output", new Option_FileName());
125  oc.addDescription("fcd-output", "Output", "Save the Floating Car Data");
126  oc.doRegister("fcd-output.geo", new Option_Bool(false));
127  oc.addDescription("fcd-output.geo", "Output", "Save the Floating Car Data using geo-coordinates (lon/lat)");
128  oc.doRegister("full-output", new Option_FileName());
129  oc.addDescription("full-output", "Output", "Save a lot of information for each timestep (very redundant)");
130  oc.doRegister("queue-output", new Option_FileName());
131  oc.addDescription("queue-output", "Output", "Save the vehicle queues at the junctions (experimental)");
132  oc.doRegister("vtk-output", new Option_FileName());
133  oc.addDescription("vtk-output", "Output", "Save complete vehicle positions in VTK Format (usage: /file/out will produce /file/out_$NR$.vtp files)");
134 
135 
136  oc.doRegister("summary-output", new Option_FileName());
137  oc.addSynonyme("summary-output", "summary");
138  oc.addSynonyme("summary-output", "emissions-output", true);
139  oc.addSynonyme("summary-output", "emissions", true);
140  oc.addDescription("summary-output", "Output", "Save aggregated vehicle departure info into FILE");
141 
142  oc.doRegister("tripinfo-output", new Option_FileName());
143  oc.addSynonyme("tripinfo-output", "tripinfo");
144  oc.addDescription("tripinfo-output", "Output", "Save single vehicle trip info into FILE");
145 
146  oc.doRegister("vehroute-output", new Option_FileName());
147  oc.addSynonyme("vehroute-output", "vehroutes");
148  oc.addDescription("vehroute-output", "Output", "Save single vehicle route info into FILE");
149 
150  oc.doRegister("vehroute-output.exit-times", new Option_Bool(false));
151  oc.addSynonyme("vehroute-output.exit-times", "vehroutes.exit-times");
152  oc.addDescription("vehroute-output.exit-times", "Output", "Write the exit times for all edges");
153 
154  oc.doRegister("vehroute-output.last-route", new Option_Bool(false));
155  oc.addSynonyme("vehroute-output.last-route", "vehroutes.last-route");
156  oc.addDescription("vehroute-output.last-route", "Output", "Write the last route only");
157 
158  oc.doRegister("vehroute-output.sorted", new Option_Bool(false));
159  oc.addSynonyme("vehroute-output.sorted", "vehroutes.sorted");
160  oc.addDescription("vehroute-output.sorted", "Output", "Sorts the output by departure time");
161 
162  oc.doRegister("vehroute-output.write-unfinished", new Option_Bool(false));
163  oc.addDescription("vehroute-output.write-unfinished", "Output", "Write vehroute output for vehicles which have not arrived at simulation end");
164 
165 
166 
167 #ifdef HAVE_INTERNAL
168  oc.doRegister("save-state.times", new Option_IntVector(IntVector()));
169  oc.addDescription("save-state.times", "Output", "Use INT[] as times at which a network state written");
170  oc.doRegister("save-state.prefix", new Option_FileName("state"));
171  oc.addDescription("save-state.prefix", "Output", "Prefix for network states");
172  oc.doRegister("save-state.files", new Option_FileName());
173  oc.addDescription("save-state.files", "Output", "Files for network states");
174 #endif
175 
176  // register the simulation settings
177  oc.doRegister("begin", 'b', new Option_String("0", "TIME"));
178  oc.addDescription("begin", "Time", "Defines the begin time; The simulation starts at this time");
179 
180  oc.doRegister("end", 'e', new Option_String("-1", "TIME"));
181  oc.addDescription("end", "Time", "Defines the end time; The simulation ends at this time");
182 
183 #ifdef HAVE_SUBSECOND_TIMESTEPS
184  oc.doRegister("step-length", new Option_String("1", "TIME"));
185  oc.addDescription("step-length", "Time", "Defines the step duration");
186 #endif
187 
188 
189  // register the processing options
190  oc.doRegister("route-steps", 's', new Option_String("200", "TIME"));
191  oc.addDescription("route-steps", "Processing", "Load routes for the next number of seconds ahead");
192 
193 #ifdef HAVE_INTERNAL_LANES
194  oc.doRegister("no-internal-links", new Option_Bool(false));
195  oc.addDescription("no-internal-links", "Processing", "Disable (junction) internal links");
196 #endif
197 
198  oc.doRegister("ignore-accidents", new Option_Bool(false));
199  oc.addDescription("ignore-accidents", "Processing", "Do not check whether accidents occure more deeply");
200 
201  oc.doRegister("ignore-route-errors", new Option_Bool(false));
202  oc.addDescription("ignore-route-errors", "Processing", "Do not check whether routes are connected");
203 
204  oc.doRegister("max-num-vehicles", new Option_Integer(-1));
205  oc.addSynonyme("max-num-vehicles", "too-many-vehicles", true);
206  oc.addDescription("max-num-vehicles", "Processing", "Quit simulation if this number of vehicles is exceeded");
207 
208  oc.doRegister("incremental-dua-step", new Option_Integer());
209  oc.addDescription("incremental-dua-step", "Processing", "Perform the simulation as a step in incremental DUA");
210  oc.doRegister("incremental-dua-base", new Option_Integer(10));
211  oc.addDescription("incremental-dua-base", "Processing", "Base value for incremental DUA");
212  oc.doRegister("scale", new Option_Float());
213  oc.addDescription("scale", "Processing", "Scale demand by the given factor (0..1)");
214 
215  oc.doRegister("time-to-teleport", new Option_String("300", "TIME"));
216  oc.addDescription("time-to-teleport", "Processing", "Specify how long a vehicle may wait until being teleported, defaults to 300, non-positive values disable teleporting");
217 
218  oc.doRegister("max-depart-delay", new Option_String("-1", "TIME"));
219  oc.addDescription("max-depart-delay", "Processing", "How long vehicles wait for departure before being skipped, defaults to -1 which means vehicles are never skipped");
220 
221  oc.doRegister("sloppy-insert", new Option_Bool(false));
222  oc.addDescription("sloppy-insert", "Processing", "Whether insertion on an edge shall not be repeated in same step once failed.");
223 
224  oc.doRegister("lanechange.allow-swap", new Option_Bool(false));
225  oc.addDescription("lanechange.allow-swap", "Processing", "Whether blocking vehicles trying to change lanes may be swapped.");
226 
227  oc.doRegister("routing-algorithm", new Option_String("dijkstra"));
228  oc.addDescription("routing-algorithm", "Processing",
229  "Select among routing algorithms ['dijkstra', 'astar']");
230 
231  oc.doRegister("routeDist.maxsize", new Option_Integer());
232  oc.addDescription("routeDist.maxsize", "Processing",
233  "Restrict the maximum size of route distributions");
234 
235  // devices
238 
239 
240  // register report options
241  oc.doRegister("no-duration-log", new Option_Bool(false));
242  oc.addDescription("no-duration-log", "Report", "Disable performance reports for individual simulation steps");
243 
244  oc.doRegister("no-step-log", new Option_Bool(false));
245  oc.addDescription("no-step-log", "Report", "Disable console output of current simulation step");
246 
247 
248 #ifndef NO_TRACI
249  //remote port 0 if not used
250  oc.addOptionSubTopic("TraCI Server");
251  oc.doRegister("remote-port", new Option_Integer(0));
252  oc.addDescription("remote-port", "TraCI Server", "Enables TraCI Server if set");
253 #ifdef HAVE_PYTHON
254  oc.doRegister("python-script", new Option_String());
255  oc.addDescription("python-script", "TraCI Server", "Runs TraCI script with embedded python");
256 #endif
257 #endif
258  //
259 #ifdef HAVE_INTERNAL
260  oc.addOptionSubTopic("Mesoscopic");
261  oc.doRegister("mesosim", new Option_Bool(false));
262  oc.addDescription("mesosim", "Mesoscopic", "Enables mesoscopic simulation");
263  oc.doRegister("meso-edgelength", new Option_Float(98.0f));
264  oc.addDescription("meso-edgelength", "Mesoscopic", "Length of an edge segment in mesoscopic simulation");
265  oc.doRegister("meso-tauff", new Option_String("1.4", "TIME"));
266  oc.addDescription("meso-tauff", "Mesoscopic", "Factor for calculating the free-free headway time");
267  oc.doRegister("meso-taufj", new Option_String("1.4", "TIME"));
268  oc.addDescription("meso-taufj", "Mesoscopic", "Factor for calculating the free-jam headway time");
269  oc.doRegister("meso-taujf", new Option_String("2", "TIME"));
270  oc.addDescription("meso-taujf", "Mesoscopic", "Factor for calculating the jam-free headway time");
271  oc.doRegister("meso-taujj", new Option_String("2", "TIME"));
272  oc.addDescription("meso-taujj", "Mesoscopic", "Factor for calculating the jam-jam headway time");
273  oc.doRegister("meso-jam-threshold", new Option_Float(-1));
274  oc.addDescription("meso-jam-threshold", "Mesoscopic", "Minimum percentage of occupied space to consider a segment jammed. A negative argument causes thresholds to be computed based on edge speed and tauff (default)");
275  oc.doRegister("meso-multi-queue", new Option_Bool(false));
276  oc.addDescription("meso-multi-queue", "Mesoscopic", "Enable multiple queues at edge ends");
277  oc.doRegister("meso-junction-control", new Option_Bool(false));
278  oc.addDescription("meso-junction-control", "Mesoscopic", "Enable mesoscopic traffic light and priority junction handling");
279  oc.doRegister("meso-junction-control.limited", new Option_Bool(false));
280  oc.addDescription("meso-junction-control.limited", "Mesoscopic", "Enable mesoscopic traffic light and priority junction handling for saturated links. This prevents faulty traffic lights from hindering flow in low-traffic situations");
281  oc.doRegister("meso-recheck", new Option_String("0", "TIME"));
282  oc.addDescription("meso-recheck", "Mesoscopic", "Time interval for rechecking insertion into the next segment after failure");
283 #endif
284 
285  // add rand options
287 
288  // add GUI options
289  // the reason that we include them in vanilla sumo as well is to make reusing config files easy
290  oc.addOptionSubTopic("GUI Only");
291  oc.doRegister("gui-settings-file", new Option_FileName());
292  oc.addDescription("gui-settings-file", "GUI Only", "Load visualisation settings from FILE");
293 
294  oc.doRegister("quit-on-end", 'Q', new Option_Bool(false));
295  oc.addDescription("quit-on-end", "GUI Only", "Quits the GUI when the simulation stops");
296 
297  oc.doRegister("game", 'G', new Option_Bool(false));
298  oc.addDescription("game", "GUI Only", "Start the GUI in gaming mode");
299 
300  oc.doRegister("start", 'S', new Option_Bool(false));
301  oc.addDescription("start", "GUI Only", "Start the simulation after loading");
302 
303  oc.doRegister("disable-textures", 'T', new Option_Bool(false));
304  oc.addDescription("disable-textures", "GUI Only", "Do not load background pictures");
305 
306 #ifdef HAVE_INTERNAL
307  oc.doRegister("osg-view", new Option_Bool(false));
308  oc.addDescription("osg-view", "GUI Only", "Start with an OpenSceneGraph view instead of the regular 2D view");
309 #endif
310 
311 }
312 
313 
314 void
316  // standard outputs
317  OutputDevice::createDeviceByOption("netstate-dump", "netstate");
318  OutputDevice::createDeviceByOption("summary-output", "summary");
319  OutputDevice::createDeviceByOption("tripinfo-output", "tripinfos");
320 
321  //extended
322  OutputDevice::createDeviceByOption("fcd-output", "fcd-export");
323  OutputDevice::createDeviceByOption("emission-output", "emission-export");
324  OutputDevice::createDeviceByOption("full-output", "full-export");
325  OutputDevice::createDeviceByOption("queue-output", "queue-export");
326  OutputDevice::createDeviceByOption("vtk-output", "vtk-export");
327 
329 }
330 
331 
332 bool
335  bool ok = true;
336  if (!oc.isSet("net-file")) {
337  WRITE_ERROR("No network file (-n) specified.");
338  ok = false;
339  }
340  if (oc.isSet("incremental-dua-step") && oc.isSet("incremental-dua-base")) {
341  WRITE_WARNING("The options 'incremental-dua-step' and 'incremental-dua-base' are deprecated, use 'scale' instead.");
342  if (oc.getInt("incremental-dua-step") > oc.getInt("incremental-dua-base")) {
343  WRITE_ERROR("Invalid dua step.");
344  ok = false;
345  }
346  }
347  if (!oc.isDefault("scale")) {
348  if (oc.getFloat("scale") < 0. || oc.getFloat("scale") > 1.) {
349  WRITE_ERROR("Invalid scaling factor.");
350  ok = false;
351  }
352  }
353  if (oc.getBool("vehroute-output.exit-times") && !oc.isSet("vehroute-output")) {
354  WRITE_ERROR("A vehroute-output file is needed for exit times.");
355  ok = false;
356  }
357  if (oc.isSet("gui-settings-file") &&
358  oc.getString("gui-settings-file") != "" &&
359  !oc.isUsableFileList("gui-settings-file")) {
360  ok = false;
361  }
362  if (oc.isSet("routeDist.maxsize") && oc.getInt("routeDist.maxsize") <= 0) {
363  WRITE_ERROR("routeDist.maxsize must be positive");
364  ok = false;
365  }
366 #ifdef HAVE_INTERNAL
367  if (oc.getBool("meso-junction-control.limited") && !oc.getBool("meso-junction-control")) {
368  oc.set("meso-junction-control", "true");
369  }
370 #endif
371  return ok;
372 }
373 
374 
375 void
377  // pre-initialise the network
378  // set whether empty edges shall be printed on dump
379  MSGlobals::gOmitEmptyEdgesOnDump = !oc.getBool("netstate-dump.empty-edges");
380 #ifdef HAVE_INTERNAL_LANES
381  // set whether internal lanes shall be used
382  MSGlobals::gUsingInternalLanes = !oc.getBool("no-internal-links");
383 #else
385 #endif
386  // set the grid lock time
387  MSGlobals::gTimeToGridlock = string2time(oc.getString("time-to-teleport")) < 0 ? 0 : string2time(oc.getString("time-to-teleport"));
388  MSGlobals::gCheck4Accidents = !oc.getBool("ignore-accidents");
389  MSGlobals::gCheckRoutes = !oc.getBool("ignore-route-errors");
390 #ifdef HAVE_INTERNAL
391  MSGlobals::gStateLoaded = oc.isSet("load-state");
392  MSGlobals::gUseMesoSim = oc.getBool("mesosim");
393  MSGlobals::gMesoLimitedJunctionControl = oc.getBool("meso-junction-control.limited");
396  }
397 #endif
398 
399 #ifdef HAVE_SUBSECOND_TIMESTEPS
400  DELTA_T = string2time(oc.getString("step-length"));
401 #endif
402  if (oc.isSet("routeDist.maxsize")) {
403  MSRoute::setMaxRouteDistSize(oc.getInt("routeDist.maxsize"));
404  }
405 }
406 
407 
408 
409 /****************************************************************************/
410