21 package org.matsim.counts.algorithms;
23 import java.io.BufferedWriter;
24 import java.io.FileWriter;
25 import java.io.IOException;
26 import java.text.DecimalFormat;
27 import java.text.NumberFormat;
28 import java.util.List;
29 import java.util.Locale;
31 import org.apache.logging.log4j.LogManager;
32 import org.apache.logging.log4j.Logger;
55 private static final String
NEWLINE =
"\n";
60 private static final String[]
COLUMNHEADERS = {
"Link Id",
"Count Station Id",
"Hour",
61 "MATSIM volumes",
"Count volumes",
"Relative Error",
"Normalized Relative Error",
"GEH"};
76 final List<CountSimComparison> countSimComparisons,
final Locale l) {
77 super(countSimComparisons);
79 this.numberFormat =
new DecimalFormat(
"#.############");
82 this.numberFormat = NumberFormat.getInstance(l);
84 this.numberFormat.setGroupingUsed(
false);
94 log.info(
"Writing CountsSimComparison to " + filename);
95 try (BufferedWriter out =
new BufferedWriter(
new FileWriter(filename))) {
97 out.write(COLUMNHEADERS[0]);
98 for (
int i = 1; i < COLUMNHEADERS.length; i++) {
100 out.write(COLUMNHEADERS[i]);
106 out.write(csc.getId().toString());
107 out.write(SEPARATOR);
108 out.write(csc.getCsId());
109 out.write(SEPARATOR);
110 out.write(Integer.toString(csc.getHour()));
111 out.write(SEPARATOR);
112 out.write(this.numberFormat.format(csc.getSimulationValue()));
113 out.write(SEPARATOR);
114 out.write(this.numberFormat.format(csc.getCountValue()));
115 out.write(SEPARATOR);
116 out.write(this.numberFormat.format(csc.calculateRelativeError()));
117 out.write(SEPARATOR);
118 out.write(this.numberFormat.format(csc.calculateNormalizedRelativeError()));
119 out.write(SEPARATOR);
120 out.write(this.numberFormat.format(csc.calculateGEHValue()));
123 }
catch (IOException e) {
133 String filename = file.substring(0, file.length() - 4) +
"AWTV.txt";
135 log.info(
"Writing 'average weekday traffic volume' to " + filename);
138 this.countComparisonFilter.getCountsForHour(null));
140 try (BufferedWriter out =
new BufferedWriter(
new FileWriter(filename))) {
141 out.write(
"Link Id");
142 out.write(SEPARATOR);
143 out.write(
"Count Station Id");
144 out.write(SEPARATOR);
145 out.write(
"MATSIM volumes");
146 out.write(SEPARATOR);
147 out.write(
"Count volumes");
148 out.write(SEPARATOR);
149 out.write(
"Normalized Relative Error");
156 final double nomRelError;
158 final double max = Math.max(simValue, countValue);
159 if (max == 0.0) nomRelError = 0;
160 else nomRelError = Math.abs(simValue - countValue) / max;
162 out.write(csc.getId().toString());
163 out.write(SEPARATOR);
164 out.write(csc.getCsId());
165 out.write(SEPARATOR);
166 out.write(this.numberFormat.format(simValue));
167 out.write(SEPARATOR);
168 out.write(this.numberFormat.format(countValue));
169 out.write(SEPARATOR);
170 out.write(this.numberFormat.format(nomRelError));
173 }
catch (IOException e) {
double getAggregatedSimValue(final Id< Link > linkfilter)
void writeFile(final String filename)
void writeAWTVTable(final String file)
static final String NEWLINE
CountSimComparisonTableWriter(final List< CountSimComparison > countSimComparisons, final Locale l)
static final String [] COLUMNHEADERS
static final String SEPARATOR
double getAggregatedCountValue(final Id< Link > linkfilter)
final NumberFormat numberFormat