diff --git a/contribs/minibus/src/test/java/org/matsim/contrib/minibus/integration/PControlerTestIT.java b/contribs/minibus/src/test/java/org/matsim/contrib/minibus/integration/PControlerTestIT.java index ecbc79cef88..3429d672745 100644 --- a/contribs/minibus/src/test/java/org/matsim/contrib/minibus/integration/PControlerTestIT.java +++ b/contribs/minibus/src/test/java/org/matsim/contrib/minibus/integration/PControlerTestIT.java @@ -94,9 +94,9 @@ public final void testPControler() { filesToCheckFor.add(outputPath + scenarioName + ".0.actsFromParatransitUsers.txt"); filesToCheckFor.add(outputPath + scenarioName + ".pOperatorLogger.txt"); filesToCheckFor.add(outputPath + scenarioName + ".pStats.txt"); - filesToCheckFor.add(outputPath + scenarioName + ".scorestats.txt"); + filesToCheckFor.add(outputPath + scenarioName + ".scorestats.csv"); filesToCheckFor.add(outputPath + scenarioName + ".stopwatch.csv"); - filesToCheckFor.add(outputPath + scenarioName + ".traveldistancestats.txt"); + filesToCheckFor.add(outputPath + scenarioName + ".traveldistancestats.csv"); filesToCheckFor.add(outputPath + scenarioName + ".pStat_light.gexf.gz"); filesToCheckFor.add(outputPath + scenarioName + ".pStat.gexf.gz"); diff --git a/contribs/minibus/src/test/java/org/matsim/contrib/minibus/integration/SubsidyContextTestIT.java b/contribs/minibus/src/test/java/org/matsim/contrib/minibus/integration/SubsidyContextTestIT.java index 716a6bc481e..f9881ed715e 100644 --- a/contribs/minibus/src/test/java/org/matsim/contrib/minibus/integration/SubsidyContextTestIT.java +++ b/contribs/minibus/src/test/java/org/matsim/contrib/minibus/integration/SubsidyContextTestIT.java @@ -85,7 +85,7 @@ public final void testDefaultPControler() { filesToCheckFor.add(utils.getOutputDirectory() + "pStats.txt"); filesToCheckFor.add(utils.getOutputDirectory() + "scorestats.csv"); filesToCheckFor.add(utils.getOutputDirectory() + "stopwatch.csv"); - filesToCheckFor.add(utils.getOutputDirectory() + "traveldistancestats.txt"); + filesToCheckFor.add(utils.getOutputDirectory() + "traveldistancestats.csv"); filesToCheckFor.add(utils.getOutputDirectory() + "pStat_light.gexf.gz"); filesToCheckFor.add(utils.getOutputDirectory() + "pStat.gexf.gz"); @@ -147,7 +147,7 @@ public final void testSubsidyPControler() { filesToCheckFor.add(utils.getOutputDirectory() + "pStats.txt"); filesToCheckFor.add(utils.getOutputDirectory() + "scorestats.csv"); filesToCheckFor.add(utils.getOutputDirectory() + "stopwatch.csv"); - filesToCheckFor.add(utils.getOutputDirectory() + "traveldistancestats.txt"); + filesToCheckFor.add(utils.getOutputDirectory() + "traveldistancestats.csv"); filesToCheckFor.add(utils.getOutputDirectory() + "pStat_light.gexf.gz"); filesToCheckFor.add(utils.getOutputDirectory() + "pStat.gexf.gz"); diff --git a/contribs/minibus/src/test/java/org/matsim/contrib/minibus/integration/SubsidyTestIT.java b/contribs/minibus/src/test/java/org/matsim/contrib/minibus/integration/SubsidyTestIT.java index 9eb7d1a1331..98107c2c0d0 100644 --- a/contribs/minibus/src/test/java/org/matsim/contrib/minibus/integration/SubsidyTestIT.java +++ b/contribs/minibus/src/test/java/org/matsim/contrib/minibus/integration/SubsidyTestIT.java @@ -86,7 +86,7 @@ public final void testSubsidyPControler() { filesToCheckFor.add(utils.getOutputDirectory() + "pStats.txt"); filesToCheckFor.add(utils.getOutputDirectory() + "scorestats.csv"); filesToCheckFor.add(utils.getOutputDirectory() + "stopwatch.csv"); - filesToCheckFor.add(utils.getOutputDirectory() + "traveldistancestats.txt"); + filesToCheckFor.add(utils.getOutputDirectory() + "traveldistancestats.csv"); filesToCheckFor.add(utils.getOutputDirectory() + "pStat_light.gexf.gz"); filesToCheckFor.add(utils.getOutputDirectory() + "pStat.gexf.gz"); diff --git a/matsim/src/main/java/org/matsim/analysis/TravelDistanceStats.java b/matsim/src/main/java/org/matsim/analysis/TravelDistanceStats.java index 7387cb0536d..30be4f51e02 100644 --- a/matsim/src/main/java/org/matsim/analysis/TravelDistanceStats.java +++ b/matsim/src/main/java/org/matsim/analysis/TravelDistanceStats.java @@ -28,6 +28,7 @@ import org.matsim.api.core.v01.population.Plan; import org.matsim.core.config.Config; import org.matsim.core.config.groups.ControllerConfigGroup; +import org.matsim.core.config.groups.GlobalConfigGroup; import org.matsim.core.controler.OutputDirectoryHierarchy; import org.matsim.core.router.TripStructureUtils; import org.matsim.core.router.TripStructureUtils.Trip; @@ -59,9 +60,10 @@ public class TravelDistanceStats { private final ControllerConfigGroup controllerConfigGroup; - final private BufferedWriter out; - final private String legStatsPngName; - final private String tripStatsPngName; + private final BufferedWriter out; + private final String legStatsPngName; + private final String tripStatsPngName; + private final String delimiter; private double[] legStatsHistory = null; private double[] tripStatsHistory = null; @@ -69,10 +71,12 @@ public class TravelDistanceStats { private final static Logger log = LogManager.getLogger(TravelDistanceStats.class); @Inject - TravelDistanceStats(ControllerConfigGroup controllerConfigGroup, OutputDirectoryHierarchy controlerIO) { + TravelDistanceStats(ControllerConfigGroup controllerConfigGroup, OutputDirectoryHierarchy controlerIO, GlobalConfigGroup globalConfig) { this(controllerConfigGroup, controlerIO.getOutputFilename("traveldistancestats"), controlerIO.getOutputFilename("traveldistancestats") + "legs", - controlerIO.getOutputFilename("traveldistancestats") + "trips", controllerConfigGroup.isCreateGraphs()); + controlerIO.getOutputFilename("traveldistancestats") + "trips", + controllerConfigGroup.isCreateGraphs(), + globalConfig.getDefaultDelimiter()); } /** @@ -80,15 +84,16 @@ public class TravelDistanceStats { * @param createPNG true if in every iteration, the distance statistics should be visualized in a graph and written to disk. * @throws UncheckedIOException */ - public TravelDistanceStats(final Config config, final String filename, final boolean createPNG) throws UncheckedIOException { - this(config.controller(), filename, filename + "legs", filename + "trips", createPNG); + public TravelDistanceStats(final Config config, final String filename, final boolean createPNG, final String delimiter) throws UncheckedIOException { + this(config.controller(), filename, filename + "legs", filename + "trips", createPNG, delimiter); } - private TravelDistanceStats(ControllerConfigGroup controllerConfigGroup, String travelDistanceStatsFileName, - String legStatsPngName, String tripStatsPngName, boolean createPNG) { + private TravelDistanceStats(ControllerConfigGroup controllerConfigGroup, String travelDistanceStatsFileName, + String legStatsPngName, String tripStatsPngName, boolean createPNG, String delimiter) { this.controllerConfigGroup = controllerConfigGroup; this.legStatsPngName = legStatsPngName; this.tripStatsPngName = tripStatsPngName; + this.delimiter = delimiter; if (createPNG) { int iterations = controllerConfigGroup.getLastIteration() - controllerConfigGroup.getFirstIteration(); if (iterations > 5000) { @@ -97,13 +102,13 @@ private TravelDistanceStats(ControllerConfigGroup controllerConfigGroup, String this.legStatsHistory = new double[iterations+1]; this.tripStatsHistory = new double[iterations+1]; } - if (travelDistanceStatsFileName.toLowerCase(Locale.ROOT).endsWith(".txt")) { + if (travelDistanceStatsFileName.toLowerCase(Locale.ROOT).endsWith(".csv")) { this.out = IOUtils.getBufferedWriter(travelDistanceStatsFileName); } else { - this.out = IOUtils.getBufferedWriter(travelDistanceStatsFileName + ".txt"); + this.out = IOUtils.getBufferedWriter(travelDistanceStatsFileName + ".csv"); } try { - this.out.write("ITERATION\tavg. Average Leg distance\tavg. Average Trip distance\n"); + this.out.write("ITERATION" + this.delimiter + "avg. Average Leg distance" + this.delimiter + "avg. Average Trip distance\n"); } catch (IOException e) { throw new UncheckedIOException(e); } @@ -149,7 +154,7 @@ public void addIteration(int iteration, IdMap map) { log.info("(and teleported legs whose route contains a distance.)");// TODO: still valid? try { - this.out.write(iteration + "\t" + legStats.getAverage() + "\t" + tripStats.getAverage() + "\t" + "\n"); + this.out.write(iteration + this.delimiter + legStats.getAverage() + this.delimiter + tripStats.getAverage() + this.delimiter + "\n"); this.out.flush(); } catch (IOException e) { e.printStackTrace(); diff --git a/matsim/src/test/java/org/matsim/analysis/TravelDistanceStatsTest.java b/matsim/src/test/java/org/matsim/analysis/TravelDistanceStatsTest.java index 627ba72c840..e1e0a8fb0d2 100644 --- a/matsim/src/test/java/org/matsim/analysis/TravelDistanceStatsTest.java +++ b/matsim/src/test/java/org/matsim/analysis/TravelDistanceStatsTest.java @@ -23,6 +23,7 @@ import org.matsim.api.core.v01.population.Route; import org.matsim.core.config.groups.ControllerConfigGroup; import org.matsim.core.config.groups.ControllerConfigGroup.CompressionType; +import org.matsim.core.config.groups.GlobalConfigGroup; import org.matsim.core.controler.OutputDirectoryHierarchy; import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; import org.matsim.core.population.PopulationUtils; @@ -35,9 +36,9 @@ */ public class TravelDistanceStatsTest { - HashMap person3modes = new HashMap(); - HashMap person1modes = new HashMap(); - HashMap person2modes = new HashMap(); + HashMap person3modes = new HashMap<>(); + HashMap person1modes = new HashMap<>(); + HashMap person2modes = new HashMap<>(); private int avglegdis; private int avgtripdis; private Double person1legsum; @@ -342,7 +343,7 @@ private void performTest(IdMap map, String outputDirectory) { controllerConfigGroup.setCreateGraphs(true); controllerConfigGroup.setFirstIteration(0); controllerConfigGroup.setLastIteration(10); - TravelDistanceStats travelDistanceStats = new TravelDistanceStats(controllerConfigGroup, controlerIO); + TravelDistanceStats travelDistanceStats = new TravelDistanceStats(controllerConfigGroup, controlerIO, new GlobalConfigGroup()); travelDistanceStats.addIteration(0, map); readAndValidateValues(0, person1legsum + person2legsum + person3legsum, 12, person1TotalNumberOfLegs + person2TotalNumberOfLegs + person3TotalNumberOfLegs); @@ -357,22 +358,23 @@ private void performTest(IdMap map, String outputDirectory) { private void readAndValidateValues(int itr, Double legSum, int totalTrip, long totalLeg) { - String file = utils.getOutputDirectory() + "/TravelDistanceStat" + "/traveldistancestats.txt"; + String file = utils.getOutputDirectory() + "/TravelDistanceStat" + "/traveldistancestats.csv"; BufferedReader br; String line; try { br = new BufferedReader(new FileReader(file)); String firstRow = br.readLine(); - String[] columnNames = firstRow.split(" "); + String delimiter = new GlobalConfigGroup().getDefaultDelimiter(); + String[] columnNames = firstRow.split(delimiter); decideColumns(columnNames); int iteration = 0; while ((line = br.readLine()) != null) { if (iteration == itr) { - String[] column = line.split(" "); + String[] column = line.split(delimiter); // checking if column number in greater than 0, because 0th column is always // 'Iteration' and we don't need that --> see decideColumns() method - Double avgLegvalue = (avglegdis > 0) ? Double.valueOf(column[avglegdis]) : 0; - Double avgTripvalue = (avgtripdis > 0) ? Double.valueOf(column[avgtripdis]) : 0; + double avgLegvalue = (avglegdis > 0) ? Double.parseDouble(column[avglegdis]) : 0; + double avgTripvalue = (avgtripdis > 0) ? Double.parseDouble(column[avgtripdis]) : 0; Assert.assertEquals("avg. Average Trip distance does not match", (legSum / totalTrip), avgTripvalue, 0); @@ -384,7 +386,6 @@ private void readAndValidateValues(int itr, Double legSum, int totalTrip, long t iteration++; } } catch (IOException e) { - // TODO Auto-generated catch block e.printStackTrace(); }