MATSIM
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
org.matsim.run.Events2Snapshot Class Reference

Public Member Functions

void run (final String[] args)
 
void run (final File eventsFile, final Config config, final Network network)
 
void addExternalSnapshotWriter (final SnapshotWriter writer)
 

Static Public Member Functions

static void main (final String[] args)
 

Private Member Functions

void parseArguments (final String[] args)
 
void printUsage ()
 
void prepare ()
 
void loadSnapshotWriters (final String outputDir)
 

Private Attributes

Config config = null
 
Network network = null
 
EventsManager events = null
 
SnapshotGenerator visualizer = null
 
String configfile = null
 
String eventsfile
 
SnapshotWriter writer = null
 

Detailed Description

Converts an events file to a snapshot file.

Author
mrieser
glaemmel

Definition at line 50 of file Events2Snapshot.java.

Member Function Documentation

◆ parseArguments()

void org.matsim.run.Events2Snapshot.parseArguments ( final String []  args)
private

Parses all arguments and sets the corresponding members.

Parameters
args

Definition at line 65 of file Events2Snapshot.java.

References org.matsim.core.utils.misc.ArgumentParser.iterator(), and org.matsim.run.Events2Snapshot.printUsage().

Referenced by org.matsim.run.Events2Snapshot.run().

65  {
66  if (args.length == 0) {
67  System.out.println("Too few arguments.");
68  printUsage();
69  System.exit(1);
70  }
71  Iterator<String> argIter = new ArgumentParser(args).iterator();
72  while (argIter.hasNext()) {
73  String arg = argIter.next();
74  if (arg.equals("-h") || arg.equals("--help")) {
75  printUsage();
76  System.exit(0);
77  } else {
78  if (arg.contains(".xml"))
79  this.configfile = arg;
80  else if (arg.contains("events"))
81  this.eventsfile = arg;
82  else {
83  System.out.println("Unrecognized file \"" + arg + "\"");
84  printUsage();
85  System.exit(1);
86  }
87  }
88  }
89  }
Here is the call graph for this function:

◆ printUsage()

void org.matsim.run.Events2Snapshot.printUsage ( )
private

Definition at line 91 of file Events2Snapshot.java.

Referenced by org.matsim.run.Events2Snapshot.parseArguments().

91  {
92  System.out.println();
93  System.out.println("Events2Snapshot");
94  System.out.println("Converts an events file to a snapshot file.");
95  System.out.println();
96  System.out.println("usage: Events2Snapshot [OPTIONS] configfile [eventsfile]");
97  System.out.println(" If no eventsfile is given, the in-events-file specified in the config-");
98  System.out.println(" file will be used.");
99  System.out.println(" The snapshots are generated according to the snapshot-settings in the");
100  System.out.println(" simulation-part of the configuration.");
101  System.out.println();
102  System.out.println("Options:");
103  System.out.println("-h, --help: Displays this message.");
104  System.out.println();
105  System.out.println("----------------");
106  System.out.println("2007, matsim.org");
107  System.out.println();
108  }

◆ run() [1/2]

void org.matsim.run.Events2Snapshot.run ( final String []  args)

Starts the conversion of events into snapshot files. Stand-alone run-method.

Parameters
argscommand-line arguments

Definition at line 114 of file Events2Snapshot.java.

References org.matsim.core.scenario.ScenarioUtils.createScenario(), org.matsim.core.events.algorithms.SnapshotGenerator.finish(), org.matsim.core.config.groups.NetworkConfigGroup.getInputFile(), org.matsim.api.core.v01.Scenario.getNetwork(), org.matsim.core.config.Config.getParam(), org.matsim.core.config.groups.GlobalConfigGroup.getRandomSeed(), org.matsim.core.config.Config.global(), org.matsim.core.config.ConfigUtils.loadConfig(), org.matsim.run.Events2Snapshot.loadSnapshotWriters(), org.matsim.core.config.Config.network(), org.matsim.run.Events2Snapshot.parseArguments(), org.matsim.run.Events2Snapshot.prepare(), org.matsim.core.events.MatsimEventsReader.readFile(), and org.matsim.core.gbl.MatsimRandom.reset().

