From a75e3b03df6c948d12d03e38d817fab99f8335cd Mon Sep 17 00:00:00 2001 From: GunnarF Date: Mon, 12 Nov 2018 17:14:34 +0100 Subject: [PATCH] towards systematic injection of opdyts/matsim objective functions --- .../gunnar/ihop4/IHOP4ProductionRunner.java | 66 ++++--- .../AbstractTollZonePassageDataHandler.java | 2 +- .../PassageDataAnalyzer.java | 21 +-- .../PassageDataHandler.java | 14 +- .../SizeAnalysisHandler.java | 15 +- .../tollzonepassagedata/SizeAnalyzer.java | 33 ++-- .../TollZoneMeasurementReader.java | 165 ++++++++++++------ .../TollZonePassageDataSpecification.java | 2 - 8 files changed, 193 insertions(+), 125 deletions(-) diff --git a/stockholm/src/main/java/gunnar/ihop4/IHOP4ProductionRunner.java b/stockholm/src/main/java/gunnar/ihop4/IHOP4ProductionRunner.java index f00b2f77d55..de50a920012 100644 --- a/stockholm/src/main/java/gunnar/ihop4/IHOP4ProductionRunner.java +++ b/stockholm/src/main/java/gunnar/ihop4/IHOP4ProductionRunner.java @@ -29,13 +29,19 @@ import org.matsim.api.core.v01.population.Leg; import org.matsim.api.core.v01.population.Person; import org.matsim.api.core.v01.population.PlanElement; +import org.matsim.contrib.opdyts.buildingblocks.calibration.counting.AbsoluteLinkEntryCountDeviationObjectiveFunction; import org.matsim.contrib.pseudosimulation.searchacceleration.Greedo; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Controler; import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.controler.events.BeforeMobsimEvent; +import org.matsim.core.controler.listener.BeforeMobsimListener; import org.matsim.core.scenario.ScenarioUtils; +import gunnar.ihop4.tollzonepassagedata.TollZoneMeasurementReader; + /** * * @author Gunnar Flötteröd @@ -90,32 +96,48 @@ static void run(boolean useGreedo) { final Controler controler = new Controler(scenario); if (greedo != null) { controler.addOverridingModule(greedo); - // greedo.meet(controler); } // Toll zone link flows. - // final LinkFlowTimeSeries tollZoneFlows = new LinkFlowTimeSeries(new - // TimeDiscretization(0, 3600, 30)); - // tollZoneFlows.setLogFileName("tollZoneFlows.data"); - // for (String linkName : new String[] { "101350_NW", "112157_SE", "9216_N", - // "13354_W", "18170_SE", "35424_NW", - // "44566_NE", "51930_W", "53064_SE", "68760_SW", "74188_NW", "79555_NE", - // "90466_SE", "122017_NW", - // "122017_SE", "22626_W", "77626_W", "90317_W", "92866_E", "110210_E", - // "2453_SW", "6114_S", "6114_N", - // "25292_NE", "28480_S", "34743_NE", "124791_W", "71617_SW", "71617_SE", - // "80449_N", "96508_NW", - // "96508_SE", "108353_SE", "113763_NW", "121908_N", "121908_S", "52416_NE", - // "125425_N" }) { - // tollZoneFlows.addObservedLink(linkName); - // } - // controler.addOverridingModule(new AbstractModule() { - // @Override - // public void install() { - // this.addEventHandlerBinding().toInstance(tollZoneFlows); - // } - // }); + final TollZoneMeasurementReader measReader = new TollZoneMeasurementReader(config); + measReader.run(); + for (AbstractModule module : measReader.getAllDayMeasurements().getModules()) { + controler.addOverridingModule(module); + } + for (AbstractModule module : measReader.getOnlyTollTimeMeasurements().getModules()) { + controler.addOverridingModule(module); + } + + // Checking if this really works: + + final int testIteration = 10; + + BeforeMobsimListener testListener = new BeforeMobsimListener() { + @Override + public void notifyBeforeMobsim(BeforeMobsimEvent event) { + if (event.getIteration() == testIteration) { + for (AbsoluteLinkEntryCountDeviationObjectiveFunction objFct : measReader.getAllDayMeasurements().getObjectiveFunctions()) { + System.out.println(); + System.out.println(objFct); + } + for (AbsoluteLinkEntryCountDeviationObjectiveFunction objFct : measReader.getOnlyTollTimeMeasurements().getObjectiveFunctions()) { + System.out.println(); + System.out.println(objFct); + } + System.out.println(); + System.out.println("TERMINATING IN ITERATION " + event.getIteration()); + System.exit(0); + } + } + }; + + controler.addOverridingModule(new AbstractModule() { + @Override + public void install() { + this.addControlerListenerBinding().toInstance(testListener); + } + }); // ... and run. diff --git a/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/AbstractTollZonePassageDataHandler.java b/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/AbstractTollZonePassageDataHandler.java index 99f0af8d5aa..a1e47d75919 100644 --- a/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/AbstractTollZonePassageDataHandler.java +++ b/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/AbstractTollZonePassageDataHandler.java @@ -69,7 +69,7 @@ abstract class AbstractTollZonePassageDataHandler extends AbstractTabularFileHan @Override public final void startDataRow(String[] args) { - + this.time_s = null; this.chargingPointStr = null; this.linkStr = null; diff --git a/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/PassageDataAnalyzer.java b/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/PassageDataAnalyzer.java index 0fa5e8da326..4b04242c0db 100644 --- a/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/PassageDataAnalyzer.java +++ b/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/PassageDataAnalyzer.java @@ -36,24 +36,24 @@ * @author Gunnar Flötteröd * */ -public class PassageDataAnalyzer { +class PassageDataAnalyzer { private final DynamicData data; private final double[] weightPerVehicleLengthClass; - public PassageDataAnalyzer(final TimeDiscretization timeDiscr, final double[] weightPerVehicleLengthClass) { + PassageDataAnalyzer(final TimeDiscretization timeDiscr, final double[] weightPerVehicleLengthClass) { this.data = new DynamicData<>(timeDiscr); this.weightPerVehicleLengthClass = weightPerVehicleLengthClass; } - public void parse(final String file) { + void parse(final String file) { final TabularFileParser parser = new TabularFileParser(); parser.setDelimiterTags(new String[] { "," }); parser.setOmitEmptyColumns(false); - final PassageDataHandler handler = new PassageDataHandler(this.data, this.weightPerVehicleLengthClass, false); + final PassageDataHandler handler = new PassageDataHandler(this.data, this.weightPerVehicleLengthClass); try { parser.parse(file, handler); } catch (IOException e) { @@ -61,6 +61,10 @@ public void parse(final String file) { } } + DynamicData getData() { + return this.data; + } + @Override public String toString() { final StringBuffer result = new StringBuffer(); @@ -80,19 +84,16 @@ public String toString() { } return result.toString(); } - - public DynamicData getData() { - return this.data; - } public static void main(String[] args) throws IOException { - final TimeDiscretization timeDiscr = new TimeDiscretization(0, 3600, 24); + final TimeDiscretization timeDiscr = new TimeDiscretization(0, 3600 / 2, 24 * 2); final List days = Arrays.asList("2016-10-11", "2016-10-12", "2016-10-13", "2016-10-18", "2016-10-19", "2016-10-20", "2016-10-25", "2016-10-26", "2016-10-27"); - PassageDataAnalyzer dataAnalyzer = new PassageDataAnalyzer(timeDiscr, null); + PassageDataAnalyzer dataAnalyzer = new PassageDataAnalyzer(timeDiscr, + new double[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}); for (String day : days) { for (String postfix : new String[] { "-01", "-02" }) { diff --git a/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/PassageDataHandler.java b/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/PassageDataHandler.java index ef93357c5a8..9c1dd3d2fd7 100644 --- a/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/PassageDataHandler.java +++ b/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/PassageDataHandler.java @@ -32,30 +32,24 @@ class PassageDataHandler extends AbstractTollZonePassageDataHandler { private final double[] weightPerMeterLengthClass; - private final boolean includeChargingPointId; - - PassageDataHandler(final DynamicData data, final double[] weightPerMeterLengthClass, - final boolean includeChargingPointId) { + PassageDataHandler(final DynamicData data, final double[] weightPerMeterLengthClass) { this.data = data; this.weightPerMeterLengthClass = weightPerMeterLengthClass; - this.includeChargingPointId = includeChargingPointId; } @Override protected void processFields() { - final String key = this.linkStr + (this.includeChargingPointId ? "(" + this.chargingPointStr + ")" : ""); - if (this.containsRegisterData) { if (this.registerDataFeasible) { - this.data.add(key, this.data.bin((int) this.time_s), 1.0); + this.data.add(super.linkStr, this.data.bin((int) this.time_s), 1.0); } } else { // contains no register data -> weight by length class int lengthClass = this.vehicleLength_cm / 100; if (lengthClass < this.weightPerMeterLengthClass.length) { - this.data.add(key, this.data.bin((int) this.time_s), this.weightPerMeterLengthClass[lengthClass]); + this.data.add(super.linkStr, this.data.bin((int) this.time_s), + this.weightPerMeterLengthClass[lengthClass]); } } } - } diff --git a/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/SizeAnalysisHandler.java b/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/SizeAnalysisHandler.java index 32693192776..2cf1c117211 100644 --- a/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/SizeAnalysisHandler.java +++ b/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/SizeAnalysisHandler.java @@ -26,29 +26,26 @@ */ class SizeAnalysisHandler extends AbstractTollZonePassageDataHandler { - private final int[] totalVehiclesPerMeterLengthClass; private final int[] relevantIdentifiedVehiclesPerMeterLengthClass; private final int[] identifiedVehiclesPerMeterLengthClass; - SizeAnalysisHandler(final int[] totalVehiclesPerMeterLengthClass, final int[] relevantVehiclesPerMeterLengthClass, + SizeAnalysisHandler(final int[] relevantIdentifiedVehiclesPerMeterLengthClass, final int[] identifiedVehiclesPerMeterLengthClass) { - this.totalVehiclesPerMeterLengthClass = totalVehiclesPerMeterLengthClass; - this.relevantIdentifiedVehiclesPerMeterLengthClass = relevantVehiclesPerMeterLengthClass; + this.relevantIdentifiedVehiclesPerMeterLengthClass = relevantIdentifiedVehiclesPerMeterLengthClass; this.identifiedVehiclesPerMeterLengthClass = identifiedVehiclesPerMeterLengthClass; } @Override protected void processFields() { - final int lengthClass = this.vehicleLength_cm / 100; - if ((lengthClass < 0) || (lengthClass >= this.totalVehiclesPerMeterLengthClass.length)) { + final int lengthClass = super.vehicleLength_cm / 100; + if ((lengthClass < 0) || (lengthClass >= this.identifiedVehiclesPerMeterLengthClass.length)) { return; } - this.totalVehiclesPerMeterLengthClass[lengthClass]++; - if (this.containsRegisterData) { + if (super.containsRegisterData) { this.identifiedVehiclesPerMeterLengthClass[lengthClass]++; - if (this.registerDataFeasible) { + if (super.registerDataFeasible) { this.relevantIdentifiedVehiclesPerMeterLengthClass[lengthClass]++; } } diff --git a/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/SizeAnalyzer.java b/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/SizeAnalyzer.java index 9ab472f081a..454f6759151 100644 --- a/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/SizeAnalyzer.java +++ b/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/SizeAnalyzer.java @@ -32,56 +32,51 @@ * @author Gunnar Flötteröd * */ -public class SizeAnalyzer { +class SizeAnalyzer { - private final int[] totalVehiclesPerMeterLengthClass; private final int[] relevantIdentifiedVehiclesPerMeterLengthClass; private final int[] identifiedVehiclesPerMeterLengthClass; - public SizeAnalyzer(final int maxLength_m) { - this.totalVehiclesPerMeterLengthClass = new int[maxLength_m]; + SizeAnalyzer(final int maxLength_m) { this.relevantIdentifiedVehiclesPerMeterLengthClass = new int[maxLength_m]; this.identifiedVehiclesPerMeterLengthClass = new int[maxLength_m]; } - public void parse(final String file) { + void parse(final String file) { final TabularFileParser parser = new TabularFileParser(); parser.setDelimiterTags(new String[] { "," }); parser.setOmitEmptyColumns(false); - final SizeAnalysisHandler handler = new SizeAnalysisHandler(this.totalVehiclesPerMeterLengthClass, - this.relevantIdentifiedVehiclesPerMeterLengthClass, this.identifiedVehiclesPerMeterLengthClass); + final SizeAnalysisHandler handler = new SizeAnalysisHandler(this.relevantIdentifiedVehiclesPerMeterLengthClass, + this.identifiedVehiclesPerMeterLengthClass); try { parser.parse(file, handler); } catch (IOException e) { throw new RuntimeException(e); } } - - public double[] getRelevantProbaPerMeterLengthClass() { - final double[] result = new double[this.totalVehiclesPerMeterLengthClass.length]; - for (int i = 0; i < this.totalVehiclesPerMeterLengthClass.length; i++) { + + double[] getRelevanceProbabilityPerMeterLengthClass() { + final double[] result = new double[this.identifiedVehiclesPerMeterLengthClass.length]; + for (int i = 0; i < this.identifiedVehiclesPerMeterLengthClass.length; i++) { final double relevantIdentified = this.relevantIdentifiedVehiclesPerMeterLengthClass[i]; final double identified = this.identifiedVehiclesPerMeterLengthClass[i]; if (identified > 0) { - result[i] = relevantIdentified / identified; + result[i] = relevantIdentified / identified; } - } return result; } @Override public String toString() { - final double[] relevantProba = this.getRelevantProbaPerMeterLengthClass(); - final StringBuffer result = new StringBuffer("length[m]\ttotal\tidentified\trelevantIdentified\tP(relevant)\n"); - for (int i = 0; i < this.totalVehiclesPerMeterLengthClass.length; i++) { - final int total = this.totalVehiclesPerMeterLengthClass[i]; + final double[] relevantProba = this.getRelevanceProbabilityPerMeterLengthClass(); + final StringBuffer result = new StringBuffer("length[m]\tidentified\trelevantIdentified\tPr(relevant)\n"); + for (int i = 0; i < this.identifiedVehiclesPerMeterLengthClass.length; i++) { final int relevantIdentified = this.relevantIdentifiedVehiclesPerMeterLengthClass[i]; final int identified = this.identifiedVehiclesPerMeterLengthClass[i]; - result.append(i + "\t" + total + "\t" + identified + "\t" + relevantIdentified + "\t" - + (((double) relevantIdentified) / identified) + "\t" + relevantProba[i] + "\n"); + result.append(i + "\t" + identified + "\t" + relevantIdentified + "\t" + relevantProba[i] + "\n"); } return result.toString(); } diff --git a/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/TollZoneMeasurementReader.java b/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/TollZoneMeasurementReader.java index 9f571d01b48..83df58b43ee 100644 --- a/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/TollZoneMeasurementReader.java +++ b/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/TollZoneMeasurementReader.java @@ -28,10 +28,13 @@ import java.util.Set; import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.network.Network; +import org.matsim.api.core.v01.network.Link; +import org.matsim.contrib.opdyts.buildingblocks.calibration.counting.AbsoluteLinkEntryCountDeviationObjectiveFunction; import org.matsim.contrib.opdyts.buildingblocks.calibration.counting.CountMeasurementSpecification; import org.matsim.contrib.opdyts.buildingblocks.calibration.counting.CountMeasurements; +import org.matsim.contrib.opdyts.buildingblocks.calibration.counting.Filter; import org.matsim.core.config.Config; +import org.matsim.vehicles.Vehicle; import floetteroed.utilities.DynamicData; import floetteroed.utilities.TimeDiscretization; @@ -43,7 +46,49 @@ */ public class TollZoneMeasurementReader { - static void replaceByInterpolation(final DynamicData data, final int interpolateTime_s) { + // -------------------- CONSTANTS -------------------- + + private final String pathStr; + + private final Config config; + + private final int maxVehicleLength_m; + + private final TimeDiscretization allDayTimeDiscr; + + private final TimeDiscretization tollTimeOnlyTimeDiscr; + + private final List days; + + // -------------------- MEMBERS -------------------- + + private CountMeasurements allDayMeasurements = null; + + private CountMeasurements onlyTollTimeMeasurements = null; + + // -------------------- CONSTRUCTION -------------------- + + public TollZoneMeasurementReader(final String path, final Config config, final int maxVehicleLength_m, + final TimeDiscretization allDayTimeDiscr, final TimeDiscretization tollTimeOnlyTimeDiscr, + final List days) { + this.pathStr = path; + this.config = config; + this.maxVehicleLength_m = maxVehicleLength_m; + this.allDayTimeDiscr = allDayTimeDiscr; + this.tollTimeOnlyTimeDiscr = tollTimeOnlyTimeDiscr; + this.days = days; + } + + public TollZoneMeasurementReader(final Config config) { + this("/Users/GunnarF/NoBackup/data-workspace/ihop4/2016-10-xx_passagedata", config, 20, + new TimeDiscretization(0, 1800, 48), new TimeDiscretization(6 * 3600 + 30 * 60, 1800, 24), + Arrays.asList("2016-10-11", "2016-10-12", "2016-10-13", "2016-10-18", "2016-10-19", "2016-10-20", + "2016-10-25", "2016-10-26", "2016-10-27")); + } + + // -------------------- IMPLEMENTATION -------------------- + + private void replaceByInterpolation(final DynamicData data, final int interpolateTime_s) { int bin = data.bin(interpolateTime_s); for (String key : data.keySet()) { final double prevValue = data.getBinValue(key, bin - 1); @@ -52,7 +97,7 @@ static void replaceByInterpolation(final DynamicData data, final int int } } - static Set keysWithDataOutsideOfTollTime(final DynamicData data, final int tollStart_s, + private Set keysWithDataOutsideOfTollTime(final DynamicData data, final int tollStart_s, final int tollEnd_s) { final Set result = new LinkedHashSet<>(); for (int bin = 0; bin < data.bin(tollStart_s); bin++) { @@ -72,38 +117,27 @@ static Set keysWithDataOutsideOfTollTime(final DynamicData data, return result; } - static CountMeasurements loadLinkStr2countMeas(final Config config) { - - final int maxVehicleLength_m = 20; + public void run() { - final TimeDiscretization allDayTimeDiscr = new TimeDiscretization(0, 1800, 48); - final TimeDiscretization tollTimeOnlyTimeDiscr = new TimeDiscretization(6 * 3600 + 30 * 60, 1800, 24); - final int guaranteedBeforeToll_s = 6 * 3600; - final int guaranteedAfterToll_s = 19 * 3600; - - final List days = Arrays.asList("2016-10-11", "2016-10-12", "2016-10-13", "2016-10-18", "2016-10-19", - "2016-10-20", "2016-10-25", "2016-10-26", "2016-10-27"); - - final List files = new ArrayList<>(days.size() * 2); - for (String day : days) { + final List files = new ArrayList<>(this.days.size() * 2); + for (String day : this.days) { for (String postfix : new String[] { "-01", "-02" }) { - final Path path = Paths.get("/Users/GunnarF/NoBackup/data-workspace/ihop4/2016-10-xx_passagedata", - "wsp-passages-vtr-" + day + postfix + ".csv"); + final Path path = Paths.get(this.pathStr, "wsp-passages-vtr-" + day + postfix + ".csv"); files.add(path.toString()); } } - final SizeAnalyzer sizeAnalyzer = new SizeAnalyzer(maxVehicleLength_m); + final SizeAnalyzer sizeAnalyzer = new SizeAnalyzer(this.maxVehicleLength_m); for (String file : files) { - System.out.println(file); + System.out.println("size analysis: " + file); sizeAnalyzer.parse(file); } System.out.println(sizeAnalyzer.toString()); - final PassageDataAnalyzer dataAnalyzer = new PassageDataAnalyzer(allDayTimeDiscr, - sizeAnalyzer.getRelevantProbaPerMeterLengthClass()); + final PassageDataAnalyzer dataAnalyzer = new PassageDataAnalyzer(this.allDayTimeDiscr, + sizeAnalyzer.getRelevanceProbabilityPerMeterLengthClass()); for (String file : files) { - System.out.println(file); + System.out.println("passage analysis: " + file); dataAnalyzer.parse(file); } System.out.println(dataAnalyzer.toString()); @@ -112,51 +146,78 @@ static CountMeasurements loadLinkStr2countMeas(final Config config) { replaceByInterpolation(dataAnalyzer.getData(), 18 * 3600 + 45 * 60); System.out.println(dataAnalyzer.toString()); - for (String key : keysWithDataOutsideOfTollTime(dataAnalyzer.getData(), 6 * 3600, 19 * 3600)) { - System.out.print(key + "\t"); - } - System.out.println(); - // CREATION OF ACTUAL SENSOR DATA - final CountMeasurements measurements = new CountMeasurements(config); + this.allDayMeasurements = new CountMeasurements(this.config); + this.onlyTollTimeMeasurements = new CountMeasurements(this.config); final DynamicData allData = dataAnalyzer.getData(); + final Set linksWithDataOutsideOfTollTime = keysWithDataOutsideOfTollTime(allData, 6 * 3600, 19 * 3600); for (String linkStr : allData.keySet()) { - // TODO CONTINUE HERE + final TimeDiscretization singleSensorTimeDiscr; + if (linksWithDataOutsideOfTollTime.contains(linkStr)) { + singleSensorTimeDiscr = this.allDayTimeDiscr; + } else { + singleSensorTimeDiscr = this.tollTimeOnlyTimeDiscr; + } - final double[] singleSensorData = new double[allDayTimeDiscr.getBinCnt()]; - for (int bin = 0; bin < allDayTimeDiscr.getBinCnt(); bin++) { - singleSensorData[bin] = allData.getBinValue(linkStr, bin); + final CountMeasurementSpecification spec = new CountMeasurementSpecification(singleSensorTimeDiscr, + new Filter>() { + @Override + public boolean test(Id arg0) { + return true; + } + }, new LinkedHashSet>(Arrays.asList(Id.createLinkId(linkStr)))); + + final double[] singleSensorData = new double[singleSensorTimeDiscr.getBinCnt()]; + for (int singleSensorTimeBin = 0; singleSensorTimeBin < singleSensorTimeDiscr + .getBinCnt(); singleSensorTimeBin++) { + final int allDayTimeBin = this.allDayTimeDiscr + .getBin(singleSensorTimeDiscr.getBinCenterTime_s(singleSensorTimeBin)); + singleSensorData[singleSensorTimeBin] = allData.getBinValue(linkStr, allDayTimeBin); } - CountMeasurementSpecification spec = new CountMeasurementSpecification(Id.createLinkId(linkStr), null, - null); - - measurements.addMeasurement(spec, singleSensorData); - - // if (linksWithAllDayData.contains(linkStr)) { - // linkStr2countMeas.put(linkStr, new CountMeasurement(singleSensorData, - // allDayTimeDiscr)); - // } else { - // final DiscretizationChanger discretizationChanger = new - // DiscretizationChanger(allDayTimeDiscr, - // singleSensorData, DiscretizationChanger.DataType.TOTALS); - // discretizationChanger.run(tollTimeOnlyTimeDiscr); - // linkStr2countMeas.put(linkStr, - // new CountMeasurement(discretizationChanger.getToTotalsCopy(), - // tollTimeOnlyTimeDiscr)); - // } + if (linksWithDataOutsideOfTollTime.contains(linkStr)) { + this.allDayMeasurements.addMeasurement(spec, singleSensorData); + } else { + this.onlyTollTimeMeasurements.addMeasurement(spec, singleSensorData); + } } - return measurements; + this.allDayMeasurements.build(); + this.onlyTollTimeMeasurements.build(); + } + + public CountMeasurements getAllDayMeasurements() { + return this.allDayMeasurements; } + public CountMeasurements getOnlyTollTimeMeasurements() { + return this.onlyTollTimeMeasurements; + } + + + public static void main(String[] args) { - loadLinkStr2countMeas(null); + TollZoneMeasurementReader reader = new TollZoneMeasurementReader(null); + reader.run(); + + System.out.println("\nALL-DAY SENSORS"); + for (AbsoluteLinkEntryCountDeviationObjectiveFunction objFct : reader.getAllDayMeasurements() + .getObjectiveFunctions()) { + System.out.println(objFct.getSpecification().getLinks() + ": " + objFct.getSpecification().getTimeDiscretization()); + } + + System.out.println("\nONLY-TOLL SENSORS"); + for (AbsoluteLinkEntryCountDeviationObjectiveFunction objFct : reader.getOnlyTollTimeMeasurements() + .getObjectiveFunctions()) { + System.out.println(objFct.getSpecification().getLinks() + ": " + objFct.getSpecification().getTimeDiscretization()); + } + + System.out.println("DONE"); } diff --git a/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/TollZonePassageDataSpecification.java b/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/TollZonePassageDataSpecification.java index 8b946a77d65..ba0fa2f5653 100644 --- a/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/TollZonePassageDataSpecification.java +++ b/stockholm/src/main/java/gunnar/ihop4/tollzonepassagedata/TollZonePassageDataSpecification.java @@ -21,9 +21,7 @@ import java.util.Collections; import java.util.LinkedHashMap; -import java.util.LinkedHashSet; import java.util.Map; -import java.util.Set; /** *