MATSIM
NetworkCleaner.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * NetworkCleaner.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 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.api.core.v01.Scenario;
32 
39 public class NetworkCleaner {
40 
41  private void printUsage() {
42  System.out.println();
43  System.out.println("NetworkCleaner");
44  System.out.println("Reads a network-file and \"cleans\" it. Currently, it performs the following");
45  System.out.println("steps to ensure a network is suited for simulation:");
46  System.out.println(" - ensure every link can be reached by every other link. It looks for the");
47  System.out.println(" biggest cluster of connected nodes and links and removes all other elements.");
48  System.out.println();
49  System.out.println("usage: NetworkCleaner [OPTIONS] input-network-file output-network-file");
50  System.out.println();
51  System.out.println("Options:");
52  System.out.println("-h, --help: Displays this message.");
53  System.out.println();
54  System.out.println("----------------");
55  System.out.println("2008, matsim.org");
56  System.out.println();
57  }
58 
65  public void run(final String inputNetworkFile, final String outputNetworkFile) {
67  final Network network = scenario.getNetwork();
68  new MatsimNetworkReader(scenario.getNetwork()).readFile(inputNetworkFile);
69 
71 
72  new NetworkWriter(network).write(outputNetworkFile);
73  }
74 
81  public void run(final String[] args) {
82  if (args.length == 0) {
83  System.out.println("Too few arguments.");
84  printUsage();
85  System.exit(1);
86  }
87  Iterator<String> argIter = new ArgumentParser(args).iterator();
88  String arg = argIter.next();
89  if (arg.equals("-h") || arg.equals("--help")) {
90  printUsage();
91  System.exit(0);
92  } else {
93  String inputFile = arg;
94  if (!argIter.hasNext()) {
95  System.out.println("Too few arguments.");
96  printUsage();
97  System.exit(1);
98  }
99  String outputFile = argIter.next();
100  if (argIter.hasNext()) {
101  System.out.println("Too many arguments.");
102  printUsage();
103  System.exit(1);
104  }
105  run(inputFile, outputFile);
106  }
107  }
108 
109  public static void main(String[] args) {
110  new NetworkCleaner().run(args);
111  }
112 
113 }
void run(final String inputNetworkFile, final String outputNetworkFile)
void write(final String filename)
static void main(String[] args)
void run(final String[] args)
static Scenario createScenario(final Config config)
static Config createConfig(final String context)