Referenced by org.matsim.run.Events2Snapshot.main().

114  {
115  parseArguments(args);
116  Scenario scenario;
117  this.config = ConfigUtils.loadConfig(this.configfile);
118  MatsimRandom.reset(this.config.global().getRandomSeed());
119  scenario = ScenarioUtils.createScenario(this.config);
120 
121 // if (((SimulationConfigGroup) this.config.getModule(SimulationConfigGroup.GROUP_NAME)).getSnapshotPeriod() <= 0.0) {
122 // System.out.println("The snapshotPeriod must be larger than 0 seconds.");
123 // return;
124 // }
125 
126  this.network = scenario.getNetwork();
127  new MatsimNetworkReader(scenario.getNetwork()).readFile(this.config.network().getInputFile());
128  prepare();
129 
130  if (this.eventsfile == null) {
131  this.eventsfile = this.config.getParam("events", "inputFile");
132  }
133  System.out.println("reading events from " + this.eventsfile);
134  File file = new File(this.eventsfile);
135  String outputDir = file.getParent() + "/";
136 
137  loadSnapshotWriters(outputDir);
138 
139  new MatsimEventsReader(this.events).readFile(this.eventsfile);
140  this.visualizer.finish();
141  System.out.println("done.");
142  }
final String getParam(final String moduleName, final String paramName)
Definition: Config.java:318
void loadSnapshotWriters(final String outputDir)
final NetworkConfigGroup network()
Definition: Config.java:411
void parseArguments(final String[] args)
final GlobalConfigGroup global()
Definition: Config.java:395
Here is the call graph for this function:

◆ run() [2/2]

void org.matsim.run.Events2Snapshot.run ( final File  eventsFile,
final Config  config,
final Network  network 
)

Starts the conversion of events into snapshot files. Alternative run-method to more easily integrate it into existing code where config, network etc. are already loaded.

Parameters
eventsFile
config
network

Definition at line 152 of file Events2Snapshot.java.

References org.matsim.run.Events2Snapshot.config, org.matsim.core.events.algorithms.SnapshotGenerator.finish(), org.matsim.core.config.Config.getParam(), org.matsim.core.config.groups.QSimConfigGroup.getSnapshotPeriod(), org.matsim.run.Events2Snapshot.loadSnapshotWriters(), org.matsim.run.Events2Snapshot.network, org.matsim.run.Events2Snapshot.prepare(), org.matsim.core.config.Config.qsim(), and org.matsim.core.events.MatsimEventsReader.readFile().

152  {
153  this.eventsfile = eventsFile.getAbsolutePath();
154  this.config = config;
155 
156  if (this.config.qsim().getSnapshotPeriod() <= 0.0) {
157  System.out.println("The snapshotPeriod must be larger than 0 seconds.");
158  return;
159  }
160 
161  this.network = network;
162 
163  prepare();
164 
165  if (this.eventsfile == null) {
166  this.eventsfile = this.config.getParam("events", "inputFile");
167  }
168  System.out.println("reading events from " + this.eventsfile);
169  File file = new File(this.eventsfile);
170  String outputDir = file.getParent() + "/";
171 
172  loadSnapshotWriters(outputDir);
173 
174  try {
175  new MatsimEventsReader(this.events).readFile(this.eventsfile);
176  }
177  catch (OutOfMemoryError e) {
178  System.err.println("OutOfMemoryError while reading all events:");
179  e.printStackTrace();
180  System.err.println("Trying to close visualizer file up to this state, it may not be complete though.");
181  }
182  this.visualizer.finish();
183  System.out.println("done.");
184  }
final String getParam(final String moduleName, final String paramName)
Definition: Config.java:318
void loadSnapshotWriters(final String outputDir)
QSimConfigGroup qsim()
Definition: Config.java:447
Here is the call graph for this function:

◆ prepare()

void org.matsim.run.Events2Snapshot.prepare ( )
private

