MATSIM
ControlerConfigGroup.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 ControlerConfigGroup extends ReflectiveConfigGroup {
35  private static final Logger log = LogManager.getLogger( ControlerConfigGroup.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 = "controler";
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 DUMP_DATA_AT_END = "dumpDataAtEnd";
77  private static final String CLEAN_ITERS_AT_END = "cleanItersAtEnd";
78  private static final String COMPRESSION_TYPE = "compressionType";
79  private static final String EVENT_TYPE_TO_CREATE_SCORING_FUNCTIONS = "createScoringFunctionType";
80 
81  /*package*/ static final String MOBSIM = "mobsim";
82  public enum MobsimType {qsim, JDEQSim, hermes}
83 
84  private static final String WRITE_SNAPSHOTS_INTERVAL = "writeSnapshotsInterval";
85 
86 
87  private String outputDirectory = "./output";
88  private int firstIteration = 0;
89  private int lastIteration = 1000;
92 
93  private boolean linkToLinkRoutingEnabled = false;
94 
95  private String runId = null;
96 
97  private Set<EventsFileFormat> eventsFileFormats = Collections.unmodifiableSet(EnumSet.of(EventsFileFormat.xml));
98 
99  private int writeEventsInterval= 50;
100  private int writePlansInterval= 50;
101  private int writeTripsInterval = 50;
102  private String mobsim = MobsimType.qsim.toString();
103  private int writeSnapshotsInterval = 1;
104  private boolean createGraphs = true;
105  private boolean dumpDataAtEnd = true;
106 
109 
111 
113  super(GROUP_NAME);
114  }
115 
116  @Override
117  public final Map<String, String> getComments() {
118  Map<String,String> map = super.getComments();
119  map.put(ROUTINGALGORITHM_TYPE, "The type of routing (least cost path) algorithm used, may have the values: " + Arrays.toString(RoutingAlgorithmType.values()));
120  map.put(RUNID, "An identifier for the current run which is used as prefix for output files and mentioned in output xml files etc.");
121  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" +
122  "Multiple values can be specified separated by commas (',').");
123  map.put(WRITE_EVENTS_INTERVAL, "iterationNumber % writeEventsInterval == 0 defines in which iterations events are written " +
124  "to a file. `0' disables events writing completely.");
125  map.put(WRITE_TRIPS_INTERVAL, "iterationNumber % writeEventsInterval == 0 defines in which iterations trips CSV are written " +
126  "to a file. `0' disables trips writing completely.");
127  map.put(WRITE_PLANS_INTERVAL, "iterationNumber % writePlansInterval == 0 defines (hopefully) in which iterations plans are " +
128  "written to a file. `0' disables plans writing completely. Some plans in early iterations are always written");
129  map.put(LINKTOLINK_ROUTING_ENABLED, "Default=false. If enabled, the router takes travel times needed for turning moves into account."
130  + " Can only be used with Dijkstra routing. Cannot be used when TravelTimeCalculator.separateModes is enabled.");
131  map.put(FIRST_ITERATION, "Default=0. First Iteration of a simulation.");
132  map.put(LAST_ITERATION, "Default=1000. Last Iteration of a simulation.");
133 
134  map.put(CREATE_GRAPHS, "Sets whether graphs showing some analyses should automatically be generated during the simulation." +
135  " The generation of graphs usually takes a small amount of time that does not have any weight in big simulations," +
136  " but add a significant overhead in smaller runs or in test cases where the graphical output is not even requested." );
137  map.put(COMPRESSION_TYPE, "Compression algorithm to use when writing out data to files. Possible values: " + Arrays.toString(CompressionType.values()));
138  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()));
139 
140  map.put(MOBSIM, "Defines which mobility simulation will be used. Currently supported: " + Arrays.toString(MobsimType.values()) + IOUtils.NATIVE_NEWLINE + "\t\t" +
141  "Depending on the chosen mobsim, you'll have to add additional config modules to configure the corresponding mobsim." + IOUtils.NATIVE_NEWLINE + "\t\t" +
142  "For 'qsim', add a module 'qsim' to the config.");
143 
144  map.put(SNAPSHOT_FORMAT, "Comma-separated list of visualizer output file formats. `transims' and `otfvis'.");
145  map.put(WRITE_SNAPSHOTS_INTERVAL, "iterationNumber % " + WRITE_SNAPSHOTS_INTERVAL + " == 0 defines in which iterations snapshots are written " +
146  "to a file. `0' disables snapshots writing completely");
147  map.put(DUMP_DATA_AT_END, "true if at the end of a run, plans, network, config etc should be dumped to a file");
148  map.put(CLEAN_ITERS_AT_END, "Defines what should be done with the ITERS directory when a simulation finished successfully");
149  return map;
150  }
151 
152 
153  @StringSetter( OUTPUT_DIRECTORY )
154  public void setOutputDirectory(final String outputDirectory) {
155  this.outputDirectory = outputDirectory;
156  }
157 
158  @StringGetter( OUTPUT_DIRECTORY )
159  public String getOutputDirectory() {
160  return this.outputDirectory;
161  }
162 
163  @StringSetter( FIRST_ITERATION )
164  public void setFirstIteration(final int firstIteration) {
165  this.firstIteration = firstIteration;
166  }
167 
169  public int getFirstIteration() {
170  return this.firstIteration;
171  }
172 
174  public void setLastIteration(final int lastIteration) {
175  this.lastIteration = lastIteration;
176  }
177 
179  public int getLastIteration() {
180  return this.lastIteration;
181  }
182 
185  return this.routingAlgorithmType;
186  }
187 
190  this.routingAlgorithmType = type;
191  }
192 
195  return this.compressionType;
196  }
197 
200  this.compressionType = type;
201  }
202 
203  @StringGetter( RUNID )
204  public String getRunId() {
205  return this.runId;
206  }
207 
209  public int getWriteTripsInterval() {
210  return writeTripsInterval;
211  }
212 
216  }
217 
218  @StringSetter( RUNID )
219  public void setRunId(final String runid) {
220  if (runid == null) {
221  this.runId = null;
222  } else {
223  if (runid.equals("")) {
224  log.info("No run Id provided. Setting run Id to null.");
225  this.runId = null;
226  } else {
227  this.runId = runid;
228  }
229  }
230  }
231 
233  public boolean isLinkToLinkRoutingEnabled() {
234  return this.linkToLinkRoutingEnabled;
235  }
236 
238  public void setLinkToLinkRoutingEnabled(final boolean enabled) {
239  this.linkToLinkRoutingEnabled = enabled;
240  }
241 
242 
243  @StringGetter( EVENTS_FILE_FORMAT )
244  private String getEventsFileFormatAsString() {
245  boolean isFirst = true;
246  StringBuilder str = new StringBuilder();
247  for (EventsFileFormat format : this.eventsFileFormats) {
248  if (!isFirst) {
249  str.append(',');
250  }
251  str.append(format.toString());
252  isFirst = false;
253  }
254  return str.toString();
255  }
256 
257  @StringSetter( EVENTS_FILE_FORMAT )
258  private void setEventFileFormats( final String value ) {
259  String[] parts = StringUtils.explode(value, ',');
260  Set<EventsFileFormat> formats = EnumSet.noneOf(EventsFileFormat.class);
261  for (String part : parts) {
262  String trimmed = part.trim();
263  if (trimmed.length() > 0) {
264  formats.add(EventsFileFormat.valueOf(trimmed));
265  }
266  }
267  this.eventsFileFormats = formats;
268  }
269 
270  public Set<EventsFileFormat> getEventsFileFormats() {
271  return this.eventsFileFormats;
272  }
273 
274  public void setEventsFileFormats(final Set<EventsFileFormat> eventsFileFormats) {
275  this.eventsFileFormats = Collections.unmodifiableSet(EnumSet.copyOf(eventsFileFormats));
276  }
277  // ---
278  public enum SnapshotFormat { transims, googleearth, otfvis, positionevents }
279  private Set<SnapshotFormat> snapshotFormat = Collections.emptySet();
280 
282  private void setSnapshotFormats( final String value ) {
283  String[] parts = StringUtils.explode(value, ',');
284  Set<SnapshotFormat> formats = EnumSet.noneOf( SnapshotFormat.class );
285  for (String part : parts) {
286  String trimmed = part.trim();
287  if (trimmed.length() > 0) {
288  formats.add(SnapshotFormat.valueOf( trimmed ) );
289  }
290  }
291  this.snapshotFormat = formats;
292  }
293 
295  private String getSnapshotFormatAsString() {
296  boolean isFirst = true;
297  StringBuilder str = new StringBuilder();
298  for (SnapshotFormat format : this.snapshotFormat) {
299  if (!isFirst) {
300  str.append(',');
301  }
302  str.append(format.name());
303  isFirst = false;
304  }
305  return str.toString();
306  }
307 
308  public void setSnapshotFormat(final Collection<SnapshotFormat> snapshotFormat) {
309  this.snapshotFormat = Collections.unmodifiableSet(EnumSet.copyOf( snapshotFormat) );
310  }
311 
312  public Collection<SnapshotFormat> getSnapshotFormat() {
313  return this.snapshotFormat;
314  }
315  // ---
317  public int getWriteEventsInterval() {
318  return this.writeEventsInterval;
319  }
320 
324  }
325 
326  @StringGetter( MOBSIM )
327  public String getMobsim() {
328  return this.mobsim;
329  }
330 
331  @StringSetter( MOBSIM )
332  public void setMobsim(final String mobsim) {
333  this.mobsim = mobsim;
334  }
335 
337  public int getWritePlansInterval() {
338  return this.writePlansInterval;
339  }
340 
342  public void setWritePlansInterval(final int writePlansInterval) {
344  }
345 
348  return writeSnapshotsInterval;
349  }
350 
354  }
355 
357  public boolean isCreateGraphs() {
358  return createGraphs;
359  }
360 
372  public void setCreateGraphs(boolean createGraphs) {
373  this.createGraphs = createGraphs;
374  }
375 
378  return overwriteFileSetting;
379  }
380 
384  }
385 
387  public boolean getDumpDataAtEnd() {
388  return dumpDataAtEnd;
389  }
390 
392  public void setDumpDataAtEnd(boolean dumpDataAtEnd) {
394  }
395 
399  }
400 
403  return cleanItersAtEnd;
404  }
405 
409  }
410 
414  }
415  // ---
416  int writePlansUntilIteration = 1 ;
418  return this.writePlansUntilIteration ;
419  }
420  public void setWritePlansUntilIteration(int val) {
421  this.writePlansUntilIteration = val ;
422  }
423  // ---
424  int writeEventsUntilIteration = 0 ; // old default of this was 0, not 1 as for plans. kai, aug'16
426  return this.writeEventsUntilIteration ;
427  }
428  public void setWriteEventsUntilIteration(int val) {
429  this.writeEventsUntilIteration = val ;
430  }
431  @Override
432  protected void checkConsistency(Config config) {
434  log.warn( "setting overwriting behavior to "+overwriteFileSetting );
435  log.warn( "this is not recommended, as it might result in a directory containing output from several model runs" );
437  }
438  }
439 }
void setOverwriteFileSetting(final OverwriteFileSetting overwriteFileSetting)
void setCleanItersAtEnd(CleanIterations cleanItersAtEnd)
void setSnapshotFormat(final Collection< SnapshotFormat > snapshotFormat)
EventTypeToCreateScoringFunctions getEventTypeToCreateScoringFunctions()
static final String NATIVE_NEWLINE
Definition: IOUtils.java:185
void setWritePlansInterval(final int writePlansInterval)
void setRoutingAlgorithmType(final RoutingAlgorithmType type)
EventTypeToCreateScoringFunctions eventTypeToCreateScoringFunctions
static String [] explode(final String str, final char delimiter, final int limit)
void setWriteEventsInterval(final int writeEventsInterval)
void setEventsFileFormats(final Set< EventsFileFormat > eventsFileFormats)
final ControlerConfigGroup controler()
Definition: Config.java:403
void setEventTypeToCreateScoringFunctions(EventTypeToCreateScoringFunctions eventTypeToCreateScoringFunctions)
void setWriteSnapshotsInterval(int writeSnapshotsInterval)