MATSIM
ControllerConfigGroup.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * ControlerConfigGroup.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2007 by the members listed in the COPYING, *
8  * LICENSE and WARRANTY file. *
9  * email : info at matsim dot org *
10  * *
11  * *********************************************************************** *
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * See also COPYING, LICENSE and WARRANTY file *
18  * *
19  * *********************************************************************** */
20 
21 package org.matsim.core.config.groups;
22 
23 import org.apache.logging.log4j.LogManager;
24 import org.apache.logging.log4j.Logger;
25 import org.matsim.core.config.Config;
28 import org.matsim.core.utils.io.IOUtils;
30 
31 import java.util.*;
32 
33 
34 public final class ControllerConfigGroup extends ReflectiveConfigGroup {
35  private static final Logger log = LogManager.getLogger( ControllerConfigGroup.class );
36 
37  public enum RoutingAlgorithmType {Dijkstra, AStarLandmarks, SpeedyALT}
38 
40 
41  public enum EventsFileFormat {xml, pb, json}
42 
43  public enum CompressionType {
44  none(""),
45  gzip(".gz"),
46  lz4(".lz4"),
47  zst(".zst");
48 
49  public final String fileEnding;
50 
51  CompressionType(String fileEnding) {
52  this.fileEnding = fileEnding;
53  }
54  }
55 
56  public enum CleanIterations {
58  delete,
59  }
60 
61  public static final String GROUP_NAME = "controller";
62 
63  private static final String OUTPUT_DIRECTORY = "outputDirectory";
64  private static final String FIRST_ITERATION = "firstIteration";
65  private static final String LAST_ITERATION = "lastIteration";
66  private static final String ROUTINGALGORITHM_TYPE = "routingAlgorithmType";
67  private static final String RUNID = "runId";
68  private static final String LINKTOLINK_ROUTING_ENABLED = "enableLinkToLinkRouting";
69  /*package*/ static final String EVENTS_FILE_FORMAT = "eventsFileFormat";
70  private static final String SNAPSHOT_FORMAT = "snapshotFormat";
71  private static final String WRITE_EVENTS_INTERVAL = "writeEventsInterval";
72  private static final String WRITE_PLANS_INTERVAL = "writePlansInterval";
73  private static final String WRITE_TRIPS_INTERVAL = "writeTripsInterval";
74  private static final String OVERWRITE_FILE = "overwriteFiles";
75  private static final String CREATE_GRAPHS = "createGraphs";
76  private static final String CREATE_GRAPHS_INTERVAL = "createGraphsInterval";
77  private static final String DUMP_DATA_AT_END = "dumpDataAtEnd";
78  private static final String CLEAN_ITERS_AT_END = "cleanItersAtEnd";
79  private static final String COMPRESSION_TYPE = "compressionType";
80  private static final String EVENT_TYPE_TO_CREATE_SCORING_FUNCTIONS = "createScoringFunctionType";
81 
82  private static final String MEMORY_OBSERVER_INTERVAL = "memoryObserverInterval";
83 
84  /*package*/ static final String MOBSIM = "mobsim";
85  public enum MobsimType {qsim, hermes}
86 
87  private static final String WRITE_SNAPSHOTS_INTERVAL = "writeSnapshotsInterval";
88 
89  private String outputDirectory = "./output";
90  private int firstIteration = 0;
91  private int lastIteration = 1000;
94 
95  private boolean linkToLinkRoutingEnabled = false;
96 
97  private String runId = null;
98 
99  private Set<EventsFileFormat> eventsFileFormats = Collections.unmodifiableSet(EnumSet.of(EventsFileFormat.xml));
100 
101  private int writeEventsInterval= 50;
102  private int writePlansInterval= 50;
103  private int writeTripsInterval = 50;
104  private String mobsim = MobsimType.qsim.toString();
105  private int writeSnapshotsInterval = 1;
106  private int createGraphsInterval = 1;
107  private boolean dumpDataAtEnd = true;
108 
111 
113 
114  private int memoryObserverInterval = 60;
115 
117  super(GROUP_NAME);
118  }
119 
120  @Override
121  public final Map<String, String> getComments() {
122  Map<String,String> map = super.getComments();
123  map.put(ROUTINGALGORITHM_TYPE, "The type of routing (least cost path) algorithm used, may have the values: " + Arrays.toString(RoutingAlgorithmType.values()));
124  map.put(RUNID, "An identifier for the current run which is used as prefix for output files and mentioned in output xml files etc.");
125  map.put(EVENTS_FILE_FORMAT, "Default="+EventsFileFormat.xml+"; Specifies the file format for writing events. Currently supported: " + Arrays.toString(EventsFileFormat.values()) + IOUtils.NATIVE_NEWLINE+ "\t\t" +
126  "Multiple values can be specified separated by commas (',').");
127  map.put(WRITE_EVENTS_INTERVAL, "iterationNumber % writeEventsInterval == 0 defines in which iterations events are written " +
128  "to a file. `0' disables events writing completely.");
129  map.put(WRITE_TRIPS_INTERVAL, "iterationNumber % writeEventsInterval == 0 defines in which iterations trips CSV are written " +
130  "to a file. `0' disables trips writing completely.");
131  map.put(WRITE_PLANS_INTERVAL, "iterationNumber % writePlansInterval == 0 defines (hopefully) in which iterations plans are " +
132  "written to a file. `0' disables plans writing completely. Some plans in early iterations are always written");
133  map.put(LINKTOLINK_ROUTING_ENABLED, "Default=false. If enabled, the router takes travel times needed for turning moves into account."
134  + " Can only be used with Dijkstra routing. Cannot be used when TravelTimeCalculator.separateModes is enabled.");
135  map.put(FIRST_ITERATION, "Default=0. First Iteration of a simulation.");
136  map.put(LAST_ITERATION, "Default=1000. Last Iteration of a simulation.");
137 
138  map.put(CREATE_GRAPHS, "Sets whether graphs showing some analyses should automatically be generated during the simulation." +
139  " The generation of graphs usually takes a small amount of time that does not have any weight in big simulations," +
140  " but add a significant overhead in smaller runs or in test cases where the graphical output is not even requested." );
141 
142  map.put(CREATE_GRAPHS_INTERVAL, "Sets the interval in which graphs are generated. Default is 1. If set to 0, no graphs are generated." +
143  " The generation of graphs usually takes a small amount of time that does not have any weight in big simulations," +
144  " but add a significant overhead in smaller runs or in test cases where the graphical output is not even requested." );
145 
146  map.put(COMPRESSION_TYPE, "Compression algorithm to use when writing out data to files. Possible values: " + Arrays.toString(CompressionType.values()));
147  map.put(EVENT_TYPE_TO_CREATE_SCORING_FUNCTIONS, "Defines when the scoring functions for the population are created. Default=IterationStarts. Possible values: " + Arrays.toString(EventTypeToCreateScoringFunctions.values()));
148 
149  map.put(MOBSIM, "Defines which mobility simulation will be used. Currently supported: " + Arrays.toString(MobsimType.values()) + IOUtils.NATIVE_NEWLINE + "\t\t" +
150  "Depending on the chosen mobsim, you'll have to add additional config modules to configure the corresponding mobsim." + IOUtils.NATIVE_NEWLINE + "\t\t" +
151  "For 'qsim', add a module 'qsim' to the config.");
152 
153  map.put(SNAPSHOT_FORMAT, "Comma-separated list of visualizer output file formats. `transims' and `otfvis'.");
154  map.put(WRITE_SNAPSHOTS_INTERVAL, "iterationNumber % " + WRITE_SNAPSHOTS_INTERVAL + " == 0 defines in which iterations snapshots are written " +
155  "to a file. `0' disables snapshots writing completely");
156  map.put(DUMP_DATA_AT_END, "true if at the end of a run, plans, network, config etc should be dumped to a file");
157  map.put(CLEAN_ITERS_AT_END, "Defines what should be done with the ITERS directory when a simulation finished successfully");
158  map.put(MEMORY_OBSERVER_INTERVAL, "Defines the interval for printing memory usage to the log in [seconds]. Must be positive. Defaults to 60.");
159  return map;
160  }
161 
162 
163  @StringSetter( OUTPUT_DIRECTORY )
164  public void setOutputDirectory(final String outputDirectory) {
165  this.outputDirectory = outputDirectory;
166  }
167 
168  @StringGetter( OUTPUT_DIRECTORY )
169  public String getOutputDirectory() {
170  return this.outputDirectory;
171  }
172 
173  @StringSetter( FIRST_ITERATION )
174  public void setFirstIteration(final int firstIteration) {
175  this.firstIteration = firstIteration;
176  }
177 
179  public int getFirstIteration() {
180  return this.firstIteration;
181  }
182 
184  public void setLastIteration(final int lastIteration) {
185  this.lastIteration = lastIteration;
186  }
187 
189  public int getLastIteration() {
190  return this.lastIteration;
191  }
192 
195  return this.routingAlgorithmType;
196  }
197 
200  this.routingAlgorithmType = type;
201  }
202 
205  return this.compressionType;
206  }
207 
210  this.compressionType = type;
211  }
212 
213  @StringGetter( RUNID )
214  public String getRunId() {
215  return this.runId;
216  }
217 
219  public int getWriteTripsInterval() {
220  return writeTripsInterval;
221  }
222 
226  }
227 
228  @StringSetter( RUNID )
229  public void setRunId(final String runid) {
230  if (runid == null) {
231  this.runId = null;
232  } else {
233  if (runid.equals("")) {
234  log.info("No run Id provided. Setting run Id to null.");
235  this.runId = null;
236  } else {
237  this.runId = runid;
238  }
239  }
240  }
241 
243  public boolean isLinkToLinkRoutingEnabled() {
244  return this.linkToLinkRoutingEnabled;
245  }
246 
248  public void setLinkToLinkRoutingEnabled(final boolean enabled) {
249  this.linkToLinkRoutingEnabled = enabled;
250  }
251 
252 
253  @StringGetter( EVENTS_FILE_FORMAT )
254  private String getEventsFileFormatAsString() {
255  boolean isFirst = true;
256  StringBuilder str = new StringBuilder();
257  for (EventsFileFormat format : this.eventsFileFormats) {
258  if (!isFirst) {
259  str.append(',');
260  }
261  str.append(format.toString());
262  isFirst = false;
263  }
264  return str.toString();
265  }
266 
267  @StringSetter( EVENTS_FILE_FORMAT )
268  private void setEventFileFormats( final String value ) {
269  String[] parts = StringUtils.explode(value, ',');
270  Set<EventsFileFormat> formats = EnumSet.noneOf(EventsFileFormat.class);
271  for (String part : parts) {
272  String trimmed = part.trim();
273  if (trimmed.length() > 0) {
274  formats.add(EventsFileFormat.valueOf(trimmed));
275  }
276  }
277  this.eventsFileFormats = formats;
278  }
279 
280  public Set<EventsFileFormat> getEventsFileFormats() {
281  return this.eventsFileFormats;
282  }
283 
284  public void setEventsFileFormats(final Set<EventsFileFormat> eventsFileFormats) {
285  this.eventsFileFormats = Collections.unmodifiableSet(EnumSet.copyOf(eventsFileFormats));
286  }
287  // ---
288  public enum SnapshotFormat { transims, googleearth, otfvis, positionevents }
289  private Set<SnapshotFormat> snapshotFormat = Collections.emptySet();
290 
292  private void setSnapshotFormats( final String value ) {
293  String[] parts = StringUtils.explode(value, ',');
294  Set<SnapshotFormat> formats = EnumSet.noneOf( SnapshotFormat.class );
295  for (String part : parts) {
296  String trimmed = part.trim();
297  if (trimmed.length() > 0) {
298  formats.add(SnapshotFormat.valueOf( trimmed ) );
299  }
300  }
301  this.snapshotFormat = formats;
302  }
303 
305  private String getSnapshotFormatAsString() {
306  boolean isFirst = true;
307  StringBuilder str = new StringBuilder();
308  for (SnapshotFormat format : this.snapshotFormat) {
309  if (!isFirst) {
310  str.append(',');
311  }
312  str.append(format.name());
313  isFirst = false;
314  }
315  return str.toString();
316  }
317 
318  public void setSnapshotFormat(final Collection<SnapshotFormat> snapshotFormat) {
319  this.snapshotFormat = Collections.unmodifiableSet(EnumSet.copyOf( snapshotFormat) );
320  }
321 
322  public Collection<SnapshotFormat> getSnapshotFormat() {
323  return this.snapshotFormat;
324  }
325  // ---
327  public int getWriteEventsInterval() {
328  return this.writeEventsInterval;
329  }
330 
334  }
335 
336  @StringGetter( MOBSIM )
337  public String getMobsim() {
338  return this.mobsim;
339  }
340 
341  @StringSetter( MOBSIM )
342  public void setMobsim(final String mobsim) {
343  this.mobsim = mobsim;
344  }
345 
347  public int getWritePlansInterval() {
348  return this.writePlansInterval;
349  }
350 
352  public void setWritePlansInterval(final int writePlansInterval) {
354  }
355 
358  return writeSnapshotsInterval;
359  }
360 
364  }
365 
367  public int getCreateGraphsInterval() {
368  return createGraphsInterval;
369  }
370 
383  }
384 
386  @Deprecated
387  public void setCreateGraphs(boolean createGraphs) {
388  log.warn("Parameter 'createGraphs' is deprecated. Using 'createGraphsInterval' instead. The output_config.xml will contain the new parameter.");
389  if (createGraphs) {
390  this.setCreateGraphsInterval(1);
391  } else {
392  this.setCreateGraphsInterval(0);
393  }
394  }
395 
398  return overwriteFileSetting;
399  }
400 
404  }
405 
407  public boolean getDumpDataAtEnd() {
408  return dumpDataAtEnd;
409  }
410 
412  public void setDumpDataAtEnd(boolean dumpDataAtEnd) {
414  }
415 
419  }
420 
423  return cleanItersAtEnd;
424  }
425 
429  }
430 
434  }
435 
438  return memoryObserverInterval;
439  }
440 
444  }
445 
446  // ---
447  int writePlansUntilIteration = 1 ;
449  return this.writePlansUntilIteration ;
450  }
451  public void setWritePlansUntilIteration(int val) {
452  this.writePlansUntilIteration = val ;
453  }
454  // ---
455  int writeEventsUntilIteration = 0 ; // old default of this was 0, not 1 as for plans. kai, aug'16
457  return this.writeEventsUntilIteration ;
458  }
459  public void setWriteEventsUntilIteration(int val) {
460  this.writeEventsUntilIteration = val ;
461  }
462  @Override
463  protected void checkConsistency(Config config) {
465  log.warn( "setting overwriting behavior to "+overwriteFileSetting );
466  log.warn( "this is not recommended, as it might result in a directory containing output from several model runs" );
468  }
469  if(config.controller().getMemoryObserverInterval() < 0) {
470  log.warn("Memory observer interval is negative. Simulation will most likely crash.");
471  }
472  }
473 }
static final String NATIVE_NEWLINE
Definition: IOUtils.java:186
void setRoutingAlgorithmType(final RoutingAlgorithmType type)
void setCleanItersAtEnd(CleanIterations cleanItersAtEnd)
static String [] explode(final String str, final char delimiter, final int limit)
void setOverwriteFileSetting(final OverwriteFileSetting overwriteFileSetting)
void setEventsFileFormats(final Set< EventsFileFormat > eventsFileFormats)
EventTypeToCreateScoringFunctions getEventTypeToCreateScoringFunctions()
void setWriteEventsInterval(final int writeEventsInterval)
final ControllerConfigGroup controller()
Definition: Config.java:399
EventTypeToCreateScoringFunctions eventTypeToCreateScoringFunctions
void setSnapshotFormat(final Collection< SnapshotFormat > snapshotFormat)
void setEventTypeToCreateScoringFunctions(EventTypeToCreateScoringFunctions eventTypeToCreateScoringFunctions)