public KMZPtCountSimComparisonWriter(final Controler controler) { this.controler = controler; // load data net = controler.getScenario().getNetwork(); MatsimCountsReader reader = new MatsimCountsReader(occupCounts); reader.readFile(controler.getConfig().ptCounts().getOccupancyCountsFileName()); scalefactor = controler.getConfig().ptCounts().getCountsScaleFactor(); reader = null; // M }
public static void main(String args[]) throws IOException { String countsInFile = "/Volumes/johannes/sge/prj/fpd/data/counts/counts.2014.net20140909.5.24h.xml"; String countsOutFile = "/Users/johannes/gsv/fpd/telefonica/032016/analysis/20160623/countIds.xml"; String mappingFile = "/Volumes/johannes/sge/prj/fpd/data/counts/counts2014-directions.csv"; Counts<Link> counts = new Counts(); MatsimCountsReader countsReader = new MatsimCountsReader(counts); countsReader.readFile(countsInFile); BufferedReader txtReader = new BufferedReader(new FileReader(mappingFile)); String line = txtReader.readLine(); Map<String, Record> records = new HashMap<>(); while ((line = txtReader.readLine()) != null) { String[] tokens = line.split("\t"); String id = tokens[1]; String name = tokens[2]; double kfzR1 = parseDouble(tokens[15]); double kfzR2 = parseDouble(tokens[16]); double svR1 = parseDouble(tokens[18]); double svR2 = parseDouble(tokens[19]); Record record = new Record(); record.id = id; record.name = name; record.pkwR1 = kfzR1 - svR1; record.pkwR2 = kfzR2 - svR2; if (records.containsKey(record.name)) { logger.warn(String.format("Entry for %s already exists - removing both.", record.name)); records.remove(record.name); } else { records.put(record.name, record); } } Set<Count> remove = new HashSet<>(); for (Count<Link> count : counts.getCounts().values()) { Record record = records.get(count.getCsLabel()); if (record != null) { double pkwR1_h = record.pkwR1 / 24.0; double pkwR2_h = record.pkwR2 / 24.0; double diffR1 = Math.abs(pkwR1_h - count.getVolume(1).getValue()); double diffR2 = Math.abs(pkwR2_h - count.getVolume(1).getValue()); if (diffR1 < diffR2) { if (diffR1 > 10) { logger.warn(String.format("Difference %s is greater than 10.", diffR1)); } count.setCsId(record.id + "_R1"); } else { if (diffR2 > 10) { logger.warn(String.format("Difference %s is greater than 10.", diffR2)); } count.setCsId(record.id + "_R2"); } } else { logger.warn(String.format("No count station with name %s found.", count.getCsLabel())); remove.add(count); } } for (Count<Link> count : remove) { counts.getCounts().remove(count.getId()); } CountsWriter writer = new CountsWriter(counts); writer.write(countsOutFile); }