MATSIM
XY2Links.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * XY2Links.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2007, 2008 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.run;
22 
23 import java.util.Iterator;
24 
25 import org.matsim.core.config.Config;
35 
43 public class XY2Links {
44 
45  private Config config;
46  private String configfile = null;
47  private String plansfile = null;
48 
54  private void parseArguments(final String[] args) {
55  if (args.length == 0) {
56  System.out.println("Too few arguments.");
57  printUsage();
58  System.exit(1);
59  }
60  Iterator<String> argIter = new ArgumentParser(args).iterator();
61  String arg = argIter.next();
62  if (arg.equals("-h") || arg.equals("--help")) {
63  printUsage();
64  System.exit(0);
65  } else {
66  this.configfile = arg;
67  this.plansfile = argIter.next();
68  if (argIter.hasNext()) {
69  System.out.println("Too many arguments.");
70  printUsage();
71  System.exit(1);
72  }
73  }
74  }
75 
76  private void printUsage() {
77  System.out.println();
78  System.out.println("XY2Links");
79  System.out.println("Reads a plans-file and assignes each activity in each plan of each person");
80  System.out.println("a link based on the coordinates given in the activity. The modified plans/");
81  System.out.println("persons are then written out to file again.");
82  System.out.println();
83  System.out.println("usage: XY2Links [OPTIONS] configfile plansfile");
84  System.out.println(" The following parameters must be given in the config-file:");
85  System.out.println(" - network.inputNetworkFile");
86  System.out.println(" - plans.inputPlansFile");
87  System.out.println();
88  System.out.println("Options:");
89  System.out.println("-h, --help: Displays this message.");
90  System.out.println();
91  System.out.println("----------------");
92  System.out.println("2008, matsim.org");
93  System.out.println();
94  }
95 
100  public void run(final String[] args) {
101  parseArguments(args);
102  this.config = ConfigUtils.loadConfig(this.configfile);
103  MatsimRandom.reset(this.config.global().getRandomSeed());
104  MutableScenario scenario = ScenarioUtils.createMutableScenario(this.config);
105  new MatsimNetworkReader(scenario.getNetwork()).readFile(this.config.network().getInputFile());
106  this.config = scenario.getConfig();
107 
108  StreamingPopulationReader reader = new StreamingPopulationReader( scenario ) ;
109  final StreamingPopulationWriter plansWriter = new StreamingPopulationWriter();
110  plansWriter.startStreaming(this.plansfile);
111  reader.addAlgorithm(new org.matsim.core.population.algorithms.XY2Links(scenario));
112  reader.addAlgorithm(plansWriter);
113  reader.readFile(this.config.plans().getInputFile());
115  plansWriter.closeStreaming();
116 
117  System.out.println("done.");
118  }
119 
125  public static void main(final String[] args) {
126  new XY2Links().run(args);
127  }
128 
129 }
final NetworkConfigGroup network()
Definition: Config.java:411
static Config loadConfig(final String filename, ConfigGroup... customModules)
static MutableScenario createMutableScenario(final Config config)
static void printPlansCount(Population population)
final GlobalConfigGroup global()
Definition: Config.java:395