Definition at line 187 of file Events2Snapshot.java.

References org.matsim.core.api.experimental.events.EventsManager.addHandler(), org.matsim.core.events.EventsUtils.createEventsManager(), org.matsim.core.config.groups.QSimConfigGroup.getSnapshotPeriod(), and org.matsim.core.config.Config.qsim().

Referenced by org.matsim.run.Events2Snapshot.run().

187  {
188  // create events
189  this.events = EventsUtils.createEventsManager();
190 
191  // create SnapshotGenerator
192  this.visualizer = new SnapshotGenerator(this.network, this.config.qsim().getSnapshotPeriod(),
193  this.config.qsim());
194  this.events.addHandler(this.visualizer);
195  }
void addHandler(final EventHandler handler)
QSimConfigGroup qsim()
Definition: Config.java:447
Here is the call graph for this function:

◆ addExternalSnapshotWriter()

void org.matsim.run.Events2Snapshot.addExternalSnapshotWriter ( final SnapshotWriter  writer)

Definition at line 197 of file Events2Snapshot.java.

References org.matsim.run.Events2Snapshot.writer.

197  {
198  this.writer = writer;
199  }

◆ loadSnapshotWriters()

void org.matsim.run.Events2Snapshot.loadSnapshotWriters ( final String  outputDir)
private

Definition at line 201 of file Events2Snapshot.java.

References org.matsim.core.events.algorithms.SnapshotGenerator.addSnapshotWriter(), org.matsim.core.config.Config.controller(), and org.matsim.core.config.groups.ControllerConfigGroup.getSnapshotFormat().

Referenced by org.matsim.run.Events2Snapshot.run().

201  {
202 
203  if (this.writer != null) {
205  }
206 
207  Collection<SnapshotFormat> snapshotFormats = this.config.controller().getSnapshotFormat();
208 
209  for( SnapshotFormat snapshotFormat : snapshotFormats ){
210  switch( snapshotFormat ){
211  case transims: {
212  String snapshotFile = outputDir + "T.veh";
213  this.visualizer.addSnapshotWriter(new TransimsSnapshotWriter(snapshotFile));
214  break; }
215  case googleearth:
216  // KML support removed, michalm, may'22
217  case otfvis:
218  // this was not filled in when I found it, but I think it should. kai, feb'20
219  case positionevents:
220  default:
221  throw new IllegalStateException( "Unexpected value: " + snapshotFormat );
222  }
223  }
224  }
final void addSnapshotWriter(final SnapshotWriter writer)
final ControllerConfigGroup controller()
Definition: Config.java:399
Here is the call graph for this function:

◆ main()

static void org.matsim.run.Events2Snapshot.main ( final String []  args)
static

Definition at line 226 of file Events2Snapshot.java.

References org.matsim.run.Events2Snapshot.run().

226  {
227  new Events2Snapshot().run(args);
228  }
Here is the call graph for this function:

Member Data Documentation

◆ config

Config org.matsim.run.Events2Snapshot.config = null
private

Definition at line 52 of file Events2Snapshot.java.

Referenced by org.matsim.run.Events2Snapshot.run().

◆ network

Network org.matsim.run.Events2Snapshot.network = null
private

Definition at line 53 of file Events2Snapshot.java.

Referenced by org.matsim.run.Events2Snapshot.run().

◆ events

EventsManager org.matsim.run.Events2Snapshot.events = null
private

Definition at line 54 of file Events2Snapshot.java.

◆ visualizer

SnapshotGenerator org.matsim.run.Events2Snapshot.visualizer = null
private

Definition at line 55 of file Events2Snapshot.java.

◆ configfile

String org.matsim.run.Events2Snapshot.configfile = null
private

Definition at line 56 of file Events2Snapshot.java.

◆ eventsfile

String org.matsim.run.Events2Snapshot.eventsfile
private

Definition at line 57 of file Events2Snapshot.java.

◆ writer

SnapshotWriter org.matsim.run.Events2Snapshot.writer = null
private

The documentation for this class was generated from the following file: