diff --git a/contribs/application/test/input/org/matsim/smallScaleCommercialTrafficGeneration/config_demand.xml b/contribs/application/test/input/org/matsim/smallScaleCommercialTrafficGeneration/config_demand.xml index 67f61c5ca74..31f7045a0d8 100644 --- a/contribs/application/test/input/org/matsim/smallScaleCommercialTrafficGeneration/config_demand.xml +++ b/contribs/application/test/input/org/matsim/smallScaleCommercialTrafficGeneration/config_demand.xml @@ -407,24 +407,6 @@ - - - - - - - - - - - - - - - - - - diff --git a/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/CadytsBuilderImplGT.java b/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/CadytsBuilderImplGT.java deleted file mode 100644 index 1165c45aed3..00000000000 --- a/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/CadytsBuilderImplGT.java +++ /dev/null @@ -1,87 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * * - * *********************************************************************** * - * * - * copyright : (C) 2012 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -package org.matsim.contrib.cadyts.pt; - -import java.util.Map; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.matsim.api.core.v01.Id; -import org.matsim.contrib.cadyts.general.CadytsBuilderImpl; -import org.matsim.contrib.cadyts.general.LookUpItemFromId; -import org.matsim.core.config.Config; -import org.matsim.counts.Count; -import org.matsim.counts.Counts; -import org.matsim.counts.Volume; - -import cadyts.calibrators.analytical.AnalyticalCalibrator; -import cadyts.measurements.SingleLinkMeasurement; - -/** - * @author nagel - * @author mrieser - */ -public final class CadytsBuilderImplGT { - // yyyy why "GT"? Is this a typo and should have been PT (or Pt, to be consistent with other classes)? kai, feb'20 - - // yy I also don't know where and when this is used to I am commenting it out to see if someone complains. kai, feb'20 - -// private static Logger log = LogManager.getLogger( CadytsBuilderImplGT.class ) ; -// -// private CadytsBuilderImplGT(){} // do not instantiate -// -// public static AnalyticalCalibrator buildCalibratorAndAddMeasurements(final Config config, final Counts occupCounts, -// LookUpItemFromId lookUp, Class idType ) { -// -// if (occupCounts.getCounts().size() == 0) { -// log.warn("Counts container is empty."); -// } -// -// AnalyticalCalibrator matsimCalibrator = CadytsBuilderImpl.buildCalibrator(config); -// -// //add counts data into calibrator -// int numberOfAddedMeasurements = 0 ; -// for (Map.Entry, Count> entry : occupCounts.getCounts().entrySet()) { -// // (loop over all counting "items" (usually locations/stations) -// -// T item = lookUp.getItem(Id.create(entry.getKey(), idType)) ; -// if ( item==null ) { -// throw new RuntimeException("item is null; entry=" + entry + " idType=" + idType ) ; -// } -// -// double sum = 0; -// for (Volume volume : entry.getValue().getVolumes().values()){ -// // (loop over the different time slots) -// sum += volume.getValue() ; -// } -// numberOfAddedMeasurements++ ; -// matsimCalibrator.addMeasurement(item, 0, 86400, sum, SingleLinkMeasurement.TYPE.COUNT_VEH ); -// } -// -// if ( numberOfAddedMeasurements==0 ) { -// log.warn("No measurements were added."); -// } -// -// if ( matsimCalibrator.getProportionalAssignment() ) { -// throw new RuntimeException("Gunnar says that this may not work so do not set to true. kai, sep'14") ; -// } -// return matsimCalibrator; -// } -} diff --git a/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/CadytsPtContext.java b/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/CadytsPtContext.java deleted file mode 100644 index e1f918c4ac1..00000000000 --- a/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/CadytsPtContext.java +++ /dev/null @@ -1,265 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * * - * *********************************************************************** * - * * - * copyright : (C) 2013 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -package org.matsim.contrib.cadyts.pt; - -import java.io.IOException; -import java.util.HashSet; -import java.util.Set; - -import jakarta.inject.Inject; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.matsim.analysis.IterationStopWatch; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Network; -import org.matsim.api.core.v01.population.Person; -import org.matsim.contrib.cadyts.general.CadytsBuilderImpl; -import org.matsim.contrib.cadyts.general.CadytsConfigGroup; -import org.matsim.contrib.cadyts.general.CadytsContextI; -import org.matsim.contrib.cadyts.general.CadytsCostOffsetsXMLFileIO; -import org.matsim.contrib.cadyts.general.PlansTranslator; -import org.matsim.core.api.experimental.events.EventsManager; -import org.matsim.core.config.Config; -import org.matsim.core.config.groups.PtCountsConfigGroup; -import org.matsim.core.controler.OutputDirectoryHierarchy; -import org.matsim.core.controler.events.AfterMobsimEvent; -import org.matsim.core.controler.events.BeforeMobsimEvent; -import org.matsim.core.controler.events.IterationEndsEvent; -import org.matsim.core.controler.events.StartupEvent; -import org.matsim.core.controler.listener.AfterMobsimListener; -import org.matsim.core.controler.listener.BeforeMobsimListener; -import org.matsim.core.controler.listener.IterationEndsListener; -import org.matsim.core.controler.listener.StartupListener; -import org.matsim.core.utils.geometry.CoordinateTransformation; -import org.matsim.core.utils.geometry.transformations.TransformationFactory; -import org.matsim.counts.Counts; -import org.matsim.counts.MatsimCountsReader; -import org.matsim.pt.transitSchedule.api.TransitLine; -import org.matsim.pt.transitSchedule.api.TransitRoute; -import org.matsim.pt.transitSchedule.api.TransitRouteStop; -import org.matsim.pt.transitSchedule.api.TransitStopFacility; - -import cadyts.calibrators.analytical.AnalyticalCalibrator; -import cadyts.measurements.SingleLinkMeasurement.TYPE; -import cadyts.supply.SimResults; - -/** - * @author nagel - * - */ -public class CadytsPtContext implements StartupListener, IterationEndsListener, BeforeMobsimListener, AfterMobsimListener, -CadytsContextI { - // can be/remain public as long as constructor is package-private. kai, feb'20 - - private final static Logger log = LogManager.getLogger(CadytsPtContext.class); - - private final static String LINKOFFSET_FILENAME = "linkCostOffsets.xml"; - private static final String FLOWANALYSIS_FILENAME = "flowAnalysis.txt"; - private static final String OCCUPANCYANALYSIS_FILENAME = "cadytsPtOccupancyAnalysis.txt"; - - private AnalyticalCalibrator calibrator = null; - private final SimResults simResults; - private final Counts occupCounts = new Counts<>(); - // private final Counts boardCounts = new Counts(); - // private final Counts alightCounts = new Counts(); - private final CadytsPtOccupancyAnalyzerI cadytsPtOccupAnalyzer; - private PtPlanToPlanStepBasedOnEvents ptStep ; - - private CadytsConfigGroup cadytsConfig; - private EventsManager events; - private Scenario scenario; - private OutputDirectoryHierarchy controlerIO; - private IterationStopWatch stopWatch; - - @Inject - CadytsPtContext(final Config config, EventsManager events, Scenario scenario, OutputDirectoryHierarchy controlerIO, - IterationStopWatch stopWatch, final CadytsPtOccupancyAnalyzerI cadytsPtOccupancyAnalyzer ) { - this.events = events; - this.scenario = scenario; - this.controlerIO = controlerIO; - this.stopWatch = stopWatch; - cadytsConfig = (CadytsConfigGroup) config.getModule(CadytsConfigGroup.GROUP_NAME); - this.cadytsPtOccupAnalyzer = cadytsPtOccupancyAnalyzer ; - - // === prepare the structure which extracts the measurements from the simulation: - // since there is already some other method, we just need to write a wrapper. - -// this.cadytsPtOccupAnalyzer = new CadytsPtOccupancyAnalyzer(CadytsPtOccupancyAnalyzer.toTransitLineIdSet(cadytsConfig.getCalibratedItems()), cadytsConfig.getTimeBinSize() ); - events.addHandler(this.cadytsPtOccupAnalyzer); - - this.simResults = new SimResults() { - private static final long serialVersionUID = 1L; - @Override - public double getSimValue(TransitStopFacility stop, int startTime_s, int endTime_s, TYPE type) { - final int timeBinSize_s = cadytsConfig.getTimeBinSize() ; - final double countsScaleFactor = config.ptCounts().getCountsScaleFactor() ; - double retval = 0. ; - switch ( type ) { - case COUNT_VEH: - retval = cadytsPtOccupAnalyzer.getOccupancyVolumeForStopAndTime(stop.getId(), startTime_s) * countsScaleFactor ; - break; - case FLOW_VEH_H: - int multiple = timeBinSize_s / 3600 ; // e.g. "3" when timeBinSize_s = 3*3600 = 10800 - retval = cadytsPtOccupAnalyzer.getOccupancyVolumeForStopAndTime(stop.getId(), startTime_s) * countsScaleFactor / multiple ; - break; - default: - throw new RuntimeException("not implemented ...") ; - } -// if ( retval != 0. ) { -// log.warn("retval=" + retval ); -// } - return retval ; - } - @Override - public String toString() { - return cadytsPtOccupAnalyzer.toString() ; - } - } ; - // === end wrapper === - - } - - @Override - public void notifyStartup(StartupEvent event) { - - // === prepare the calibrator by giving measurements to it: - String occupancyCountsFilename = scenario.getConfig().ptCounts().getOccupancyCountsFileName(); - new MatsimCountsReader(this.occupCounts).readFile(occupancyCountsFilename); - - // === build the calibrator: - this.calibrator = CadytsBuilderImpl.buildCalibratorAndAddMeasurements(scenario.getConfig(), this.occupCounts, new TransitStopFacilityLookUp(scenario) , TransitStopFacility.class); - - // === find out which plan is contributing what to each measurement: - this.ptStep = new PtPlanToPlanStepBasedOnEvents<>(scenario, CadytsPtOccupancyAnalyzer.toTransitLineIdSet(cadytsConfig.getCalibratedLines())); - events.addHandler(ptStep); - } - - @Override - public void notifyBeforeMobsim(final BeforeMobsimEvent event) { - this.cadytsPtOccupAnalyzer.reset(event.getIteration()); - for (Person person : scenario.getPopulation().getPersons().values()) { - this.calibrator.addToDemand(ptStep.getCadytsPlan(person.getSelectedPlan())); - } - } - - @Override - public void notifyAfterMobsim(final AfterMobsimEvent event) { - int it = event.getIteration(); - - // Get all stations of all analyzed lines and invoke the method write to get all information of them - Set> stopIds = new HashSet<>(); - for ( String pseudoLineId : this.cadytsConfig.getCalibratedLines()) { - Id lineId = Id.create(pseudoLineId, TransitLine.class); - TransitLine line = scenario.getTransitSchedule().getTransitLines().get(lineId); - for (TransitRoute route : line.getRoutes().values()) { - for (TransitRouteStop stop : route.getStops()) { - stopIds.add(stop.getStopFacility().getId()); - } - } - } - String outFile = controlerIO.getIterationFilename(it, OCCUPANCYANALYSIS_FILENAME); - this.cadytsPtOccupAnalyzer.writeResultsForSelectedStopIds(outFile, this.occupCounts, stopIds); - } - - @Override - public void notifyIterationEnds(final IterationEndsEvent event) { - if (cadytsConfig.isWriteAnalysisFile()) { - String analysisFilepath = controlerIO.getIterationFilename(event.getIteration(), FLOWANALYSIS_FILENAME); - this.calibrator.setFlowAnalysisFile(analysisFilepath); - } - - this.calibrator.afterNetworkLoading(this.simResults); - - // write some output - String filename = controlerIO.getIterationFilename(event.getIteration(), LINKOFFSET_FILENAME); - try { - new CadytsCostOffsetsXMLFileIO<>(new TransitStopFacilityLookUp(scenario), TransitStopFacility.class) - .write(filename, this.calibrator.getLinkCostOffsets()); - } catch (IOException e) { - log.error("Could not write link cost offsets!", e); - } - - generateAndWriteCountsComparisons(event); - } - - // =========================================================================================================================== - // private methods & pure delegate methods only below this line - - private void generateAndWriteCountsComparisons(final IterationEndsEvent event) { - if ( this.cadytsConfig.getTimeBinSize()!=3600 ) { - log.warn("generateAndWriteCountsComparisons() does not work when time bin size != 3600. See comments in code. Skipping the comparison ..." ) ; - return ; - // yyyy there are some conceptual problems behind this which are not resolved: - // () There should reasonably be two methods: one describing what cadyts _thinks_ it is comparing, and one that just - // compares the output. There is one methods writing simCountCompare..., and then this one here - // writing cadytsSimCountCompare... . It is not clarified which one is doing which. - // () The method that just compares the output should not rely on cadyts but compute its own observations. -- - // Unfortunately, this collides with the fact that the time bin size is part of the cadyts configuration. This is, in the end, a - // consequence of the fact that the Counts format assumes hourly counts (other than cadyts, which reasonably allows the - // specify the time span for every observation separately). - // kai, feb'13 - } - - - PtCountsConfigGroup ptCountsConfig = scenario.getConfig().ptCounts(); - if (ptCountsConfig.getOccupancyCountsFileName() == null) { // yyyy this check should reasonably also be done in isActiveInThisIteration. kai,oct'10 - log.warn("generateAndWriteCountsComparisons() does not work since occupancy counts file name not given ") ; - return ; - } - int iter = event.getIteration(); - - stopWatch.beginOperation("compare with pt counts"); - - Network network = scenario.getNetwork(); - CadytsPtCountsComparisonAlgorithm ccaOccupancy = new CadytsPtCountsComparisonAlgorithm(this.cadytsPtOccupAnalyzer, - this.occupCounts, network, scenario.getConfig().ptCounts().getCountsScaleFactor()); - - Double distanceFilter = ptCountsConfig.getDistanceFilter(); - String distanceFilterCenterNodeId = ptCountsConfig.getDistanceFilterCenterNode(); - if ((distanceFilter != null) && (distanceFilterCenterNodeId != null)) { - ccaOccupancy.setDistanceFilter(distanceFilter, distanceFilterCenterNodeId); - } - - ccaOccupancy.calculateComparison(); - - String outputFormat = ptCountsConfig.getOutputFormat(); - if (outputFormat.contains("txt") || outputFormat.contains("all")) { - // As far as I can tell, this file is written twice, the other times without the "cadyts" part. kai, feb'13 - // yyyyyy As far as I can tell, the version here is wrong as soon as the time bin is different from 3600.--?? kai, feb'13 - // See near beginning of method. kai, feb'13 - ccaOccupancy.write(controlerIO.getIterationFilename(iter, "cadytsSimCountCompareOccupancy.txt")); - } - - stopWatch.endOperation("compare with pt counts"); - } - - @Override - public AnalyticalCalibrator getCalibrator() { - return calibrator; - } - - @Override - public PlansTranslator getPlansTranslator() { - return ptStep; - } - -} diff --git a/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/CadytsPtCountsComparisonAlgorithm.java b/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/CadytsPtCountsComparisonAlgorithm.java deleted file mode 100644 index 6327a98260f..00000000000 --- a/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/CadytsPtCountsComparisonAlgorithm.java +++ /dev/null @@ -1,185 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * * - * *********************************************************************** * - * * - * copyright : (C) 2012 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -package org.matsim.contrib.cadyts.pt; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.matsim.api.core.v01.Coord; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Identifiable; -import org.matsim.api.core.v01.network.Network; -import org.matsim.api.core.v01.network.Node; -import org.matsim.core.utils.geometry.CoordUtils; -import org.matsim.counts.Count; -import org.matsim.counts.CountSimComparison; -import org.matsim.counts.CountSimComparisonImpl; -import org.matsim.counts.Counts; -import org.matsim.counts.Volume; -import org.matsim.pt.counts.SimpleWriter; - -/** - * This is a modified copy of CountsComparisonAlgorithm, in order to realize the same functionality - * for pt counts. - */ -final class CadytsPtCountsComparisonAlgorithm { - /** - * The StopAttributes of the simulation - */ - private final CadytsPtOccupancyAnalyzerI oa; - /** - * The counts object - */ - Counts counts; - // needed in CadytsErrorPlot - - /** - * The result list - */ - private final List countSimComp; - - private Node distanceFilterNode = null; - - private Double distanceFilter = null; - - private final Network network; - - double countsScaleFactor; // needed in CadytsErrorPlot - - final static Logger log = LogManager.getLogger(CadytsPtCountsComparisonAlgorithm.class); - - StringBuffer content = new StringBuffer(); - - CadytsPtCountsComparisonAlgorithm(final CadytsPtOccupancyAnalyzerI oa, final Counts counts, final Network network, final double countsScaleFactor) { - this.oa = oa; - this.counts = counts; - this.countSimComp = new ArrayList(); - this.network = network; - this.countsScaleFactor = countsScaleFactor; - } - - /** - * Creates the List with the counts vs sim values stored in the countAttribute Attribute of this - * class. - */ - final String STR_NOVOLUMES = "No volumes for stop: "; - final String STR_STOPID = "StopId :\t"; - final String STR_HEAD = "\nhour\tsimVal\tscaledSimVal\tcountVal\n"; - final char CHR_HT = '\t'; - final char CHR_NL = '\n'; - - public void calculateComparison() { - double countValue; - for (Count count : this.counts.getCounts().values()) { - Id stopId = count.getId(); - if (!isInRange(count.getCoord())) { - continue; - } - int[] volumes = this.getVolumesForStop(stopId); - if (volumes == null) { - log.warn(this.STR_NOVOLUMES + stopId); - continue; - } else /* volumes!=null */if (volumes.length == 0) { - log.warn(this.STR_NOVOLUMES + stopId); - continue; - } - - this.content.append(this.STR_STOPID); - this.content.append(stopId.toString()); - this.content.append(this.STR_HEAD); - - for (int hour = 1; hour <= volumes.length; hour++) { - // real volumes: - Volume volume = count.getVolume(hour); - if (volume != null) { - - this.content.append(hour); - this.content.append(this.CHR_HT); - - countValue = volume.getValue(); - double simValue = volumes[hour - 1]; - - this.content.append(simValue); - this.content.append(this.CHR_HT); - - simValue *= this.countsScaleFactor; - - this.content.append(simValue); - this.content.append(this.CHR_HT); - this.content.append(countValue); - this.content.append(this.CHR_NL); - - this.countSimComp.add(new CountSimComparisonImpl(stopId, hour, countValue, simValue)); - - } else { - countValue = 0.0; - } - - } - } - } - - int[] getVolumesForStop(final Id stopId) { - return this.oa.getOccupancyVolumesForStop(stopId); - } - - /** - * - * @param stopCoord - * @return true if the Link with the given Id is not farther away than the - * distance specified by the distance filter from the center node of the filter. - */ - boolean isInRange(final Coord stopCoord) { - if ((this.distanceFilterNode == null) || (this.distanceFilter == null)) { - return true; - } - - double dist = CoordUtils.calcEuclideanDistance(stopCoord, this.distanceFilterNode.getCoord()); - return dist < this.distanceFilter.doubleValue(); - } - - /** - * - * @return the result list - */ - public List getComparison() { - return this.countSimComp; - } - - /** - * Set a distance filter, dropping everything out which is not in the distance given in meters - * around the given Node Id. - * - * @param distance - * @param nodeId - */ - public void setDistanceFilter(final Double distance, final String nodeId) { - this.distanceFilter = distance; - this.distanceFilterNode = this.network.getNodes().get(Id.create(nodeId, Node.class)); - } - - public void write(final String outputFilename) { - final SimpleWriter simpleWriter = new SimpleWriter(outputFilename); - simpleWriter.write(this.content.toString()); - simpleWriter.close(); - } -} diff --git a/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/CadytsPtModule.java b/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/CadytsPtModule.java deleted file mode 100644 index d9f459047b3..00000000000 --- a/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/CadytsPtModule.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.matsim.contrib.cadyts.pt; - - -import org.matsim.core.controler.AbstractModule; - -import jakarta.inject.Singleton; - -public class CadytsPtModule extends AbstractModule { - @Override - public void install() { - bind(CadytsPtContext.class).in( Singleton.class ); - addControlerListenerBinding().to(CadytsPtContext.class); - bind(CadytsPtOccupancyAnalyzerI.class).to(CadytsPtOccupancyAnalyzer.class); - } -} diff --git a/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/CadytsPtOccupancyAnalyzer.java b/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/CadytsPtOccupancyAnalyzer.java deleted file mode 100644 index c116c652e0c..00000000000 --- a/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/CadytsPtOccupancyAnalyzer.java +++ /dev/null @@ -1,299 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * * - * *********************************************************************** * - * * - * copyright : (C) 2012 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -package org.matsim.contrib.cadyts.pt; - -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; - -import jakarta.inject.Inject; - -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.events.PersonEntersVehicleEvent; -import org.matsim.api.core.v01.events.PersonLeavesVehicleEvent; -import org.matsim.api.core.v01.events.TransitDriverStartsEvent; -import org.matsim.api.core.v01.network.Link; -import org.matsim.contrib.cadyts.general.CadytsConfigGroup; -import org.matsim.core.api.experimental.events.VehicleArrivesAtFacilityEvent; -import org.matsim.core.api.experimental.events.VehicleDepartsAtFacilityEvent; -import org.matsim.core.config.Config; -import org.matsim.core.config.ConfigUtils; -import org.matsim.core.utils.misc.Time; -import org.matsim.counts.Count; -import org.matsim.counts.Counts; -import org.matsim.counts.Volume; -import org.matsim.pt.counts.SimpleWriter; -import org.matsim.pt.transitSchedule.api.TransitLine; -import org.matsim.pt.transitSchedule.api.TransitStopFacility; -import org.matsim.vehicles.Vehicle; - -/** - * Collects occupancy data of transit-line stations - *

- * This is probably similar to code elsewhere. However, it makes some sense to keep this here since the correct workings of cadyts - * (obviously) depends on the fact that the counts are actually what it thinks, and so it makes sense to decouple this from the upstream - * counting method and leave it here. kai, sep'13 - */ -final class CadytsPtOccupancyAnalyzer implements CadytsPtOccupancyAnalyzerI { - // can be/remain public as long as constructor is package-private. kai, feb'20 - - private final int timeBinSize, maxSlotIndex; - private final double maxTime; - private Map, int[]> occupancies; // Map< stopFacilityId,value[]> - private final Map, Id> vehStops = new HashMap<>(); // Map< vehId,stopFacilityId> - private final Map, Integer> vehPassengers = new HashMap<>(); // Map - private StringBuffer occupancyRecord = new StringBuffer("time\tvehId\tStopId\tno.ofPassengersInVeh\n"); - private final Set analyzedTransitDrivers = new HashSet<>(); - private final Set analyzedTransitVehicles = new HashSet<>(); - private final Set> calibratedLines; - - @Inject - CadytsPtOccupancyAnalyzer( Config config ) { - CadytsConfigGroup ccc = ConfigUtils.addOrGetModule(config, CadytsConfigGroup.class ) ; - - this.calibratedLines = toTransitLineIdSet( ccc.getCalibratedLines() ) ; - this.timeBinSize = ccc.getTimeBinSize() ; - - this.maxTime = Time.MIDNIGHT-1; //24 * 3600 - 1; - // (yy not completely clear if it might be better to use 24*this.timeBimSize, but it is overall not so great - // to have this hardcoded. kai/manuel, jul'12) - - this.maxSlotIndex = ((int) this.maxTime) / this.timeBinSize + 1; - this.occupancies = new HashMap<>(); - } - - @Override - public void reset(final int iteration) { - this.occupancies.clear(); - this.vehStops.clear(); - this.vehPassengers.clear(); - this.occupancyRecord = new StringBuffer("time\tvehId\tStopId\tno.ofPassengersInVeh\n"); - this.analyzedTransitDrivers.clear(); - this.analyzedTransitVehicles.clear(); - } - - @Override - public void handleEvent(final TransitDriverStartsEvent event) { - if (this.calibratedLines.contains(event.getTransitLineId())) { - this.analyzedTransitDrivers.add(event.getDriverId()); - this.analyzedTransitVehicles.add(event.getVehicleId()); - } - } - - @Override - public void handleEvent(final PersonEntersVehicleEvent event) { - if (this.analyzedTransitDrivers.contains(event.getPersonId()) || !this.analyzedTransitVehicles.contains(event.getVehicleId())) { - return; // ignore transit drivers or persons entering non-(analyzed-)transit vehicles - } - - // ------------------veh_passenger- (for occupancy)----------------- - Id vehId = event.getVehicleId(); - Id stopId = this.vehStops.get(vehId); - double time = event.getTime(); - Integer nPassengers = this.vehPassengers.get(vehId); - this.vehPassengers.put(vehId, (nPassengers != null) ? (nPassengers + 1) : 1); - this.occupancyRecord.append("time :\t").append(time).append(" veh :\t").append(vehId).append(" has Passenger\t").append(this.vehPassengers.get(vehId)).append(" \tat stop :\t").append(stopId).append(" ENTERING PERSON :\t").append(event.getPersonId()).append("\n"); - } - - @Override - public void handleEvent(final PersonLeavesVehicleEvent event) { - if (this.analyzedTransitDrivers.contains(event.getPersonId()) || !this.analyzedTransitVehicles.contains(event.getVehicleId())) { - return; // ignore transit drivers or persons entering non-(analyzed-)transit vehicles - } - - // ----------------veh_passenger-(for occupancy)-------------------------- - Id vehId = event.getVehicleId(); - double time = event.getTime(); - Integer nPassengers = this.vehPassengers.get(vehId); - if (nPassengers == null) { - throw new RuntimeException("null passenger-No. in vehicle ?"); - } - this.vehPassengers.put(vehId, nPassengers - 1); - if (this.vehPassengers.get(vehId) == 0) { - this.vehPassengers.remove(vehId); - } - Integer passengers = this.vehPassengers.get(vehId); - this.occupancyRecord.append("time :\t").append(time).append(" veh :\t").append(vehId).append(" has Passenger\t").append((passengers != null) ? passengers : 0).append("\n"); - } - - @Override - public void handleEvent(final VehicleDepartsAtFacilityEvent event) { - Id vehId = event.getVehicleId(); - Id facId = event.getFacilityId(); - - // -----------------------occupancy-------------------------------- - this.vehStops.remove(vehId); - int[] occupancyAtStop = this.occupancies.get(facId); - if (occupancyAtStop == null) { // no previous departure from this stop, therefore no occupancy - // record yet. Create this: - occupancyAtStop = new int[this.maxSlotIndex + 1]; - this.occupancies.put(facId, occupancyAtStop); - } - - Integer noPassengersInVeh = this.vehPassengers.get(vehId); - - if (noPassengersInVeh != null) { - occupancyAtStop[this.getTimeSlotIndex(event.getTime())] += noPassengersInVeh; - this.occupancyRecord.append(event.getTime()); - this.occupancyRecord.append("\t"); - this.occupancyRecord.append(vehId); - this.occupancyRecord.append("\t"); - this.occupancyRecord.append(facId); - this.occupancyRecord.append("\t"); - this.occupancyRecord.append(noPassengersInVeh); - this.occupancyRecord.append("\n"); - } - } - - @Override - public void handleEvent(final VehicleArrivesAtFacilityEvent event) { - Id stopId = event.getFacilityId(); - - this.vehStops.put(event.getVehicleId(), stopId); - // (constructing a table with vehId as key, and stopId as value; constructed when veh arrives at - // stop; necessary - // since personEnters/LeavesVehicle does not carry stop id) - } - - private int getTimeSlotIndex(final double time) { - if (time > this.maxTime) { - return this.maxSlotIndex; - } - return ((int) time / this.timeBinSize); - } - - /** - * @param stopId - * @return Array containing the number of passengers in bus after the transfer at the stop - * {@code stopId} per time bin, starting with time bin 0 from 0 seconds to - * (timeBinSize-1)seconds. - */ - @Override - public int[] getOccupancyVolumesForStop(final Id stopId) { - return this.occupancies.get(stopId); - } - /* (non-Javadoc) - * @see org.matsim.contrib.cadyts.pt.CadytsPtOccupancyAnalyzerI#getOccupancyVolumeForStopAndTime(org.matsim.api.core.v01.Id, int) - */ - @Override - public int getOccupancyVolumeForStopAndTime(final Id stopId, final int time_s ) { - if ( this.occupancies.get(stopId) != null ) { - int timeBinIndex = getTimeSlotIndex( time_s ) ; - return this.occupancies.get(stopId)[timeBinIndex] ; - } else { - return 0 ; - } - } - - public Set> getOccupancyStopIds() { - return this.occupancies.keySet(); - } - - @Override - public void writeResultsForSelectedStopIds(final String filename, final Counts occupCounts, final Collection> stopIds) { - SimpleWriter writer = new SimpleWriter(filename); - - final String TAB = "\t"; - final String NL = "\n"; - - // write header - writer.write("stopId\t"); - for (int i = 0; i < 24; i++) { - writer.write("oc" + i + "-" + (i + 1) + TAB); - } - for (int i = 0; i < 24; i++) { - writer.write("scalSim" + i + "-" + (i + 1) + TAB); - } - writer.write("coordinate\tcsId\n"); - - // write content - for (Id stopId : stopIds) { - // get count data - Count count = occupCounts.getCounts().get(Id.create(stopId, TransitStopFacility.class)); - if (!occupCounts.getCounts().containsKey(Id.create(stopId, TransitStopFacility.class))) { - continue; - } - - // get sim-Values - int[] ocuppancy = this.occupancies.get(stopId); - writer.write(stopId.toString() + TAB); - for (int i = 0; i < ocuppancy.length; i++) { - Volume v = count.getVolume(i + 1); - if (v != null) { - writer.write(v.getValue() + TAB); - } else { - writer.write("n/a" + TAB); - } - } - for (int anOcuppancy : ocuppancy) { - writer.write((anOcuppancy) + TAB); - } - writer.write(count.getCoord().toString() + TAB + count.getCsLabel() + NL); - } - writer.write(this.occupancyRecord.toString()); - writer.close(); - } - - @Override - public String toString() { - final StringBuilder stringBuffer2 = new StringBuilder(); - final String STOPID = "stopId: "; - final String VALUES = "; values:"; - final char TAB = '\t'; - final char RETURN = '\n'; - - for (Id stopId : this.getOccupancyStopIds()) { // Only occupancy! - StringBuilder stringBuffer = new StringBuilder(); - stringBuffer.append(STOPID); - stringBuffer.append(stopId); - stringBuffer.append(VALUES); - - boolean hasValues = false; // only prints stops with volumes > 0 - int[] values = this.getOccupancyVolumesForStop(stopId); - - for (int value : values) { - hasValues = hasValues || (value > 0); - - stringBuffer.append(TAB); - stringBuffer.append(value); - } - stringBuffer.append(RETURN); - if (hasValues) - stringBuffer2.append(stringBuffer.toString()); - - } - return stringBuffer2.toString(); - } - - public static Set> toTransitLineIdSet(Set list) { - Set> converted = new LinkedHashSet<>(); - - for ( String id : list) { - converted.add(Id.create(id, TransitLine.class)); - } - - return converted; - } - - -} diff --git a/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/CadytsPtOccupancyAnalyzerI.java b/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/CadytsPtOccupancyAnalyzerI.java deleted file mode 100644 index 069fe358fd9..00000000000 --- a/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/CadytsPtOccupancyAnalyzerI.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.matsim.contrib.cadyts.pt; - -import java.util.Collection; - -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.events.handler.PersonEntersVehicleEventHandler; -import org.matsim.api.core.v01.events.handler.PersonLeavesVehicleEventHandler; -import org.matsim.api.core.v01.events.handler.TransitDriverStartsEventHandler; -import org.matsim.api.core.v01.network.Link; -import org.matsim.core.api.experimental.events.handler.VehicleArrivesAtFacilityEventHandler; -import org.matsim.core.api.experimental.events.handler.VehicleDepartsAtFacilityEventHandler; -import org.matsim.counts.Counts; -import org.matsim.pt.transitSchedule.api.TransitStopFacility; - -public interface CadytsPtOccupancyAnalyzerI extends TransitDriverStartsEventHandler, PersonEntersVehicleEventHandler, -PersonLeavesVehicleEventHandler, VehicleArrivesAtFacilityEventHandler, VehicleDepartsAtFacilityEventHandler { - - int getOccupancyVolumeForStopAndTime(Id stopId, int time_s); - - void writeResultsForSelectedStopIds(String filename, Counts occupCounts, Collection> stopIds); - - int[] getOccupancyVolumesForStop(Id stopId); - -} diff --git a/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/PtPlanToPlanStepBasedOnEvents.java b/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/PtPlanToPlanStepBasedOnEvents.java deleted file mode 100644 index f9ab329ad5a..00000000000 --- a/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/PtPlanToPlanStepBasedOnEvents.java +++ /dev/null @@ -1,238 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * * - * *********************************************************************** * - * * - * copyright : (C) 2012 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -package org.matsim.contrib.cadyts.pt; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.events.PersonEntersVehicleEvent; -import org.matsim.api.core.v01.events.PersonLeavesVehicleEvent; -import org.matsim.api.core.v01.events.TransitDriverStartsEvent; -import org.matsim.api.core.v01.events.handler.PersonEntersVehicleEventHandler; -import org.matsim.api.core.v01.events.handler.PersonLeavesVehicleEventHandler; -import org.matsim.api.core.v01.events.handler.TransitDriverStartsEventHandler; -import org.matsim.api.core.v01.population.Person; -import org.matsim.api.core.v01.population.Plan; -import org.matsim.contrib.cadyts.general.PlansTranslator; -import org.matsim.core.api.experimental.events.VehicleDepartsAtFacilityEvent; -import org.matsim.core.api.experimental.events.handler.VehicleDepartsAtFacilityEventHandler; -import org.matsim.core.scenario.MutableScenario; -import org.matsim.pt.transitSchedule.api.TransitLine; -import org.matsim.pt.transitSchedule.api.TransitSchedule; -import org.matsim.pt.transitSchedule.api.TransitStopFacility; - -import cadyts.demand.PlanBuilder; - -/*package*/ class PtPlanToPlanStepBasedOnEvents implements TransitDriverStartsEventHandler, PersonEntersVehicleEventHandler, - PersonLeavesVehicleEventHandler, VehicleDepartsAtFacilityEventHandler, PlansTranslator { - private static final Logger log = LogManager.getLogger(PtPlanToPlanStepBasedOnEvents.class); - - private final Scenario sc; - private final TransitSchedule schedule; - - private final Map> personsFromVehId = new HashMap<>(); - - private int iteration = -1; - - // this is _only_ there for output: - Set plansEverSeen = new HashSet<>(); - - private static final String STR_PLANSTEPFACTORY = "planStepFactory"; - private static final String STR_ITERATION = "iteration"; - // (better to do it this way since when plans are removed, this additional info is removed as well) - - private final Set transitDrivers = new HashSet<>(); - private final Set transitVehicles = new HashSet<>(); - private final Set> calibratedLines; - - PtPlanToPlanStepBasedOnEvents(final Scenario sc, final Set> calibratedLines) { - this.sc = sc; - this.schedule = ((MutableScenario) sc).getTransitSchedule(); - this.calibratedLines = calibratedLines; - } - - private long plansFound = 0; - private long plansNotFound = 0; - - @Override - public final cadyts.demand.Plan getCadytsPlan(final Plan plan) { - @SuppressWarnings("unchecked") // getting stuff from custom attributes has to be untyped. - PlanBuilder planStepFactory = (PlanBuilder) plan.getCustomAttributes().get(STR_PLANSTEPFACTORY); - if (planStepFactory == null) { - this.plansNotFound++; - return null; - } - this.plansFound++; - final cadyts.demand.Plan planSteps = planStepFactory.getResult(); - return planSteps; - } - - @Override - public void reset(final int it) { - this.iteration = it; - - log.warn("found " + this.plansFound + " out of " + (this.plansFound + this.plansNotFound) + " (" - + (100. * this.plansFound / (this.plansFound + this.plansNotFound)) + "%)"); - log.warn("(above values may both be at zero for a couple of iterations if multiple plans per agent all have no score)"); - - long nPlans = 0 ; - long nMemorizedPlans = 0 ; - - for ( Person person : this.sc.getPopulation().getPersons().values() ) { - for ( Plan plan : person.getPlans() ) { - nPlans ++ ; - @SuppressWarnings("unchecked") // getting stuff from custom attributes has to be untyped. - PlanBuilder planStepFactory = (PlanBuilder) plan.getCustomAttributes().get(STR_PLANSTEPFACTORY); - if ( planStepFactory!=null ) { - nMemorizedPlans ++ ; - } - } - } - - log.warn( "nPlans=" + nPlans + ", nMemorizedPlans=" + nMemorizedPlans ); - - this.personsFromVehId.clear(); - this.transitDrivers.clear(); - this.transitVehicles.clear(); - } - - @Override - public void handleEvent(final TransitDriverStartsEvent event) { - if (this.calibratedLines.contains(event.getTransitLineId())) { - this.transitDrivers.add(event.getDriverId()); - this.transitVehicles.add(event.getVehicleId()); - } - } - - @Override - public void handleEvent(final PersonEntersVehicleEvent event) { - if (this.transitDrivers.contains(event.getPersonId()) || !this.transitVehicles.contains(event.getVehicleId())) { - return; // ignore transit drivers or persons entering non-(analyzed-)transit vehicles - } - addPersonToVehicleContainer(event.getPersonId(), event.getVehicleId()); - } - - @Override - public void handleEvent(final PersonLeavesVehicleEvent event) { - if (this.transitDrivers.contains(event.getPersonId()) || !this.transitVehicles.contains(event.getVehicleId())) { - return; // ignore transit drivers or persons entering non-(analyzed-)transit vehicles - } - removePersonFromVehicleContainer(event.getPersonId(), event.getVehicleId()); - } - - @Override - public void handleEvent(final VehicleDepartsAtFacilityEvent event) { - double time = event.getTime(); - Id vehId = event.getVehicleId(); - Id facId = event.getFacilityId(); - if (this.personsFromVehId.get(vehId) == null) { - // (means nobody has entered the vehicle yet) - return; - } - TransitStopFacility fac = this.schedule.getFacilities().get(facId); - - for (Id personId : this.personsFromVehId.get(vehId)) { - // get the "Person" behind the id: - Person person = this.sc.getPopulation().getPersons().get(personId); - - // get the selected plan: - Plan selectedPlan = person.getSelectedPlan(); - - // get the planStepFactory for the plan (or create one): - PlanBuilder tmpPlanStepFactory = getPlanStepFactoryForPlan(selectedPlan); - - if (tmpPlanStepFactory != null) { - // add the "turn" to the planStepfactory - tmpPlanStepFactory.addTurn(fac, (int) time); - } - } - } - - // ################################################################################### - // only private functions below here (low level functionality) - - private void addPersonToVehicleContainer(final Id personId, final Id vehId) { - // get the personsContainer that belongs to the vehicle: - Collection personsInVehicle = this.personsFromVehId.get(vehId); - - if (personsInVehicle == null) { - // means does not exist yet - personsInVehicle = new ArrayList<>(); - this.personsFromVehId.put(vehId, personsInVehicle); - } - - personsInVehicle.add(personId); - } - - private void removePersonFromVehicleContainer(final Id personId, final Id vehId) { - // get the personsContainer that belongs to the vehicle: - Collection personsInVehicle = this.personsFromVehId.get(vehId); - - if (personsInVehicle == null) { - throw new RuntimeException("should not be possible: person should enter before leaving, and then construct the container"); - } - - // remove the person from the personsContainer: - personsInVehicle.remove(personId); // linear time operation; a HashMap might be better. - } - - private PlanBuilder getPlanStepFactoryForPlan(final Plan selectedPlan) { - PlanBuilder planStepFactory = null; - - planStepFactory = (PlanBuilder) selectedPlan.getCustomAttributes().get(STR_PLANSTEPFACTORY); - Integer factoryIteration = (Integer) selectedPlan.getCustomAttributes().get(STR_ITERATION); - if (planStepFactory == null || factoryIteration == null || factoryIteration != this.iteration) { - // attach the iteration number to the plan: - selectedPlan.getCustomAttributes().put(STR_ITERATION, this.iteration); - - // construct a new PlanBulder and attach it to the plan: - planStepFactory = new PlanBuilder<>(); - selectedPlan.getCustomAttributes().put(STR_PLANSTEPFACTORY, planStepFactory); - - // memorize the plan as being seen: - this.plansEverSeen.add(selectedPlan); - } - - return planStepFactory; - } - - static void printCadytsPlan(final cadyts.demand.Plan cadytsPlan) { - // prints Cadyts plan - String sepCadStr = "==printing Cadyts Plan=="; - System.err.println(sepCadStr); - if (cadytsPlan != null) { - for (int ii = 0; ii < cadytsPlan.size(); ii++) { - cadyts.demand.PlanStep cadytsPlanStep = cadytsPlan.getStep(ii); - System.err.println("stopId" + cadytsPlanStep.getLink().getId() + " time: " + cadytsPlanStep.getEntryTime_s()); - } - } else { - System.err.println(" cadyts plan is null "); - } - } - -} diff --git a/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/TransitStopFacilityLookUp.java b/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/TransitStopFacilityLookUp.java deleted file mode 100644 index 651b2a99c66..00000000000 --- a/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/TransitStopFacilityLookUp.java +++ /dev/null @@ -1,48 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* * - * * - * *********************************************************************** * - * * - * copyright : (C) 2008 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ -package org.matsim.contrib.cadyts.pt; - -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.contrib.cadyts.general.LookUpItemFromId; -import org.matsim.pt.transitSchedule.api.TransitSchedule; -import org.matsim.pt.transitSchedule.api.TransitStopFacility; - -/** - * @author nagel - * - */ -class TransitStopFacilityLookUp implements LookUpItemFromId { - - private TransitSchedule schedule; - - public TransitStopFacilityLookUp( Scenario sc ) { - this.schedule = sc.getTransitSchedule() ; - } - - public TransitStopFacilityLookUp( TransitSchedule schedule ) { - this.schedule = schedule ; - } - - @Override - public TransitStopFacility getItem(Id id) { - return this.schedule.getFacilities().get(id); - } - -} diff --git a/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/package-info.java b/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/package-info.java deleted file mode 100644 index 0b45babafa5..00000000000 --- a/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt/package-info.java +++ /dev/null @@ -1,74 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* * - * * - * *********************************************************************** * - * * - * copyright : (C) 2008 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ -/** - * Integrates automatic calibration upon public transport line occupancies using Cadyts into MATSim. - * - *

Entry point / How to use

- *
    - *
  • Use org.matsim.contrib.cadyts.pt.CadytsPtPlanStrategy as a replanning strategy.
  • - *
  • Add the following configuration parameters (approximately; this has changed since inception; - * check auto-generated config comments; use second config dump for that): - *
    - * <module name="cadytsPt">
    - *   <param name="startTime" value="05:00:00" />
    - *
    - *   <param name="endTime" value="21:00:00" />
    - *
    - *   <!-- Comma-separated list of transit lines to be calibrated. ->
    - *   <param name="calibratedLines" value="M44" />
    - *
    - *   <param name="writeAnalysisFile" value="false" />
    - *
    - *   <!-- see cadyts documentation for the meaning of the following values. -->
    - *   <param name="regressionInertia" value="0.95" />
    - *   <param name="minFlowStddevVehH" value="8.0" />
    - *   <param name="freezeIteration" value="2147483647" />
    - *   <param name="preparatoryIterations" value="1" />
    - *   <param name="varianceScale" value="1.0" />
    - *   <param name="useBruteForce" value="true" />
    - *
    - * </module>
    - * These parameters are defined in {@link org.matsim.contrib.cadyts.general.CadytsConfigGroup} - * - *
  • - *
  • There also needs to be a ptCounts entry, something like: - *
    - *
    - * 	<module name="ptCounts">
    - *		<param name="inputOccupancyCountsFile" value="path-to-counts-file" />
    - *	</module>
    - * And (obviously) a working ptCounts file. - *
  • - *
  • It is a unfortunate that the counts file takes measurements in hourly values, while cadyts takes arbitrary time spans. - * (The cadyts convention seems more powerful, thus we did not want to reduce it to the "Counts" convention.) - * As long as the cadytsPt timeBinSize is set to 3600, things should be straightforward, and there is also (I think) no - * problem if there are measurements for times outside the cadytsPt startTime/endTime interval. yyyy Unfortunately, - * I cannot remember how the counts file is interpreted once the cadytsPt timeBinSize is set to something different: Does the - * Counts file than think in terms of time bins rather than in terms of hours? In fact, I think not; rather, it is probably as - * follows: Counts still refer to hours. If, say, you use timeBinSize of 7200 and start/endTime as 05:00/09:00, then the code - * will aggregate counts from the 6th and 7th hour into one time bin, etc. If things do not correspond, the code will probably - * complain. See CadytsBuilder.buildCalibrator, since there are some consistency checks. (kai, oct'12) - *
  • Typically, {@link org.matsim.contrib.cadyts.pt.CadytsPtPlanStrategy} should be the only - * plan strategy being used. So it is advised to first run the simulation until every - * agent has a few (different) plans, and then do some iterations using only the - * calibration strategy.
  • - *
- * - */ -package org.matsim.contrib.cadyts.pt; diff --git a/contribs/cadytsIntegration/src/test/java/org/matsim/contrib/cadyts/pt/CadytsPtIT.java b/contribs/cadytsIntegration/src/test/java/org/matsim/contrib/cadyts/pt/CadytsPtIT.java deleted file mode 100644 index 9185653ccd5..00000000000 --- a/contribs/cadytsIntegration/src/test/java/org/matsim/contrib/cadyts/pt/CadytsPtIT.java +++ /dev/null @@ -1,689 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * CadytsIntegrationTest.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2011 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -package org.matsim.contrib.cadyts.pt; - -import cadyts.measurements.SingleLinkMeasurement; -import cadyts.utilities.io.tabularFileParser.TabularFileParser; -import cadyts.utilities.misc.DynamicData; -import com.google.inject.Provider; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.api.core.v01.population.Person; -import org.matsim.contrib.cadyts.general.CadytsConfigGroup; -import org.matsim.contrib.cadyts.general.CadytsCostOffsetsXMLFileIO; -import org.matsim.contrib.cadyts.general.CadytsPlanChanger; -import org.matsim.contrib.cadyts.general.CadytsScoring; -import org.matsim.contrib.cadyts.utils.CalibrationStatReader; -import org.matsim.core.api.experimental.events.EventsManager; -import org.matsim.core.config.Config; -import org.matsim.core.config.ConfigUtils; -import org.matsim.core.config.groups.ControllerConfigGroup.MobsimType; -import org.matsim.core.config.groups.ScoringConfigGroup.ActivityParams; -import org.matsim.core.config.groups.PlansConfigGroup.HandlingOfPlansWithoutRoutingMode; -import org.matsim.core.config.groups.ReplanningConfigGroup.StrategySettings; -import org.matsim.core.controler.AbstractModule; -import org.matsim.core.controler.Controler; -import org.matsim.core.mobsim.framework.Mobsim; -import org.matsim.core.mobsim.framework.MobsimFactory; -import org.matsim.core.replanning.PlanStrategy; -import org.matsim.core.replanning.PlanStrategyImpl; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.core.scoring.ScoringFunction; -import org.matsim.core.scoring.ScoringFunctionFactory; -import org.matsim.core.scoring.SumScoringFunction; -import org.matsim.core.scoring.functions.CharyparNagelActivityScoring; -import org.matsim.core.scoring.functions.CharyparNagelAgentStuckScoring; -import org.matsim.core.scoring.functions.CharyparNagelLegScoring; -import org.matsim.core.scoring.functions.ScoringParameters; -import org.matsim.core.scoring.functions.ScoringParametersForPerson; -import org.matsim.counts.Count; -import org.matsim.counts.Counts; -import org.matsim.counts.MatsimCountsReader; -import org.matsim.pt.transitSchedule.api.TransitSchedule; -import org.matsim.pt.transitSchedule.api.TransitStopFacility; -import org.matsim.testcases.MatsimTestUtils; - -import jakarta.inject.Inject; -import java.io.IOException; -import java.util.HashSet; -import java.util.Set; - -public class CadytsPtIT { - - @Rule - public MatsimTestUtils utils = new MatsimTestUtils(); - - @Test - public final void testInitialization() { - String inputDir = this.utils.getClassInputDirectory(); - - Config config = createTestConfig(inputDir, this.utils.getOutputDirectory()); - config.controller().setLastIteration(0); - StrategySettings stratSets = new StrategySettings(); - stratSets.setStrategyName("ccc") ; - stratSets.setWeight(1.) ; - config.replanning().addStrategySettings(stratSets) ; - - final Scenario scenario = ScenarioUtils.loadScenario(config) ; - final Controler controler = new Controler(scenario); - controler.addOverridingModule(new CadytsPtModule()); - controler.addOverridingModule(new AbstractModule() { - @Override - public void install() { - addPlanStrategyBinding("ccc").toProvider(new jakarta.inject.Provider() { - @Inject CadytsPtContext context; - @Override - public PlanStrategy get() { - return new PlanStrategyImpl(new CadytsPlanChanger<>(scenario, context)); - } - }); - } - }); - - controler.getConfig().controller().setCreateGraphs(false); - controler.getConfig().controller().setWriteEventsInterval(0); - controler.getConfig().controller().setDumpDataAtEnd(true); - controler.addOverridingModule(new AbstractModule() { - @Override - public void install() { - bindMobsim().toProvider(new Provider() { - @Override - public Mobsim get() { - return new DummyMobsimFactory().createMobsim(controler.getScenario(), controler.getEvents()); - } - }); - } - }); - controler.run(); - - CadytsPtContext context = controler.getInjector().getInstance(CadytsPtContext.class); - - //test calibration settings - Assert.assertEquals(true, context.getCalibrator().getBruteForce()); - Assert.assertEquals(false, context.getCalibrator().getCenterRegression()); - Assert.assertEquals(Integer.MAX_VALUE, context.getCalibrator().getFreezeIteration()); - Assert.assertEquals(8.0, context.getCalibrator().getMinStddev(SingleLinkMeasurement.TYPE.FLOW_VEH_H), MatsimTestUtils.EPSILON); - Assert.assertEquals(1, context.getCalibrator().getPreparatoryIterations()); - Assert.assertEquals(0.95, context.getCalibrator().getRegressionInertia(), MatsimTestUtils.EPSILON); - Assert.assertEquals(1.0, context.getCalibrator().getVarianceScale(), MatsimTestUtils.EPSILON); - Assert.assertEquals(3600.0, context.getCalibrator().getTimeBinSize_s(), MatsimTestUtils.EPSILON); - } - - - @Test - public final void testCalibrationAsScoring() throws IOException { - final double beta=30. ; - final int lastIteration = 20 ; - - String inputDir = this.utils.getClassInputDirectory(); - String outputDir = this.utils.getOutputDirectory(); - - final Config config = createTestConfig(inputDir, outputDir); - - config.controller().setLastIteration(lastIteration) ; - - config.scoring().setBrainExpBeta(beta) ; - - StrategySettings stratSets = new StrategySettings() ; - stratSets.setStrategyName("ChangeExpBeta") ; - stratSets.setWeight(1.0) ; - config.replanning().addStrategySettings(stratSets) ; - - // === - - final Controler controler = new Controler(config); - controler.getConfig().controller().setCreateGraphs(false); - controler.addOverridingModule(new CadytsPtModule()); - - controler.setScoringFunctionFactory(new ScoringFunctionFactory() { - @Inject ScoringParametersForPerson parameters; - @Inject Network network; - @Inject CadytsPtContext cContext; - @Override - public ScoringFunction createNewScoringFunction(Person person) { - final ScoringParameters params = parameters.getScoringParameters(person); - - SumScoringFunction scoringFunctionAccumulator = new SumScoringFunction(); - scoringFunctionAccumulator.addScoringFunction(new CharyparNagelLegScoring(params, network, config.transit().getTransitModes())); - scoringFunctionAccumulator.addScoringFunction(new CharyparNagelActivityScoring(params)) ; - scoringFunctionAccumulator.addScoringFunction(new CharyparNagelAgentStuckScoring(params)); - - final CadytsScoring scoringFunction = new CadytsScoring(person.getSelectedPlan() ,config, cContext); - scoringFunction.setWeightOfCadytsCorrection(beta*30.) ; - scoringFunctionAccumulator.addScoringFunction(scoringFunction ); - - return scoringFunctionAccumulator; - } - }) ; - - controler.run(); - - //scenario data test - Assert.assertNotNull("Config is null" , controler.getConfig()); - Assert.assertEquals("Different number of links in network.", controler.getScenario().getNetwork().getLinks().size() , 23 ); - Assert.assertEquals("Different number of nodes in network.", controler.getScenario().getNetwork().getNodes().size() , 15 ); - Assert.assertNotNull("Transit schedule is null.", controler.getScenario().getTransitSchedule()); - Assert.assertEquals("Num. of trLines is wrong.", 2, controler.getScenario().getTransitSchedule().getTransitLines().size() ); - Assert.assertEquals("Num of facilities in schedule is wrong.", controler.getScenario().getTransitSchedule().getFacilities().size() , 5); - Assert.assertNotNull("Population is null.", controler.getScenario().getPopulation()); - Assert.assertEquals("Num. of persons in population is wrong.", controler.getScenario().getPopulation().getPersons().size() , 4); - Assert.assertEquals("Scale factor is wrong.", controler.getScenario().getConfig().ptCounts().getCountsScaleFactor(), 1.0, MatsimTestUtils.EPSILON); - // Assert.assertEquals("Distance filter is wrong.", controler.getTestScenarioURL().getConfig().ptCounts().getDistanceFilter() , 30000.0, MatsimTestUtils.EPSILON); - // Assert.assertEquals("DistanceFilterCenterNode is wrong.", controler.getTestScenarioURL().getConfig().ptCounts().getDistanceFilterCenterNode(), "7"); - //counts - Assert.assertEquals("Occupancy count file is wrong.", controler.getScenario().getConfig().ptCounts().getOccupancyCountsFileName(), inputDir + "counts/counts_occupancy.xml"); - Counts occupCounts = new Counts(); - new MatsimCountsReader(occupCounts).readFile(controler.getScenario().getConfig().ptCounts().getOccupancyCountsFileName()); - Count count = occupCounts.getCount(Id.create("stop1", Link.class)); // casting id from stop to link, not nice - Assert.assertEquals("Occupancy counts description is wrong", occupCounts.getDescription(), "counts values for equil net"); - Assert.assertEquals("CsId is wrong.", count.getCsLabel() , "stop1"); - Assert.assertEquals("Volume of hour 4 is wrong", count.getVolume(7).getValue(), 4.0 , MatsimTestUtils.EPSILON); - Assert.assertEquals("Max count volume is wrong.", count.getMaxVolume().getValue(), 4.0 , MatsimTestUtils.EPSILON); - - // test resulting simulation volumes - { - String outCounts = outputDir + "ITERS/it." + lastIteration + "/" + lastIteration + ".simCountCompareOccupancy.txt"; - CountsReaderPt reader = new CountsReaderPt(outCounts); - double[] simValues; - double[] realValues; - - Id stopId1 = Id.create("stop1", TransitStopFacility.class); - simValues = reader.getSimulatedValues(stopId1); - realValues= reader.getRealValues(stopId1); - Assert.assertEquals("Volume of hour 6 is wrong", 4.0, simValues[6], MatsimTestUtils.EPSILON); - Assert.assertEquals("Volume of hour 6 is wrong", 4.0, realValues[6], MatsimTestUtils.EPSILON); - - Id stopId2 = Id.create("stop2", TransitStopFacility.class); - simValues = reader.getSimulatedValues(stopId2); - realValues= reader.getRealValues(stopId2); -// Assert.assertEquals("Volume of hour 6 is wrong", 0.0, simValues[6], MatsimTestUtils.EPSILON); - Assert.assertEquals("Volume of hour 6 is wrong", 2.0, simValues[6], MatsimTestUtils.EPSILON); // Altered after using ChangeExpBeta instead of "ccc" - Assert.assertEquals("Volume of hour 6 is wrong", 1.0, realValues[6] , MatsimTestUtils.EPSILON); - - Id stopId6 = Id.create("stop6", TransitStopFacility.class); - simValues = reader.getSimulatedValues(stopId6); - realValues= reader.getRealValues(stopId6); - Assert.assertEquals("Volume of hour 6 is wrong", 0.0, simValues[6], MatsimTestUtils.EPSILON); - Assert.assertEquals("Volume of hour 6 is wrong", 2.0, realValues[6], MatsimTestUtils.EPSILON); - - Id stopId10 = Id.create("stop10", TransitStopFacility.class); - simValues = reader.getSimulatedValues(stopId10); - realValues= reader.getRealValues(stopId10); -// Assert.assertEquals("Volume of hour 6 is wrong", 4.0, simValues[6], MatsimTestUtils.EPSILON); - Assert.assertEquals("Volume of hour 6 is wrong", 2.0, simValues[6], MatsimTestUtils.EPSILON); // Altered after using ChangeExpBeta instead of "ccc" - Assert.assertEquals("Volume of hour 6 is wrong", 5.0, realValues[6], MatsimTestUtils.EPSILON); - - // test calibration statistics - String testCalibStatPath = outputDir + "calibration-stats.txt"; - CalibrationStatReader calibrationStatReader = new CalibrationStatReader(); - new TabularFileParser().parse(testCalibStatPath, calibrationStatReader); - - CalibrationStatReader.StatisticsData outStatData= calibrationStatReader.getCalStatMap().get(lastIteration); -// Assert.assertEquals("different Count_ll", "-0.046875", outStatData.getCount_ll() ); - Assert.assertEquals("different Count_ll", "-0.109375", outStatData.getCount_ll() ); // Altered after using ChangeExpBeta instead of "ccc" -// Assert.assertEquals("different Count_ll_pred_err", "0.01836234363152515" , outStatData.getCount_ll_pred_err() ); - Assert.assertEquals("different Count_ll_pred_err", "0.008411478550953913" , outStatData.getCount_ll_pred_err() ); // Altered after using ChangeExpBeta instead of "ccc" - // Assert.assertEquals("different Link_lambda_avg", "-2.2604922388914356E-10", outStatData.getLink_lambda_avg() ); - // Assert.assertEquals("different Link_lambda_max", "0.0" , outStatData.getLink_lambda_max() ); - // Assert.assertEquals("different Link_lambda_min", "-7.233575164452593E-9", outStatData.getLink_lambda_min() ); - // Assert.assertEquals("different Link_lambda_stddev", "1.261054219517188E-9", outStatData.getLink_lambda_stddev()); - // Assert.assertEquals("different P2p_ll", "--" , outStatData.getP2p_ll()); - // Assert.assertEquals("different Plan_lambda_avg", "-7.233575164452594E-9", outStatData.getPlan_lambda_avg() ); - // Assert.assertEquals("different Plan_lambda_max", "-7.233575164452593E-9" , outStatData.getPlan_lambda_max() ); - // Assert.assertEquals("different Plan_lambda_min", "-7.233575164452593E-9" , outStatData.getPlan_lambda_min() ); - // Assert.assertEquals("different Plan_lambda_stddev", "0.0" , outStatData.getPlan_lambda_stddev()); -// Assert.assertEquals("different Total_ll", "-0.046875", outStatData.getTotal_ll() ); - Assert.assertEquals("different Total_ll", "-0.109375", outStatData.getTotal_ll() ); // Altered after using ChangeExpBeta instead of "ccc" - - - //test link offsets - final TransitSchedule schedule = controler.getScenario().getTransitSchedule(); - String linkOffsetFile = outputDir + "ITERS/it." + lastIteration + "/" + lastIteration + ".linkCostOffsets.xml"; - // CadytsPtLinkCostOffsetsXMLFileIO offsetReader = new CadytsPtLinkCostOffsetsXMLFileIO (schedule); - CadytsCostOffsetsXMLFileIO offsetReader - = new CadytsCostOffsetsXMLFileIO (new TransitStopFacilityLookUp(controler.getScenario()), TransitStopFacility.class); - DynamicData stopOffsets = offsetReader.read(linkOffsetFile); - - TransitStopFacility stop2 = schedule.getFacilities().get(stopId2); - TransitStopFacility stop10 = schedule.getFacilities().get(stopId10); - - //find first offset value different from null to compare. Useful to test with different time bin sizes - int binIndex=-1; - boolean isZero; - do { - binIndex++; - isZero = (Math.abs(stopOffsets.getBinValue(stop2 , binIndex) - 0.0) < MatsimTestUtils.EPSILON); - } while (isZero && binIndex<86400); - - Assert.assertEquals("Wrong bin index for first link offset", 6, binIndex); -// Assert.assertEquals("Wrong link offset of stop 10", 0.03515757824042241, stopOffsets.getBinValue(stop10 , binIndex), MatsimTestUtils.EPSILON); - Assert.assertEquals("Wrong link offset of stop 10", 0.022383938774904025, stopOffsets.getBinValue(stop10 , binIndex), MatsimTestUtils.EPSILON); // Altered after using ChangeExpBeta instead of "ccc" -// Assert.assertEquals("Wrong link offset of stop 2", -0.011353248321030008, stopOffsets.getBinValue(stop2 , binIndex), MatsimTestUtils.EPSILON); - Assert.assertEquals("Wrong link offset of stop 2", -0.008477236625252698, stopOffsets.getBinValue(stop2 , binIndex), MatsimTestUtils.EPSILON); // Altered after using ChangeExpBeta instead of "ccc" - } - } - - - @Test - public final void testCalibration() throws IOException { - final double beta = 30. ; - final int lastIteration = 20 ; - - String inputDir = this.utils.getClassInputDirectory(); - String outputDir = this.utils.getOutputDirectory(); - - Config config = createTestConfig(inputDir, outputDir) ; - - config.controller().setWriteEventsInterval(0) ; - config.controller().setLastIteration(lastIteration) ; - // seems to need 15 iterations as "warm-up"; at least the cadyts corrections are much smaller until then. - - config.scoring().setBrainExpBeta(beta) ; - - StrategySettings stratSets = new StrategySettings(); - stratSets.setStrategyName("ccc") ; - stratSets.setWeight(1.) ; - config.replanning().addStrategySettings(stratSets) ; - - final Scenario scenario = ScenarioUtils.loadScenario(config) ; - - final Controler controler = new Controler( scenario ); - controler.getConfig().controller().setCreateGraphs(false); - controler.getConfig().controller().setDumpDataAtEnd(true); - - controler.addOverridingModule(new CadytsPtModule()); - controler.addOverridingModule(new AbstractModule() { - @Override - public void install() { - addPlanStrategyBinding("ccc").toProvider(new jakarta.inject.Provider() { - @Inject CadytsPtContext context; - @Override - public PlanStrategy get() { - final CadytsPlanChanger planSelector = new CadytsPlanChanger(scenario, context); - planSelector.setCadytsWeight(beta * 30.); - return new PlanStrategyImpl(planSelector); - } - }); - } - }); - - controler.run(); - - //scenario data test - Assert.assertNotNull("config is null" , controler.getConfig()); - Assert.assertEquals("Different number of links in network.", controler.getScenario().getNetwork().getLinks().size() , 23 ); - Assert.assertEquals("Different number of nodes in network.", controler.getScenario().getNetwork().getNodes().size() , 15 ); - Assert.assertNotNull("Transit schedule is null.", controler.getScenario().getTransitSchedule()); - Assert.assertEquals("Num. of trLines is wrong.", 2, controler.getScenario().getTransitSchedule().getTransitLines().size() ); - Assert.assertEquals("Num of facilities in schedule is wrong.", controler.getScenario().getTransitSchedule().getFacilities().size() , 5); - Assert.assertNotNull("Population is null.", controler.getScenario().getPopulation()); - Assert.assertEquals("Num. of persons in population is wrong.", controler.getScenario().getPopulation().getPersons().size() , 4); - Assert.assertEquals("Scale factor is wrong.", controler.getScenario().getConfig().ptCounts().getCountsScaleFactor(), 1.0, MatsimTestUtils.EPSILON); - // Assert.assertEquals("Distance filter is wrong.", controler.getTestScenarioURL().getConfig().ptCounts().getDistanceFilter() , 30000.0, MatsimTestUtils.EPSILON); - // Assert.assertEquals("DistanceFilterCenterNode is wrong.", controler.getTestScenarioURL().getConfig().ptCounts().getDistanceFilterCenterNode(), "7"); - //counts - Assert.assertEquals("Occupancy count file is wrong.", controler.getScenario().getConfig().ptCounts().getOccupancyCountsFileName(), inputDir + "counts/counts_occupancy.xml"); - Counts occupCounts = new Counts(); - new MatsimCountsReader(occupCounts).readFile(controler.getScenario().getConfig().ptCounts().getOccupancyCountsFileName()); - Count count = occupCounts.getCount(Id.create("stop1", Link.class)); // casting the id from a stop to a link, not nice.. - Assert.assertEquals("Occupancy counts description is wrong", occupCounts.getDescription(), "counts values for equil net"); - Assert.assertEquals("CsId is wrong.", count.getCsLabel() , "stop1"); - Assert.assertEquals("Volume of hour 4 is wrong", count.getVolume(7).getValue(), 4.0 , MatsimTestUtils.EPSILON); - Assert.assertEquals("Max count volume is wrong.", count.getMaxVolume().getValue(), 4.0 , MatsimTestUtils.EPSILON); - - // test resulting simulation volumes - { - String outCounts = outputDir + "ITERS/it." + lastIteration + "/" + lastIteration + ".simCountCompareOccupancy.txt"; - CountsReaderPt reader = new CountsReaderPt(outCounts); - double[] simValues; - double[] realValues; - - Id stopId1 = Id.create("stop1", TransitStopFacility.class); - simValues = reader.getSimulatedValues(stopId1); - realValues= reader.getRealValues(stopId1); - Assert.assertEquals("Volume of hour 6 is wrong", 4.0, simValues[6], MatsimTestUtils.EPSILON); - Assert.assertEquals("Volume of hour 6 is wrong", 4.0, realValues[6], MatsimTestUtils.EPSILON); - - Id stopId2 = Id.create("stop2", TransitStopFacility.class); - simValues = reader.getSimulatedValues(stopId2); - realValues= reader.getRealValues(stopId2); - Assert.assertEquals("Volume of hour 6 is wrong", 0.0, simValues[6], MatsimTestUtils.EPSILON); - Assert.assertEquals("Volume of hour 6 is wrong", 1.0, realValues[6] , MatsimTestUtils.EPSILON); - - Id stopId6 = Id.create("stop6", TransitStopFacility.class); - simValues = reader.getSimulatedValues(stopId6); - realValues= reader.getRealValues(stopId6); - Assert.assertEquals("Volume of hour 6 is wrong", 0.0, simValues[6], MatsimTestUtils.EPSILON); - Assert.assertEquals("Volume of hour 6 is wrong", 2.0, realValues[6], MatsimTestUtils.EPSILON); - - Id stopId10 = Id.create("stop10", TransitStopFacility.class); - simValues = reader.getSimulatedValues(stopId10); - realValues= reader.getRealValues(stopId10); - Assert.assertEquals("Volume of hour 6 is wrong", 4.0, simValues[6], MatsimTestUtils.EPSILON); - Assert.assertEquals("Volume of hour 6 is wrong", 5.0, realValues[6], MatsimTestUtils.EPSILON); - - // test calibration statistics - String testCalibStatPath = outputDir + "calibration-stats.txt"; - CalibrationStatReader calibrationStatReader = new CalibrationStatReader(); - new TabularFileParser().parse(testCalibStatPath, calibrationStatReader); - - CalibrationStatReader.StatisticsData outStatData= calibrationStatReader.getCalStatMap().get(lastIteration); - Assert.assertEquals("different Count_ll", "-0.046875", outStatData.getCount_ll() ); - Assert.assertEquals("different Count_ll_pred_err", "0.008670972399424905" , outStatData.getCount_ll_pred_err() ); - Assert.assertEquals("different Link_lambda_avg", "3.642292018550638E-4", outStatData.getLink_lambda_avg() ); - Assert.assertEquals("different Link_lambda_max", "0.032081715026130615" , outStatData.getLink_lambda_max() ); - Assert.assertEquals("different Link_lambda_min", "-0.008771046107406533", outStatData.getLink_lambda_min() ); - Assert.assertEquals("different Link_lambda_stddev", "0.0041495140513996154", outStatData.getLink_lambda_stddev()); - Assert.assertEquals("different P2p_ll", "--" , outStatData.getP2p_ll()); - Assert.assertEquals("different Plan_lambda_avg", "0.011655334459362041", outStatData.getPlan_lambda_avg() ); - Assert.assertEquals("different Plan_lambda_max", "0.032081715026130615" , outStatData.getPlan_lambda_max() ); - Assert.assertEquals("different Plan_lambda_min", "-0.008771046107406533" , outStatData.getPlan_lambda_min() ); - Assert.assertEquals("different Plan_lambda_stddev", "0.02183671935220152" , outStatData.getPlan_lambda_stddev()); - Assert.assertEquals("different Total_ll", "-0.046875", outStatData.getTotal_ll() ); - - //test link offsets - final TransitSchedule schedule = controler.getScenario().getTransitSchedule(); - String linkOffsetFile = outputDir + "ITERS/it." + lastIteration + "/" + lastIteration + ".linkCostOffsets.xml"; - // CadytsPtLinkCostOffsetsXMLFileIO offsetReader = new CadytsPtLinkCostOffsetsXMLFileIO (schedule); - CadytsCostOffsetsXMLFileIO offsetReader - = new CadytsCostOffsetsXMLFileIO (new TransitStopFacilityLookUp(controler.getScenario()), TransitStopFacility.class); - DynamicData stopOffsets = offsetReader.read(linkOffsetFile); - - TransitStopFacility stop2 = schedule.getFacilities().get(stopId2); - TransitStopFacility stop10 = schedule.getFacilities().get(stopId10); - - //find first offset value different from null to compare. Useful to test with different time bin sizes - int binIndex=-1; - boolean isZero; - do { - binIndex++; - isZero = (Math.abs(stopOffsets.getBinValue(stop2 , binIndex) - 0.0) < MatsimTestUtils.EPSILON); - }while (isZero && binIndex<86400); - - Assert.assertEquals("Wrong bin index for first link offset", 6, binIndex); - Assert.assertEquals("Wrong link offset of stop 10", 0.031842616249416734, stopOffsets.getBinValue(stop10 , binIndex), MatsimTestUtils.EPSILON); - Assert.assertEquals("Wrong link offset of stop 2", -0.0079478186053482, stopOffsets.getBinValue(stop2 , binIndex), MatsimTestUtils.EPSILON); - } - } - - - /** - * @author mmoyo - */ - @Test - public final void testCalibrationTwo() throws IOException { - // yyyy I cannot fully certify that this test is doing something reasonable, since simCountComparisonOccupancy.txt and - // cadytsSimCountComparisonOccupancy.txt are returning different results. kai, feb'13 - // There is a comment in CadytsContext that the "cadyts" version may be wrong for time bins different from one hour. kai, dec'13 - - final double beta = 30. ; - final int lastIteration = 20 ; - - String inputDir = this.utils.getClassInputDirectory(); - String outputDir = this.utils.getOutputDirectory(); - - Config config = createTestConfig(inputDir, this.utils.getOutputDirectory()); - - config.controller().setLastIteration(lastIteration) ; - config.controller().setWritePlansInterval(1) ; - config.controller().setWriteEventsInterval(1) ; - - config.ptCounts().setPtCountsInterval(1) ; - - StrategySettings stratSets = new StrategySettings(); - stratSets.setStrategyName("ccc") ; - stratSets.setWeight(1.) ; - config.replanning().addStrategySettings(stratSets) ; - - CadytsConfigGroup cConfig = (CadytsConfigGroup) config.getModule(CadytsConfigGroup.GROUP_NAME) ; - cConfig.setTimeBinSize(7200) ; - - // --- - - final Controler controler = new Controler(config); - controler.addOverridingModule(new CadytsPtModule()); -// controler.setOverwriteFiles(true); - controler.addOverridingModule(new AbstractModule() { - @Override - public void install() { - addPlanStrategyBinding("ccc").toProvider(new jakarta.inject.Provider() { - @Inject Scenario scenario; - @Inject CadytsPtContext context; - @Override - public PlanStrategy get() { - final CadytsPlanChanger planSelector = new CadytsPlanChanger(scenario, context); - planSelector.setCadytsWeight(beta * 30.); - return new PlanStrategyImpl(planSelector); - } - }); - } - }); - - controler.getConfig().controller().setCreateGraphs(false); - controler.getConfig().controller().setWriteEventsInterval(0); - controler.getConfig().controller().setDumpDataAtEnd(true); - controler.run(); - - // ==================================== - - //scenario data test - Assert.assertNotNull("config is null" , controler.getConfig()); - Assert.assertEquals("Different number of links in network.", controler.getScenario().getNetwork().getLinks().size() , 23 ); - Assert.assertEquals("Different number of nodes in network.", controler.getScenario().getNetwork().getNodes().size() , 15 ); - Assert.assertNotNull("Transit schedule is null.", controler.getScenario().getTransitSchedule()); - Assert.assertEquals("Num. of trLines is wrong.", 2, controler.getScenario().getTransitSchedule().getTransitLines().size() ); - Assert.assertEquals("Num of facilities in schedule is wrong.", controler.getScenario().getTransitSchedule().getFacilities().size() , 5); - Assert.assertNotNull("Population is null.", controler.getScenario().getPopulation()); - Assert.assertEquals("Num. of persons in population is wrong.", controler.getScenario().getPopulation().getPersons().size() , 4); - Assert.assertEquals("Scale factor is wrong.", controler.getScenario().getConfig().ptCounts().getCountsScaleFactor(), 1.0, MatsimTestUtils.EPSILON); - // Assert.assertEquals("Distance filter is wrong.", controler.getTestScenarioURL().getConfig().ptCounts().getDistanceFilter() , 30000.0, MatsimTestUtils.EPSILON); - // Assert.assertEquals("DistanceFilterCenterNode is wrong.", controler.getTestScenarioURL().getConfig().ptCounts().getDistanceFilterCenterNode(), "7"); - //counts - Assert.assertEquals("Occupancy count file is wrong.", controler.getScenario().getConfig().ptCounts().getOccupancyCountsFileName(), inputDir + "counts/counts_occupancy.xml"); - Counts occupCounts = new Counts(); - new MatsimCountsReader(occupCounts).readFile(controler.getScenario().getConfig().ptCounts().getOccupancyCountsFileName()); - Count count = occupCounts.getCount(Id.create("stop1", Link.class)); - Assert.assertEquals("Occupancy counts description is wrong", occupCounts.getDescription(), "counts values for equil net"); - Assert.assertEquals("CsId is wrong.", count.getCsLabel() , "stop1"); - - Assert.assertEquals("Volume of hour 4 is wrong", count.getVolume(7).getValue(), 4.0 , MatsimTestUtils.EPSILON); - // yy I don't know why it says "hour 4" but "getVolume(7)". kai, sep'14 - - Assert.assertEquals("Max count volume is wrong.", count.getMaxVolume().getValue(), 4.0 , MatsimTestUtils.EPSILON); - - // test resulting simulation volumes - String outCounts = outputDir + "ITERS/it." + lastIteration + "/" + lastIteration + ".simCountCompareOccupancy.txt"; - CountsReaderPt reader = new CountsReaderPt(outCounts); - Id stopId1 = Id.create("stop1", TransitStopFacility.class); - { - double[] simValues = reader.getSimulatedValues(stopId1); - double[] realValues= reader.getRealValues(stopId1); - Assert.assertEquals("Volume of hour 6 (probably: 7) is wrong", 4.0, simValues[6], MatsimTestUtils.EPSILON); - Assert.assertEquals("Volume of hour 6 (probably: 7) is wrong", 4.0, realValues[6], MatsimTestUtils.EPSILON); - } - Id stopId2 = Id.create("stop2", TransitStopFacility.class); - { - double[] simValues = reader.getSimulatedValues(stopId2); - double[] realValues= reader.getRealValues(stopId2); - Assert.assertEquals("Volume of hour 6 (probably: 7) is wrong", 0.0, simValues[6], MatsimTestUtils.EPSILON); - Assert.assertEquals("Volume of hour 6 (probably: 7) is wrong", 1.0, realValues[6] , MatsimTestUtils.EPSILON); - } - Id stopId6 = Id.create("stop6", TransitStopFacility.class); - { - double[] simValues = reader.getSimulatedValues(stopId6); - double[] realValues= reader.getRealValues(stopId6); - Assert.assertEquals("Volume of hour 6 (probably: 7) is wrong", 0.0, simValues[6], MatsimTestUtils.EPSILON); - Assert.assertEquals("Volume of hour 6 (probably: 7) is wrong", 2.0, realValues[6], MatsimTestUtils.EPSILON); - } - Id stopId10 = Id.create("stop10", TransitStopFacility.class); - { - double[] simValues = reader.getSimulatedValues(stopId10); - double[] realValues= reader.getRealValues(stopId10); - Assert.assertEquals("Volume of hour 6 (probably: 7) is wrong", 4.0, simValues[6], MatsimTestUtils.EPSILON); - Assert.assertEquals("Volume of hour 6 (probably: 7) is wrong", 5.0, realValues[6], MatsimTestUtils.EPSILON); - } - // 2 bus lines, one using stops 1, 2, 12, the other using 1, 10, 12. Counts say: - // stop1: 4 (should always be satisfied) - // stop2: 1 (should be possible to satisfy bus see below) - // stop6: 2 (not possible to satisfy (no line going there)) - // stop10: 5 (not possible to satisfy (we have not enough plans) but see below) - // and they say this at h=7 (which may, or may not, be the entry "6" in the counts array, but then the error messages are wrong). - // - // stop2 and stop10 are pulling in different directions; would need 7 plans to satisfy but have only 4. Satisfying the higher - // volume station better is the cadyts-conforming solution. - - // test calibration statistics - String testCalibStatPath = outputDir + "calibration-stats.txt"; - CalibrationStatReader calibrationStatReader = new CalibrationStatReader(); - new TabularFileParser().parse(testCalibStatPath, calibrationStatReader); - - CalibrationStatReader.StatisticsData outStatData= calibrationStatReader.getCalStatMap().get(lastIteration); - // Assert.assertEquals("different Count_ll", "-0.01171875", outStatData.getCount_ll() ); - // Assert.assertEquals("different Count_ll_pred_err", "0.004590585907794875" , outStatData.getCount_ll_pred_err() ); - // Assert.assertEquals("different Link_lambda_avg", "-1.8081427328702926E-9", outStatData.getLink_lambda_avg() ); - // Assert.assertEquals("different Link_lambda_max", "0.0" , outStatData.getLink_lambda_max() ); - // Assert.assertEquals("different Link_lambda_min", "-1.4465142715757458E-8", outStatData.getLink_lambda_min() ); - // Assert.assertEquals("different Link_lambda_stddev", "4.501584893410135E-9" , outStatData.getLink_lambda_stddev()); - // Assert.assertEquals("different P2p_ll", "--" , outStatData.getP2p_ll()); - // Assert.assertEquals("different Plan_lambda_avg", "-2.5313998260184097E-8", outStatData.getPlan_lambda_avg() ); - // Assert.assertEquals("different Plan_lambda_max", "-2.5313998260184097E-8" , outStatData.getPlan_lambda_max() ); - // Assert.assertEquals("different Plan_lambda_min", "-2.5313998260184097E-8" , outStatData.getPlan_lambda_min() ); - // Assert.assertEquals("different Plan_lambda_stddev", "NaN" , outStatData.getPlan_lambda_stddev()); - // Assert.assertEquals("different Total_ll", "-0.01171875", outStatData.getTotal_ll() ); - // - // I think that the above quantities change when changing between FLOW_VEH_H and COUNT_VEH. The calibration result, though, - // seems the same. - - - //test link offsets - final TransitSchedule schedule = controler.getScenario().getTransitSchedule(); - CadytsCostOffsetsXMLFileIO offsetReader = - new CadytsCostOffsetsXMLFileIO (new TransitStopFacilityLookUp(controler.getScenario()), TransitStopFacility.class); - DynamicData stopOffsets = - offsetReader.read(outputDir + "ITERS/it." + lastIteration + "/" + lastIteration + ".linkCostOffsets.xml"); - - TransitStopFacility stop1 = schedule.getFacilities().get(stopId1); - TransitStopFacility stop2 = schedule.getFacilities().get(stopId2); - //TransitStopFacility stop6 = schedule.getFacilities().get(stopId6); - TransitStopFacility stop10 = schedule.getFacilities().get(stopId10); - - //find first offset value different from zero to compare. Useful to test with different time bin sizes - int binIndex=-1; - boolean isZero; - do { - binIndex++; - isZero = (Math.abs(stopOffsets.getBinValue(stop2 , binIndex) - 0.0) < MatsimTestUtils.EPSILON); - }while (isZero && binIndex<86400); - - Assert.assertEquals("Wrong Bin index for first link offset", 3, binIndex); // bin size = 3600; fix! //done manuel jul.2012 - Assert.assertEquals("Wrong link offset of stop 1", 0.0, stopOffsets.getBinValue(stop1 , binIndex), MatsimTestUtils.EPSILON); -// Assert.assertEquals("Wrong link offset of stop 2", -0.0028383120802772956, stopOffsets.getBinValue(stop2 , binIndex), MatsimTestUtils.EPSILON); -// Assert.assertEquals("Wrong link offset of stop 10", 0.00878939456017082, stopOffsets.getBinValue(stop10 , binIndex), MatsimTestUtils.EPSILON); - - Assert.assertTrue("Offset at stop 2 has wrong sign.", stopOffsets.getBinValue(stop2, binIndex) < 0. ) ; - Assert.assertTrue("Offset at stop 10 has wrong sign.", stopOffsets.getBinValue(stop10, binIndex) > 0. ) ; - } - - - private static Config createTestConfig(String inputDir, String outputDir) { - Config config = ConfigUtils.createConfig() ; - // --- - config.global().setRandomSeed(4711) ; - // --- - config.network().setInputFile(inputDir + "network.xml") ; - // --- - config.plans().setInputFile(inputDir + "4plans.xml") ; - config.plans().setHandlingOfPlansWithoutRoutingMode(HandlingOfPlansWithoutRoutingMode.useMainModeIdentifier); - // --- - config.transit().setUseTransit(true) ; - // --- - config.controller().setFirstIteration(1) ; - config.controller().setLastIteration(10) ; - config.controller().setOutputDirectory(outputDir) ; - config.controller().setWriteEventsInterval(1) ; - config.controller().setMobsim(MobsimType.qsim.toString()) ; - // --- - - config.qsim().setFlowCapFactor(0.02) ; - config.qsim().setStorageCapFactor(0.06) ; - config.qsim().setStuckTime(10.) ; - config.qsim().setRemoveStuckVehicles(false) ; // ?? - // --- - config.transit().setTransitScheduleFile(inputDir + "transitSchedule1bus.xml") ; - config.transit().setVehiclesFile(inputDir + "vehicles.xml") ; - Set modes = new HashSet() ; - modes.add("pt") ; - config.transit().setTransitModes(modes) ; - // --- - { - ActivityParams params = new ActivityParams("h") ; - config.scoring().addActivityParams(params ) ; - params.setTypicalDuration(12*60*60.) ; - }{ - ActivityParams params = new ActivityParams("w") ; - config.scoring().addActivityParams(params ) ; - params.setTypicalDuration(8*60*60.) ; - } - // --- -// ConfigGroup cadytsPtConfig = config.createModule(CadytsConfigGroup.GROUP_NAME ) ; - CadytsConfigGroup cadytsPtConfig = ConfigUtils.addOrGetModule( config, CadytsConfigGroup.class ); - -// cadytsPtConfig.addParam(CadytsConfigGroup.START_TIME, "04:00:00") ; - cadytsPtConfig.setStartTime( 4*3600 ); -// cadytsPtConfig.addParam(CadytsConfigGroup.END_TIME, "20:00:00" ) ; - cadytsPtConfig.setEndTime( 20*3600 ); - cadytsPtConfig.addParam(CadytsConfigGroup.REGRESSION_INERTIA, "0.95") ; - cadytsPtConfig.addParam(CadytsConfigGroup.USE_BRUTE_FORCE, "true") ; - cadytsPtConfig.addParam(CadytsConfigGroup.MIN_FLOW_STDDEV, "8") ; - cadytsPtConfig.addParam(CadytsConfigGroup.PREPARATORY_ITERATIONS, "1") ; - cadytsPtConfig.addParam(CadytsConfigGroup.TIME_BIN_SIZE, "3600") ; - cadytsPtConfig.addParam(CadytsConfigGroup.CALIBRATED_LINES, "M44,M43") ; - -// CadytsConfigGroup ccc = new CadytsConfigGroup() ; -// config.addModule(ccc) ; - - - // --- - config.ptCounts().setOccupancyCountsFileName(inputDir + "counts/counts_occupancy.xml") ; - config.ptCounts().setBoardCountsFileName(inputDir + "counts/counts_boarding.xml") ; - config.ptCounts().setAlightCountsFileName(inputDir + "counts/counts_alighting.xml") ; - // config.ptCounts().setDistanceFilter(30000.) ; // why? - // config.ptCounts().setDistanceFilterCenterNode("7") ; // why? - config.ptCounts().setOutputFormat("txt"); - config.ptCounts().setCountsScaleFactor(1.) ; - // --- - return config; - } - - private static class DummyMobsimFactory implements MobsimFactory { - @Override - public Mobsim createMobsim(final Scenario sc, final EventsManager eventsManager) { - return new Mobsim() { - @Override public void run() { } - } ; - } - } -} diff --git a/contribs/cadytsIntegration/src/test/java/org/matsim/contrib/cadyts/pt/CountsReaderPt.java b/contribs/cadytsIntegration/src/test/java/org/matsim/contrib/cadyts/pt/CountsReaderPt.java deleted file mode 100644 index a312c472c48..00000000000 --- a/contribs/cadytsIntegration/src/test/java/org/matsim/contrib/cadyts/pt/CountsReaderPt.java +++ /dev/null @@ -1,130 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * * - * *********************************************************************** * - * * - * copyright : (C) 2012 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -package org.matsim.contrib.cadyts.pt; - -import java.io.BufferedReader; -import java.io.FileReader; -import java.util.Map; -import java.util.TreeMap; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.matsim.api.core.v01.Id; -import org.matsim.core.utils.misc.StringUtils; -import org.matsim.pt.transitSchedule.api.TransitStopFacility; - -/** - * parses a output text file containing counts comparisons - * - * this class is only there in order to read the column-oriented output back in for testing. - * It should not be used elsewhere without further thinking. kai, sep'14 - * */ -final class CountsReaderPt { - - private final static Logger log = LogManager.getLogger(CountsReaderPt.class); - - final String STOP_ID_STRING_0 = "StopId :"; - final String HEAD_STRING_0 = "hour"; - final String ZERO = "0.0"; - - String countsTextFile; - Map, Map> count = new TreeMap<>(); - - CountsReaderPt(final String countsTextFile){ - this.countsTextFile = countsTextFile; - readValues(); - } - - private void readValues() { - try { - FileReader fileReader = new FileReader(this.countsTextFile); - // ->:correct this : reads first row - BufferedReader bufferedReader = new BufferedReader(fileReader); - String row = bufferedReader.readLine(); // TODO : include the first row inside the iteration - String[] values = StringUtils.explode(row, '\t'); - - Id id = Id.create(values[1], TransitStopFacility.class); - while (row != null) { - row = bufferedReader.readLine(); - if (row != null && row != "") { - values = StringUtils.explode(row, '\t'); - if (values[0].equals(this.STOP_ID_STRING_0)) { - id = Id.create(values[1], TransitStopFacility.class); - } else if (values[0].equals(this.HEAD_STRING_0)) { - // it does nothing, correct this condition - } else { - if (!this.count.containsKey(id)) { - this.count.put(id, new TreeMap()); - } - this.count.get(id).put(values[0], - new double[] { Double.parseDouble(values[1]), Double.parseDouble(values[2]), Double.parseDouble(values[3]) }); - } - } - } - bufferedReader.close(); - fileReader.close(); - } catch (Exception e) { - log.error(e); - } - } - - /** - * I am reasonably sure that the first entry (hour 1) is at array-position 0. kai, sep'14 - */ - double[]getSimulatedValues(final Id stopId) { - return this.getCountValues(stopId, 0); - } - - /** - * I am reasonably sure that the first entry (hour 1) is at array-position 0. kai, sep'14 - */ - double[]getSimulatedScaled(final Id stopId) { - return this.getCountValues(stopId, 1); - } - - /** - * I am reasonably sure that the first entry (hour 1) is at array-position 0. kai, sep'14 - */ - double[]getRealValues(final Id stopId) { - return this.getCountValues(stopId, 2); - } - - /** - * I am reasonably sure that the first entry (hour 1) is at array-position 0. kai, sep'14 - */ - double[]getCountValues(final Id stopId, final int col) { - double[] valueArray = new double[24]; - for (byte i= 0; i<24 ; i++) { - String hour = String.valueOf(i+1); - if (this.count.keySet().contains(stopId)) { - double[] value = this.count.get(stopId).get(hour); - if (value == null){ - valueArray[i] = 0.0; - } else { - valueArray[i] = value[col] ; //0 = simulated; 1= simulatedEscaled ; 2=realValues - } - } else { - valueArray = null; - } - } - return valueArray; - } - -} diff --git a/contribs/cadytsIntegration/src/test/java/org/matsim/contrib/cadyts/utils/CalibrationStatReaderTest.java b/contribs/cadytsIntegration/src/test/java/org/matsim/contrib/cadyts/utils/CalibrationStatReaderTest.java index 5733a037c50..cf1c31b9126 100644 --- a/contribs/cadytsIntegration/src/test/java/org/matsim/contrib/cadyts/utils/CalibrationStatReaderTest.java +++ b/contribs/cadytsIntegration/src/test/java/org/matsim/contrib/cadyts/utils/CalibrationStatReaderTest.java @@ -20,12 +20,10 @@ package org.matsim.contrib.cadyts.utils; import java.io.IOException; -import java.net.URL; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; -import org.matsim.contrib.cadyts.pt.CadytsPtIT; import org.matsim.testcases.MatsimTestUtils; import cadyts.utilities.io.tabularFileParser.TabularFileParser; @@ -42,17 +40,17 @@ public void testReader() throws IOException { CalibrationStatReader calibrationStatReader = new CalibrationStatReader(); tabularFileParser.parse(calibStatFile, calibrationStatReader); CalibrationStatReader.StatisticsData statData6= calibrationStatReader.getCalStatMap().get(Integer.valueOf(6)); - Assert.assertEquals("differrent Count_ll", "-1.546875", statData6.getCount_ll() ); - Assert.assertEquals("differrent Count_ll_pred_err", "9.917082938182276E-8" , statData6.getCount_ll_pred_err() ); - Assert.assertEquals("differrent Link_lambda_avg", "0.0013507168476099964", statData6.getLink_lambda_avg() ); - Assert.assertEquals("differrent Link_lambda_max", "0.031434867572002166" , statData6.getLink_lambda_max() ); - Assert.assertEquals("differrent Link_lambda_min", "0.0", statData6.getLink_lambda_min() ); - Assert.assertEquals("differrent Link_lambda_stddev", "0.0058320747961925256" , statData6.getLink_lambda_stddev()); - Assert.assertEquals("differrent P2p_ll", "--" , statData6.getP2p_ll()); - Assert.assertEquals("differrent Plan_lambda_avg", "0.04322293912351989", statData6.getPlan_lambda_avg() ); - Assert.assertEquals("differrent Plan_lambda_max", "0.04715229919344063" , statData6.getPlan_lambda_max() ); - Assert.assertEquals("differrent Plan_lambda_min", "0.03929357905359915" , statData6.getPlan_lambda_min() ); - Assert.assertEquals("differrent Plan_lambda_stddev", "0.004200662608832472" , statData6.getPlan_lambda_stddev()); - Assert.assertEquals("differrent Total_ll", "-1.546875", statData6.getTotal_ll() ); + Assert.assertEquals("different Count_ll", "-1.546875", statData6.getCount_ll() ); + Assert.assertEquals("different Count_ll_pred_err", "9.917082938182276E-8" , statData6.getCount_ll_pred_err() ); + Assert.assertEquals("different Link_lambda_avg", "0.0013507168476099964", statData6.getLink_lambda_avg() ); + Assert.assertEquals("different Link_lambda_max", "0.031434867572002166" , statData6.getLink_lambda_max() ); + Assert.assertEquals("different Link_lambda_min", "0.0", statData6.getLink_lambda_min() ); + Assert.assertEquals("different Link_lambda_stddev", "0.0058320747961925256" , statData6.getLink_lambda_stddev()); + Assert.assertEquals("different P2p_ll", "--" , statData6.getP2p_ll()); + Assert.assertEquals("different Plan_lambda_avg", "0.04322293912351989", statData6.getPlan_lambda_avg() ); + Assert.assertEquals("different Plan_lambda_max", "0.04715229919344063" , statData6.getPlan_lambda_max() ); + Assert.assertEquals("different Plan_lambda_min", "0.03929357905359915" , statData6.getPlan_lambda_min() ); + Assert.assertEquals("different Plan_lambda_stddev", "0.004200662608832472" , statData6.getPlan_lambda_stddev()); + Assert.assertEquals("different Total_ll", "-1.546875", statData6.getTotal_ll() ); } } diff --git a/contribs/commercialTrafficApplications/scenarios/grid/jointDemand_config.xml b/contribs/commercialTrafficApplications/scenarios/grid/jointDemand_config.xml index 8dcb998aa8d..eba2edb7fe4 100644 --- a/contribs/commercialTrafficApplications/scenarios/grid/jointDemand_config.xml +++ b/contribs/commercialTrafficApplications/scenarios/grid/jointDemand_config.xml @@ -383,24 +383,6 @@
- - - - - - - - - - - - - - - - - - diff --git a/contribs/signals/examples/tutorial/example90TrafficLights/useSignalInput/withLanes/config.xml b/contribs/signals/examples/tutorial/example90TrafficLights/useSignalInput/withLanes/config.xml index dcbc59dfac2..8bb3171493d 100644 --- a/contribs/signals/examples/tutorial/example90TrafficLights/useSignalInput/withLanes/config.xml +++ b/contribs/signals/examples/tutorial/example90TrafficLights/useSignalInput/withLanes/config.xml @@ -495,35 +495,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/contribs/signals/examples/tutorial/example90TrafficLights/useSignalInput/woLanes/config.xml b/contribs/signals/examples/tutorial/example90TrafficLights/useSignalInput/woLanes/config.xml index 4dcd49397ff..bca9f9ded80 100644 --- a/contribs/signals/examples/tutorial/example90TrafficLights/useSignalInput/woLanes/config.xml +++ b/contribs/signals/examples/tutorial/example90TrafficLights/useSignalInput/woLanes/config.xml @@ -495,35 +495,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/matsim/src/main/java/org/matsim/core/config/Config.java b/matsim/src/main/java/org/matsim/core/config/Config.java index de7facd728a..ecff0be5678 100644 --- a/matsim/src/main/java/org/matsim/core/config/Config.java +++ b/matsim/src/main/java/org/matsim/core/config/Config.java @@ -49,7 +49,6 @@ import org.matsim.core.config.groups.ScoringConfigGroup; import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.config.groups.PlansConfigGroup; -import org.matsim.core.config.groups.PtCountsConfigGroup; import org.matsim.core.config.groups.QSimConfigGroup; import org.matsim.core.config.groups.ScenarioConfigGroup; import org.matsim.core.config.groups.SubtourModeChoiceConfigGroup; @@ -149,8 +148,6 @@ public void addCoreModules() { this.modules.put(VspExperimentalConfigGroup.GROUP_NAME, new VspExperimentalConfigGroup()); - this.modules.put(PtCountsConfigGroup.GROUP_NAME, new PtCountsConfigGroup()); - this.modules.put(TransitConfigGroup.GROUP_NAME, new TransitConfigGroup()); this.modules.put(LinkStatsConfigGroup.GROUP_NAME, new LinkStatsConfigGroup()); @@ -452,10 +449,6 @@ public QSimConfigGroup qsim() { return (QSimConfigGroup) this.getModule(QSimConfigGroup.GROUP_NAME); } - public PtCountsConfigGroup ptCounts() { - return (PtCountsConfigGroup) this.getModule(PtCountsConfigGroup.GROUP_NAME); - } - public TransitConfigGroup transit() { return (TransitConfigGroup) this.getModule(TransitConfigGroup.GROUP_NAME); } diff --git a/matsim/src/main/java/org/matsim/core/controler/ControlerDefaultsModule.java b/matsim/src/main/java/org/matsim/core/controler/ControlerDefaultsModule.java index 311c3ca9216..bd64b584d38 100755 --- a/matsim/src/main/java/org/matsim/core/controler/ControlerDefaultsModule.java +++ b/matsim/src/main/java/org/matsim/core/controler/ControlerDefaultsModule.java @@ -44,7 +44,6 @@ import org.matsim.core.utils.timing.TimeInterpretationModule; import org.matsim.counts.CountsModule; import org.matsim.guice.DependencyGraphModule; -import org.matsim.pt.counts.PtCountsModule; import org.matsim.vis.snapshotwriters.SnapshotWritersModule; import javax.imageio.ImageIO; @@ -74,7 +73,6 @@ public void install() { install(new ScoreStatsModule()); install(new ModeStatsModule()); install(new CountsModule()); - install(new PtCountsModule()); install(new VspPlansCleanerModule()); install(new SnapshotWritersModule()); install(new DependencyGraphModule()); diff --git a/matsim/src/main/java/org/matsim/pt/counts/OccupancyAnalyzer.java b/matsim/src/main/java/org/matsim/pt/counts/OccupancyAnalyzer.java deleted file mode 100644 index 46f103ab0f0..00000000000 --- a/matsim/src/main/java/org/matsim/pt/counts/OccupancyAnalyzer.java +++ /dev/null @@ -1,326 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * CalcTrRouteStats.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2011 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -package org.matsim.pt.counts; - -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.IdMap; -import org.matsim.api.core.v01.events.PersonEntersVehicleEvent; -import org.matsim.api.core.v01.events.PersonLeavesVehicleEvent; -import org.matsim.api.core.v01.events.TransitDriverStartsEvent; -import org.matsim.api.core.v01.events.handler.PersonEntersVehicleEventHandler; -import org.matsim.api.core.v01.events.handler.PersonLeavesVehicleEventHandler; -import org.matsim.api.core.v01.events.handler.TransitDriverStartsEventHandler; -import org.matsim.api.core.v01.population.Person; -import org.matsim.core.api.experimental.events.VehicleArrivesAtFacilityEvent; -import org.matsim.core.api.experimental.events.VehicleDepartsAtFacilityEvent; -import org.matsim.core.api.experimental.events.handler.VehicleArrivesAtFacilityEventHandler; -import org.matsim.core.api.experimental.events.handler.VehicleDepartsAtFacilityEventHandler; -import org.matsim.pt.transitSchedule.api.TransitStopFacility; -import org.matsim.vehicles.Vehicle; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; - -/** - * @author yChen - * @author mrieser / senozon - */ -public class OccupancyAnalyzer implements PersonEntersVehicleEventHandler, PersonLeavesVehicleEventHandler, - VehicleArrivesAtFacilityEventHandler, VehicleDepartsAtFacilityEventHandler, TransitDriverStartsEventHandler { - - private static final Logger log = LogManager.getLogger(OccupancyAnalyzer.class); - - private final int timeBinSize, maxSlotIndex; - private final double maxTime; - /** Map< stopFacilityId,value[]> */ - private Map, int[]> boards, alights, occupancies; - - /** Map< vehId,stopFacilityId> */ -// private final IdMap> vehStops = new IdMap<>(Vehicle.class, Id.class); - private final Map, Id> vehStops = new HashMap<>(); - /** Map */ - private final Map, Integer> vehPassengers = new HashMap<>(); - private StringBuffer occupancyRecord = new StringBuffer("time\tvehId\tStopId\tno.ofPassengersInVeh\n"); - private final Set> transitDrivers = new HashSet<>(); - private final Set> transitVehicles = new HashSet<>(); - - public OccupancyAnalyzer(final int timeBinSize, final double maxTime) { - this.timeBinSize = timeBinSize; - this.maxTime = maxTime; - this.maxSlotIndex = ((int) this.maxTime) / this.timeBinSize + 1; - this.boards = new IdMap<>(TransitStopFacility.class); - this.alights = new IdMap<>(TransitStopFacility.class); - this.occupancies = new IdMap<>(TransitStopFacility.class); - } - - public void setBoards(Map, int[]> boards) { - this.boards = boards; - } - - public void setAlights(Map, int[]> alights) { - this.alights = alights; - } - - public void setOccupancies(Map, int[]> occupancies) { - this.occupancies = occupancies; - } - - public int getTimeSlotIndex(final double time) { - if (time > this.maxTime) { - return this.maxSlotIndex; - } - return ((int) time / this.timeBinSize); - } - - @Override - public void reset(int iteration) { - this.boards.clear(); - this.alights.clear(); - this.occupancies.clear(); - this.vehStops.clear(); - this.vehPassengers.clear(); - this.occupancyRecord = new StringBuffer("time\tvehId\tStopId\tno.ofPassengersInVeh\n"); - this.transitDrivers.clear(); - this.transitVehicles.clear(); - } - - @Override - public void handleEvent(TransitDriverStartsEvent event) { - this.transitDrivers.add(event.getDriverId()); - this.transitVehicles.add(event.getVehicleId()); - } - - @Override - public void handleEvent(PersonEntersVehicleEvent event) { - if (this.transitDrivers.contains(event.getPersonId()) || !this.transitVehicles.contains(event.getVehicleId())) { - return; // ignore transit drivers or persons entering non-transit vehicles - } - - Id vehId = event.getVehicleId(); - Id stopId = this.vehStops.get(vehId); - double time = event.getTime(); - // --------------------------getOns--------------------------- - int[] getOn = this.boards.get(stopId); - if (getOn == null) { - getOn = new int[this.maxSlotIndex + 1]; - this.boards.put(stopId, getOn); - } - getOn[getTimeSlotIndex(time)]++; - // ------------------------veh_passenger--------------------------- - Integer nPassengers = this.vehPassengers.get(vehId); - this.vehPassengers.put(vehId, (nPassengers != null) ? (nPassengers + 1) : 1); - this.occupancyRecord.append("time :\t").append(time).append(" veh :\t").append(vehId).append(" has Passenger\t").append(this.vehPassengers.get(vehId)).append(" \tat stop :\t").append(stopId).append(" ENTERING PERSON :\t").append(event.getPersonId()).append("\n"); - } - - @Override - public void handleEvent(PersonLeavesVehicleEvent event) { - if (this.transitDrivers.contains(event.getPersonId()) || !this.transitVehicles.contains(event.getVehicleId())) { - return; // ignore transit drivers or persons entering non-transit vehicles - } - - Id vehId = event.getVehicleId(); - Id stopId = this.vehStops.get(vehId); - double time = event.getTime(); - // --------------------------getDowns--------------------------- - int[] getDown = this.alights.get(stopId); - if (getDown == null) { - getDown = new int[this.maxSlotIndex + 1]; - this.alights.put(stopId, getDown); - } - getDown[getTimeSlotIndex(time)]++; - // ------------------------veh_passenger--------------------------- - Integer nPassengers = this.vehPassengers.get(vehId); - if (nPassengers == null) { - log.error( "tests for `null' but exception says 'negative'??? kai, oct'10 ") ; - throw new RuntimeException("negative passenger-No. in vehicle?"); - } - this.vehPassengers.put(vehId, nPassengers - 1); - if (this.vehPassengers.get(vehId).intValue() == 0) { - this.vehPassengers.remove(vehId); - } - - Integer passengers = this.vehPassengers.get(vehId); - this.occupancyRecord.append("time :\t").append(time).append(" veh :\t").append(vehId).append(" has Passenger\t").append((passengers != null) ? passengers : 0).append("\n"); - } - - @Override - public void handleEvent(VehicleArrivesAtFacilityEvent event) { - Id stopId = event.getFacilityId(); - this.vehStops.put(event.getVehicleId(), stopId); - } - - @Override - public void handleEvent(VehicleDepartsAtFacilityEvent event) { - Id stopId = event.getFacilityId(); - Id vehId = event.getVehicleId(); - this.vehStops.remove(vehId); - // -----------------------occupancy-------------------------------- - int[] occupancyAtStop = this.occupancies.get(stopId); - - if (occupancyAtStop == null) { - // no previous departure from this stop, therefore no occupancy record yet. Create this: - occupancyAtStop = new int[this.maxSlotIndex + 1]; - this.occupancies.put(stopId, occupancyAtStop); - } - - Integer noPassengersInVeh = this.vehPassengers.get(vehId); - - if (noPassengersInVeh != null) { - occupancyAtStop[this.getTimeSlotIndex(event.getTime())] += noPassengersInVeh; - - this.occupancyRecord.append(event.getTime()); - this.occupancyRecord.append("\t"); - this.occupancyRecord.append(vehId); - this.occupancyRecord.append("\t"); - this.occupancyRecord.append(stopId); - this.occupancyRecord.append("\t"); - this.occupancyRecord.append(noPassengersInVeh); - this.occupancyRecord.append("\n"); - } - } - - /** - * @param stopId - * @return Array containing the number of agents boarding at the stop - * stopId per time bin, starting with time bin 0 from 0 - * seconds to (timeBinSize-1)seconds. - */ - public int[] getBoardVolumesForStop(final Id stopId) { - int[] values = this.boards.get(stopId); - if (values == null) { - return new int[this.maxSlotIndex + 1]; - } - return values; - } - - /** - * @param stopId - * @return Array containing the number of agents alighting at the stop - * {@code stopId} per time bin, starting with time bin 0 from 0 - * seconds to (timeBinSize-1)seconds. - */ - public int[] getAlightVolumesForStop(final Id stopId) { - int[] values = this.alights.get(stopId); - if (values == null) { - return new int[this.maxSlotIndex + 1]; - } - return values; - } - - /** - * @param stopId - * @return Array containing the number of passengers in bus after the - * transfer at the stop {@code stopId} per time bin, starting with - * time bin 0 from 0 seconds to (timeBinSize-1)seconds. - */ - public int[] getOccupancyVolumesForStop(final Id stopId) { - int[] values = this.occupancies.get(stopId); - if (values == null) { - return new int[this.maxSlotIndex + 1]; - } - return values; - } - - /** - * @return Set of {@code Id}s containing all stop ids, where the agents - * boarded, for which counting-values are available. - */ - public Set> getBoardStopIds() { - return this.boards.keySet(); - } - - /** - * @return Set of {@code Id}s containing all stop ids, where the agents - * alit, for which counting-values are available. - */ - public Set> getAlightStopIds() { - return this.alights.keySet(); - } - - public Set> getOccupancyStopIds() { - return this.occupancies.keySet(); - } - - /** - * @return Set of {@code Id}s containing all stop ids, where the agents alit - * or/and boarded, for which counting-values are available. - */ - public Set> getAllStopIds() { - Set> allStopIds = new TreeSet<>(); - allStopIds.addAll(getBoardStopIds()); - allStopIds.addAll(getAlightStopIds()); - allStopIds.addAll(getOccupancyStopIds()); - return allStopIds; - } - - public void write(String filename) { - SimpleWriter writer = new SimpleWriter(filename); - // write filehead - writer.write("stopId\t"); - for (int i = 0; i < 24; i++) { - writer.write("bo" + i + "-" + (i + 1) + "\t"); - } - for (int i = 0; i < 24; i++) { - writer.write("al" + i + "-" + (i + 1) + "\t"); - } - for (int i = 0; i < 24; i++) { - writer.write("oc" + i + "-" + (i + 1) + "\t"); - } - writer.writeln(); - // write content - for (Id stopId : getAllStopIds()) { - writer.write(stopId + "\t"); - - int[] board = this.boards.get(stopId); - if (board == null){ - log.debug("stopId:\t" + stopId + "\thas null boards!"); - } - for (int i = 0; i < 24; i++) { - writer.write((board != null ? board[i] : 0) + "\t"); - } - - int[] alight = this.alights.get(stopId); - if (alight == null) { - log.debug("stopId:\t" + stopId + "\thas null alights!"); - } - for (int i = 0; i < 24; i++) { - writer.write((alight != null ? alight[i] : 0) + "\t"); - } - - int[] ocuppancy = this.occupancies.get(stopId); - if (ocuppancy == null) { - log.debug("stopId:\t" + stopId + "\tthere aren't passengers in Bus after the transfer!"); - } - for (int i = 0; i < 24; i++) { - writer.write((ocuppancy != null ? ocuppancy[i] : 0) + "\t"); - } - writer.writeln(); - } - writer.write(this.occupancyRecord.toString()); - writer.close(); - } -} diff --git a/matsim/src/main/java/org/matsim/pt/counts/PtCountControlerListener.java b/matsim/src/main/java/org/matsim/pt/counts/PtCountControlerListener.java deleted file mode 100644 index 34ce1915824..00000000000 --- a/matsim/src/main/java/org/matsim/pt/counts/PtCountControlerListener.java +++ /dev/null @@ -1,191 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * CountControlerListener.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2007 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -package org.matsim.pt.counts; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.matsim.analysis.IterationStopWatch; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.network.Network; -import org.matsim.core.api.experimental.events.EventsManager; -import org.matsim.core.config.Config; -import org.matsim.core.config.groups.PtCountsConfigGroup; -import org.matsim.core.controler.OutputDirectoryHierarchy; -import org.matsim.core.controler.events.AfterMobsimEvent; -import org.matsim.core.controler.events.BeforeMobsimEvent; -import org.matsim.core.controler.events.IterationEndsEvent; -import org.matsim.core.controler.events.StartupEvent; -import org.matsim.core.controler.listener.AfterMobsimListener; -import org.matsim.core.controler.listener.BeforeMobsimListener; -import org.matsim.core.controler.listener.IterationEndsListener; -import org.matsim.core.controler.listener.StartupListener; -import org.matsim.counts.Counts; -import org.matsim.counts.MatsimCountsReader; -import org.matsim.counts.algorithms.CountsComparisonAlgorithm; -import org.matsim.pt.transitSchedule.api.TransitStopFacility; - -import jakarta.inject.Inject; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - -public class PtCountControlerListener implements StartupListener, IterationEndsListener, -BeforeMobsimListener, AfterMobsimListener { - - private EventsManager eventsManager; - private OutputDirectoryHierarchy controlerIO; - private IterationStopWatch iterationStopWatch; - private Network network; - - private static enum CountType { Boarding, Alighting, Occupancy } - - private static final Logger log = LogManager.getLogger(PtCountControlerListener.class); - - /* - * String used to identify the operation in the IterationStopWatch. - */ - public static final String OPERATION_COMPAREPTCOUNTS = "compare with pt counts"; - - private final static String MODULE_NAME = "ptCounts"; - // yy the above should be removed; the commands should be replaced by the "typed" commands. kai, oct'10 - - private final Config config; - private final Counts boardCounts, alightCounts,occupancyCounts; - private final OccupancyAnalyzer occupancyAnalyzer; - - @Inject - PtCountControlerListener(final Config config, EventsManager eventsManager, OutputDirectoryHierarchy controlerIO, IterationStopWatch iterationStopWatch, Network network) { - this.eventsManager = eventsManager; - this.controlerIO = controlerIO; - this.iterationStopWatch = iterationStopWatch; - this.network = network; - log.info("Using pt counts."); - this.config = config; - this.boardCounts = new Counts(); - this.alightCounts = new Counts(); - this.occupancyCounts = new Counts(); - this.occupancyAnalyzer = new OccupancyAnalyzer(3600, 24 * 3600 - 1) ; - } - - @Override - public void notifyStartup(final StartupEvent controlerStartupEvent) { - PtCountsConfigGroup ptCounts = this.config.ptCounts(); - String boardCountsFilename = ptCounts.getBoardCountsFileName(); - String alightCountsFilename = ptCounts.getAlightCountsFileName(); - String occupancyCountsFilename = ptCounts.getOccupancyCountsFileName(); - if (boardCountsFilename == null || alightCountsFilename == null || occupancyCountsFilename == null) { - throw new RuntimeException("for pt counts, at this point all three files must be given!"); - } - new MatsimCountsReader(this.alightCounts).readFile(alightCountsFilename); - new MatsimCountsReader(this.boardCounts).readFile(boardCountsFilename); - new MatsimCountsReader(this.occupancyCounts).readFile(occupancyCountsFilename); - } - - @Override - public void notifyBeforeMobsim(BeforeMobsimEvent event) { - int iter = event.getIteration(); - if ( isActiveInThisIteration( iter ) ) { - occupancyAnalyzer.reset(iter); - eventsManager.addHandler(occupancyAnalyzer); - } - } - - @Override - public void notifyAfterMobsim(AfterMobsimEvent event) { - int it = event.getIteration(); - if ( isActiveInThisIteration( it ) ) { - eventsManager.removeHandler(occupancyAnalyzer); - occupancyAnalyzer.write(controlerIO.getIterationFilename(it, "occupancyAnalysis.txt")); - } - } - - private boolean isActiveInThisIteration( int iter ) { - return iter % config.ptCounts().getPtCountsInterval() == 0 && iter >= config.controller().getFirstIteration(); - } - - @Override - public void notifyIterationEnds(final IterationEndsEvent event) { - int iter = event.getIteration(); - if ( isActiveInThisIteration( iter ) ) { - - iterationStopWatch.beginOperation(OPERATION_COMPAREPTCOUNTS); - - double countsScaleFactor = Double.parseDouble(this.config.getParam(MODULE_NAME, "countsScaleFactor")); - - Map cca = new HashMap(); - cca.put( CountType.Boarding, new CountsComparisonAlgorithm(new CountsComparisonAlgorithm.VolumesForId() { - - @Override - public double[] getVolumesForStop(Id locationId) { - return copyFromIntArray(occupancyAnalyzer.getBoardVolumesForStop(locationId)); - } - }, this.boardCounts, network, countsScaleFactor)) ; - cca.put( CountType.Alighting, new CountsComparisonAlgorithm(new CountsComparisonAlgorithm.VolumesForId() { - - @Override - public double[] getVolumesForStop(Id locationId) { - return copyFromIntArray(occupancyAnalyzer.getAlightVolumesForStop(locationId)); - } - }, this.alightCounts, network, countsScaleFactor) ) ; - cca.put( CountType.Occupancy, new CountsComparisonAlgorithm(new CountsComparisonAlgorithm.VolumesForId() { - - @Override - public double[] getVolumesForStop(Id locationId) { - return copyFromIntArray(occupancyAnalyzer.getOccupancyVolumesForStop(locationId)); - } - }, this.occupancyCounts, network, countsScaleFactor) ) ; - - String distanceFilterStr = this.config.findParam(MODULE_NAME, "distanceFilter"); - String distanceFilterCenterNodeId = this.config.findParam(MODULE_NAME, "distanceFilterCenterNode"); - - if ((distanceFilterStr != null) && (distanceFilterCenterNodeId != null)) { - - - for ( CountsComparisonAlgorithm algo : cca.values() ) { - algo.setCountCoordUsingDistanceFilter(Double.parseDouble(distanceFilterStr), distanceFilterCenterNodeId) ; - } - } - for ( CountsComparisonAlgorithm algo : cca.values() ) { - algo.setCountsScaleFactor(countsScaleFactor); - algo.run(); - } - - String outputFormat = this.config.findParam(MODULE_NAME, "outputformat"); - if (outputFormat.contains("txt") || outputFormat.contains("all")) { - for ( Entry entry : cca.entrySet() ) { - CountsComparisonAlgorithm algo = entry.getValue() ; - new PtCountSimComparisonTableWriter(algo.getComparison()).write(controlerIO.getIterationFilename(iter, "simCountCompare" + entry.getKey().toString() + ".txt")); - } - } - - iterationStopWatch.endOperation(OPERATION_COMPAREPTCOUNTS); - } - } - - private static double[] copyFromIntArray(int[] source) { - double[] dest = new double[source.length]; - for(int i=0; i countSimCompList; - - public PtCountSimComparisonTableWriter(List countSimCompList) { - this.countSimCompList = countSimCompList; - } - - @Override - public void write(String filename) { - SimpleWriter simpleWriter = null; - try { - simpleWriter = new SimpleWriter(filename); - Id lastStopId = null; - // Sorted by stopId - for (CountSimComparison count : countSimCompList) { - Id stopId = Id.create(count.getId(), TransitStopFacility.class); - if (!stopId.equals(lastStopId)) { - simpleWriter.write("StopId :\t"); - simpleWriter.write(stopId.toString()); - simpleWriter.write("\nhour\tsimVal\tscaledSimVal\tcountVal\n"); - lastStopId = stopId; - } - simpleWriter.write(count.getHour()); - simpleWriter.write('\t'); - - double countValue = count.getCountValue(); - double simValue = count.getSimulationValue(); - - simpleWriter.write(simValue); - simpleWriter.write('\t'); - - simpleWriter.write(simValue); - simpleWriter.write('\t'); - simpleWriter.write(countValue); - simpleWriter.write('\n'); - - } - } finally { - if (simpleWriter != null) { - simpleWriter.close(); - } - } - } - -} diff --git a/matsim/src/main/java/org/matsim/pt/counts/PtCountsLoadCurveGraphCreator.java b/matsim/src/main/java/org/matsim/pt/counts/PtCountsLoadCurveGraphCreator.java deleted file mode 100644 index 536cda45fe6..00000000000 --- a/matsim/src/main/java/org/matsim/pt/counts/PtCountsLoadCurveGraphCreator.java +++ /dev/null @@ -1,83 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * PtCountsLoadCurveGraphCreator.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2010 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -/** - * - */ -package org.matsim.pt.counts; - -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.network.Link; -import org.matsim.counts.CountSimComparison; -import org.matsim.counts.algorithms.graphs.CountsGraph; -import org.matsim.counts.algorithms.graphs.CountsGraphsCreator; -import org.matsim.counts.algorithms.graphs.CountsLoadCurveGraph; -import org.matsim.counts.algorithms.graphs.helper.MyURL; - -public class PtCountsLoadCurveGraphCreator extends CountsGraphsCreator { - - /** - * @param sectionTitle - */ - public PtCountsLoadCurveGraphCreator(String sectionTitle) { - super(sectionTitle); - } - @Override - public List createGraphs(List ccl, - int iteration) { - List graphList=new Vector(); - - Iterator l_it = ccl.iterator(); - CountSimComparison cc_last=null; - while (l_it.hasNext()) { - CountsLoadCurveGraph lcg=new CountsLoadCurveGraph(ccl, iteration, "dummy"); - if (cc_last!=null) { - lcg.add2LoadCurveDataSets(cc_last); - } - CountSimComparison cc= l_it.next(); - Id stopId = cc.getId(); - while (cc.getId().equals(stopId)) { - if (l_it.hasNext()) { - lcg.add2LoadCurveDataSets(cc); - cc= l_it.next(); - } - else { - lcg.add2LoadCurveDataSets(cc); - break; - } - } - lcg.setChartTitle("Stop "+stopId); - lcg.setFilename("stop"+stopId); - lcg.setLinkId(stopId.toString()); - lcg.createChart(0); - graphList.add(lcg); - this.section.addURL(new MyURL("stop"+stopId+".html", "stop"+stopId)); - cc_last=cc; - }//while - - - return graphList; - } - -} diff --git a/matsim/src/main/java/org/matsim/pt/counts/PtCountsModule.java b/matsim/src/main/java/org/matsim/pt/counts/PtCountsModule.java deleted file mode 100644 index df66130b507..00000000000 --- a/matsim/src/main/java/org/matsim/pt/counts/PtCountsModule.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * *********************************************************************** * - * * project: org.matsim.* - * * PtCountsModule.java - * * * - * * *********************************************************************** * - * * * - * * copyright : (C) 2014 by the members listed in the COPYING, * - * * LICENSE and WARRANTY file. * - * * email : info at matsim dot org * - * * * - * * *********************************************************************** * - * * * - * * This program is free software; you can redistribute it and/or modify * - * * it under the terms of the GNU General Public License as published by * - * * the Free Software Foundation; either version 2 of the License, or * - * * (at your option) any later version. * - * * See also COPYING, LICENSE and WARRANTY file * - * * * - * * *********************************************************************** - */ - -package org.matsim.pt.counts; - -import org.matsim.core.controler.AbstractModule; - -public class PtCountsModule extends AbstractModule { - @Override - public void install() { - if (getConfig().transit().isUseTransit()) { - if (getConfig().ptCounts().getAlightCountsFileName() != null) { - // only works when all three files are defined! kai, oct'10 - addControlerListenerBinding().to(PtCountControlerListener.class); - } - } - } -} diff --git a/matsim/src/main/java/org/matsim/pt/counts/SimpleWriter.java b/matsim/src/main/java/org/matsim/pt/counts/SimpleWriter.java deleted file mode 100644 index 0eab92583e4..00000000000 --- a/matsim/src/main/java/org/matsim/pt/counts/SimpleWriter.java +++ /dev/null @@ -1,112 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * * - * *********************************************************************** * - * * - * copyright : (C) 2011 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -package org.matsim.pt.counts; - -import java.io.BufferedWriter; -import java.io.Closeable; -import java.io.Flushable; -import java.io.IOException; - -import org.matsim.core.utils.io.IOUtils; -import org.matsim.core.utils.io.UncheckedIOException; - -/** - * a small and simple writer, in order to avoid copious "try" and "catch" for - * "Exception" - * - * @author yChen - * - */ -public class SimpleWriter implements Closeable, Flushable { - - private final BufferedWriter writer; - - public SimpleWriter(final String outputFilename) { - writer = IOUtils.getBufferedWriter(outputFilename); - } - - public void write(char[] c) { - if (writer != null) - try { - writer.write(c); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } - - public void write(char c) { - if (writer != null) - try { - writer.write(c); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } - - public void write(String s) { - if (writer != null) { - try { - writer.write(s); - } catch (IOException e) { - System.err.println("writer was not initialized yet!"); - throw new UncheckedIOException(e); - } - } - } - - public void write(Object o) { - write(o.toString()); - } - - public void writeln(String s) { - write(s + "\n"); - } - - public void writeln(Object o) { - write(o + "\n"); - } - - public void writeln() { - write('\n'); - } - - @Override - public void close() { - try { - writer.close(); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } - - @Override - public void flush() { - try { - writer.flush(); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } - - public void writeln(StringBuffer line) { - writeln(line.toString()); - } - -} diff --git a/matsim/src/main/java/org/matsim/pt/counts/obsolete/PtBiasErrorGraph.java b/matsim/src/main/java/org/matsim/pt/counts/obsolete/PtBiasErrorGraph.java deleted file mode 100644 index 2b29bf12005..00000000000 --- a/matsim/src/main/java/org/matsim/pt/counts/obsolete/PtBiasErrorGraph.java +++ /dev/null @@ -1,143 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * PtBiasErrorGraph.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2010 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -/** - * - */ -package org.matsim.pt.counts.obsolete; - -import java.awt.Font; -import java.util.List; - -import org.jfree.chart.ChartFactory; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.axis.AxisLocation; -import org.jfree.chart.axis.CategoryAxis; -import org.jfree.chart.axis.NumberAxis; -import org.jfree.chart.axis.ValueAxis; -import org.jfree.chart.labels.StandardCategoryToolTipGenerator; -import org.jfree.chart.plot.CategoryPlot; -import org.jfree.chart.plot.DatasetRenderingOrder; -import org.jfree.chart.plot.PlotOrientation; -import org.jfree.chart.renderer.category.LineAndShapeRenderer; -import org.jfree.data.category.DefaultCategoryDataset; -import org.matsim.counts.ComparisonErrorStatsCalculator; -import org.matsim.counts.CountSimComparison; -import org.matsim.counts.algorithms.graphs.CountsGraph; - -/** - * @author yu - * - */ -public final class PtBiasErrorGraph extends CountsGraph { - private ComparisonErrorStatsCalculator errorStats; - private String chartTitle; - - /** - * @param ccl - * @param iteration - * @param filename - * @param chartTitle - */ - @Deprecated // use standard counts package - public PtBiasErrorGraph(List ccl, int iteration, - String filename, String chartTitle) { - super(ccl, iteration, filename, chartTitle); - this.chartTitle = chartTitle; - } - - @Override - @Deprecated // use standard counts package - public JFreeChart createChart(final int nbr) { - DefaultCategoryDataset dataset0 = new DefaultCategoryDataset(); - DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); - - this.errorStats = new ComparisonErrorStatsCalculator(this.ccl_); - - double[] meanRelError = errorStats.getMeanRelError(); - // double[] meanAbsError = errorStats.getMeanAbsError(); - double[] meanAbsBias = errorStats.getMeanBias(); - - for (int h = 0; h < 24; h++) { - dataset0.addValue(meanRelError[h], "Mean rel error", Integer - .toString(h + 1)); - // dataset1.addValue(meanAbsError[h], "Mean abs error", - // Integer.toString(h + 1)); - dataset1.addValue(meanAbsBias[h], "Mean bias", Integer - .toString(h + 1)); - } - - this.chart_ = ChartFactory.createLineChart(this.chartTitle, "Hour", - "Mean rel error [%]", dataset0, PlotOrientation.VERTICAL, true, // legend? - true, // tooltips? - false // URLs? - ); - CategoryPlot plot = this.chart_.getCategoryPlot(); - plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); - plot.setDataset(1, dataset1); - plot.mapDatasetToRangeAxis(1, 1); - - final LineAndShapeRenderer renderer = new LineAndShapeRenderer(); - renderer.setSeriesToolTipGenerator(0, - new StandardCategoryToolTipGenerator()); - plot.setRenderer(0, renderer); - - final CategoryAxis axis1 = new CategoryAxis("Hour"); - axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7)); - plot.setDomainAxis(axis1); - - // final ValueAxis axis2 = new - // NumberAxis("Mean abs {bias, error} [veh/h]"); - final ValueAxis axis2 = new NumberAxis("Mean abs bias [veh/h]"); - plot.setRangeAxis(1, axis2); - - final ValueAxis axis3 = plot.getRangeAxis(0); - axis3.setRange(0.0, 100.0); - - final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); - renderer2.setSeriesToolTipGenerator(0, - new StandardCategoryToolTipGenerator()); - renderer2.setSeriesToolTipGenerator(1, - new StandardCategoryToolTipGenerator()); - // renderer2.setSeriesPaint(0, Color.black); - plot.setRenderer(1, renderer2); - plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); - - return this.chart_; - } - - @Deprecated // use standard counts package - public double[] getMeanRelError() { - if (this.errorStats == null) { - throw new RuntimeException( - "Object not initialized correctly. Call createChart(..) first!"); - } - return this.errorStats.getMeanRelError(); - } - - @Deprecated // use standard counts package - public double[] getMeanAbsBias() { - if (this.errorStats == null) { - throw new RuntimeException( - "Object not initialized correctly. Call createChart(..) first!"); - } - return this.errorStats.getMeanBias(); - } -} \ No newline at end of file diff --git a/matsim/src/main/java/org/matsim/pt/counts/obsolete/PtCountSimComparisonWriter.java b/matsim/src/main/java/org/matsim/pt/counts/obsolete/PtCountSimComparisonWriter.java deleted file mode 100644 index 86e14b88b1d..00000000000 --- a/matsim/src/main/java/org/matsim/pt/counts/obsolete/PtCountSimComparisonWriter.java +++ /dev/null @@ -1,67 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * PtCountSimComparisonWriter.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2010 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -/** - * - */ -package org.matsim.pt.counts.obsolete; - -import java.util.List; - -import org.matsim.core.api.internal.MatsimSomeWriter; -import org.matsim.counts.CountSimComparison; -import org.matsim.counts.algorithms.CountSimComparisonTimeFilter; - -@Deprecated // we should try to rather make CountSimComparisonKMLWriter more general. kai, dec'13 -public abstract class PtCountSimComparisonWriter implements MatsimSomeWriter { - public enum PtCountsType { - Boarding, Alighting, Occupancy - } - - @Deprecated // we should try to rather make CountSimComparisonKMLWriter more general. kai, dec'13 - protected int iter; - - @Deprecated // we should try to rather make CountSimComparisonKMLWriter more general. kai, dec'13 - protected CountSimComparisonTimeFilter boardCountComparisonFilter, alightCountComparisonFilter, occupancyCountComparisonFilter; - - /** - * - */ - @Deprecated // we should try to rather make CountSimComparisonKMLWriter more general. kai, dec'13 - public PtCountSimComparisonWriter(final List boardCountSimCompList, final List alightCountSimCompList, final List occupancyCountSimCompList) { - if ( boardCountSimCompList != null ) { - this.boardCountComparisonFilter = new CountSimComparisonTimeFilter(boardCountSimCompList); - } - if ( alightCountSimCompList!=null ) { - this.alightCountComparisonFilter = new CountSimComparisonTimeFilter(alightCountSimCompList); - } - if ( occupancyCountSimCompList != null ) { - this.occupancyCountComparisonFilter = new CountSimComparisonTimeFilter(occupancyCountSimCompList); - } - } - - @Deprecated // we should try to rather make CountSimComparisonKMLWriter more general. kai, dec'13 - public abstract void writeFile(final String filename); - - @Deprecated // we should try to rather make CountSimComparisonKMLWriter more general. kai, dec'13 - public void setIterationNumber(int iter) { - this.iter = iter; - } -} diff --git a/matsim/src/main/java/org/matsim/pt/counts/obsolete/PtCountsSimRealPerHourGraph.java b/matsim/src/main/java/org/matsim/pt/counts/obsolete/PtCountsSimRealPerHourGraph.java deleted file mode 100644 index 9a50b9a232c..00000000000 --- a/matsim/src/main/java/org/matsim/pt/counts/obsolete/PtCountsSimRealPerHourGraph.java +++ /dev/null @@ -1,234 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * CountsSimRealPerHourGraph.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2007 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -package org.matsim.pt.counts.obsolete; - -import java.awt.Color; -import java.awt.Font; -import java.awt.geom.Ellipse2D; -import java.awt.geom.Rectangle2D; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.jfree.chart.ChartFactory; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.annotations.XYTextAnnotation; -import org.jfree.chart.axis.LogarithmicAxis; -import org.jfree.chart.labels.CustomXYToolTipGenerator; -import org.jfree.chart.plot.PlotOrientation; -import org.jfree.chart.plot.XYPlot; -import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; -import org.jfree.chart.urls.CustomXYURLGenerator; -import org.jfree.data.xy.DefaultXYDataset; -import org.jfree.data.xy.XYSeries; -import org.jfree.data.xy.XYSeriesCollection; -import org.matsim.counts.CountSimComparison; -import org.matsim.counts.algorithms.graphs.CountsGraph; -import org.matsim.counts.algorithms.graphs.helper.Comp; -import org.matsim.counts.algorithms.graphs.helper.MyComparator; -import org.matsim.pt.counts.obsolete.PtCountSimComparisonWriter.PtCountsType; - -public final class PtCountsSimRealPerHourGraph extends CountsGraph { - /** - * The time at which the data was measured. A value in 1..24, 1 for 0 a.m. - * to 1 a.m., 2 for 1 a.m. to 2 a.m. ... - */ - private int hour; - /** - * the String type of Counts, e.g. "board" or "alight" - */ - private PtCountsType countsType; - - @Deprecated // use standard counts package - public PtCountsSimRealPerHourGraph(final List ccl, - final int iteration, final String filename, PtCountsType countsType) { - super(ccl, iteration, filename, filename); - this.countsType = countsType; - } - - /** - * @param hour - * A value in 1..24, 1 for 0 a.m. to 1 a.m., 2 for 1 a.m. to 2 - * a.m. ... - */ - @Override - @Deprecated // use standard counts package - public JFreeChart createChart(final int hour) { - this.hour = hour; - - XYSeriesCollection dataset0 = new XYSeriesCollection(); - XYSeries series = new XYSeries("MATSim volumes"); - // easier to use another dataset - XYSeriesCollection dataset_outliers = new XYSeriesCollection(); - XYSeries series_outliers = new XYSeries("MATSim outliers"); - - CustomXYURLGenerator url_gen = new CustomXYURLGenerator(); - CustomXYToolTipGenerator tt_gen = new CustomXYToolTipGenerator(); - - final ArrayList urls = new ArrayList(); - final ArrayList tooltips = new ArrayList(); - List comps = new Vector(); - - Iterator l_it = this.ccl_.iterator(); - // int elementCounter=0; - while (l_it.hasNext()) { - CountSimComparison cc = l_it.next(); - - /* - * values with simVal==0.0 or countVal==0.0 are drawn on the x==1 - * or/and y==1-line Such values are the result of a poor simulation - * run, but they can also represent a valid result (closing summer - * road during winter time) - */ - if (cc.getHour() == hour) { - // elementCounter++; - double realVal = 1.0; - double simVal = 1.0; - if (cc.getCountValue() > 0.0 && cc.getSimulationValue() > 0.0) { - realVal = cc.getCountValue(); - simVal = cc.getSimulationValue(); - series.add(realVal, simVal); - comps.add(new Comp(realVal, "link" + cc.getId() + ".html", - "Link " + cc.getId() + "; " + "Count: " + realVal - + ", Sim: " + simVal)); - } else { - realVal = Math.max(1.0, cc.getCountValue()); - simVal = Math.max(1.0, cc.getSimulationValue()); - series_outliers.add(realVal, simVal); - } - - }// if - }// while - dataset0.addSeries(series); - dataset_outliers.addSeries(series_outliers); - - /* - * first we have to sort the vector according to the rendering ordering - * (which is the x value). REALLY??? After hours of searching no better - * solution found! please help! - */ - - Collections.sort(comps, new MyComparator()); - - for (Iterator iter = comps.iterator(); iter.hasNext();) { - Comp cp = iter.next(); - urls.add(cp.getURL()); - tooltips.add(cp.getTooltip()); - } - - url_gen.addURLSeries(urls); - tt_gen.addToolTipSeries(tooltips); - - String title = "[" + this.countsType + "]\tVolumes " + (hour - 1) - + ":00 - " + (hour) + ":00, Iteration: " + this.iteration_; - this.setChartTitle(title); - this.chart_ = ChartFactory.createXYLineChart(title, - "Count Volumes [veh/h]", // x axis label - "Sim Volumes [veh/h]", // y axis label - dataset0, // data - PlotOrientation.VERTICAL, false, // include legend - true, // tooltips - true // urls - ); - XYPlot plot = this.chart_.getXYPlot(); - final LogarithmicAxis axis_x = new LogarithmicAxis( - "Count Volumes [veh/h]"); - final LogarithmicAxis axis_y = new LogarithmicAxis( - "Sim Volumes [veh/h]"); - axis_x.setAllowNegativesFlag(false); - axis_y.setAllowNegativesFlag(false); - - // regular values - XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); - renderer.setDefaultLinesVisible(false); - renderer.setURLGenerator(url_gen); - renderer.setSeriesPaint(0, Color.black); - renderer.setSeriesToolTipGenerator(0, tt_gen); - renderer - .setSeriesShape(0, new Rectangle2D.Double(-1.5, -1.5, 3.0, 3.0)); - - // outliers - XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); - renderer2.setDefaultLinesVisible(false); - renderer2.setSeriesPaint(0, Color.red); - renderer2.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0)); - - // error band - DefaultXYDataset dataset1 = new DefaultXYDataset(); - dataset1.addSeries("f1x", new double[][] { { 1.0, 10000.0 }, - { 1.0, 10000.0 } }); - dataset1.addSeries("f2x", new double[][] { { 1.0, 10000.0 }, - { 2.0, 20000.0 } }); - dataset1.addSeries("f05x", new double[][] { { 2.0, 10000.0 }, - { 1.0, 5000.0 } }); - - XYLineAndShapeRenderer renderer3 = new XYLineAndShapeRenderer(); - renderer3.setDefaultShapesVisible(false); - renderer3.setSeriesPaint(0, Color.blue); - renderer3.setSeriesPaint(1, Color.blue); - renderer3.setSeriesPaint(2, Color.blue); - renderer3.setDefaultSeriesVisibleInLegend(false); - renderer3.setSeriesItemLabelsVisible(0, true); - renderer3.setSeriesItemLabelsVisible(1, false); - renderer3.setSeriesItemLabelsVisible(2, false); - - XYTextAnnotation annotation0 = new XYTextAnnotation("2.0 count", - 12000.0, 15500.0); - annotation0.setFont(new Font("SansSerif", Font.BOLD, 11)); - plot.addAnnotation(annotation0); - XYTextAnnotation annotation1 = new XYTextAnnotation("count", 13000.0, - 10000.0); - annotation1.setFont(new Font("SansSerif", Font.BOLD, 11)); - plot.addAnnotation(annotation1); - XYTextAnnotation annotation2 = new XYTextAnnotation("0.5 count", - 11000.0, 3500.0); - annotation2.setFont(new Font("SansSerif", Font.BOLD, 11)); - plot.addAnnotation(annotation2); - - plot.setDomainAxis(axis_x); - plot.setRangeAxis(axis_y); - plot.setRenderer(0, renderer); - - plot.setRenderer(1, renderer2); - plot.setDataset(1, dataset_outliers); - - plot.setRenderer(2, renderer3); - plot.setDataset(2, dataset1); - - plot.getRangeAxis().setRange(1.0, 19000.0); - plot.getDomainAxis().setRange(1.0, 19000.0); - - return this.chart_; - }// drawGraph - - /** - * The time at which the data was measured. - * - * @return A value in 1..24, 1 for 0 a.m. to 1 a.m., 2 for 1 a.m. to 2 a.m. - * ... - */ - @Deprecated // use standard counts package - public int getHour() { - return this.hour; - } -} diff --git a/matsim/src/main/java/org/matsim/pt/counts/package-info.java b/matsim/src/main/java/org/matsim/pt/counts/package-info.java deleted file mode 100644 index 6a25ff406fd..00000000000 --- a/matsim/src/main/java/org/matsim/pt/counts/package-info.java +++ /dev/null @@ -1,25 +0,0 @@ - -/* *********************************************************************** * - * project: org.matsim.* - * package-info.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2019 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - - /** - * This package contains classes for Count functionality of "pt". Except OccupancyAnalyzer and SimpleWriter all the other classes in this package are modified copies of classes from org.matsim.counts. - */ -package org.matsim.pt.counts; \ No newline at end of file diff --git a/matsim/src/test/java/org/matsim/pt/counts/OccupancyAnalyzerTest.java b/matsim/src/test/java/org/matsim/pt/counts/OccupancyAnalyzerTest.java deleted file mode 100644 index 85fdcd5b79d..00000000000 --- a/matsim/src/test/java/org/matsim/pt/counts/OccupancyAnalyzerTest.java +++ /dev/null @@ -1,214 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * * - * *********************************************************************** * - * * - * copyright : (C) 2012 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -package org.matsim.pt.counts; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.Set; -import javax.xml.parsers.ParserConfigurationException; -import org.junit.Assert; -import org.junit.Test; -import org.matsim.api.core.v01.Coord; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.api.core.v01.network.Node; -import org.matsim.core.api.experimental.events.EventsManager; -import org.matsim.core.config.Config; -import org.matsim.core.config.ConfigUtils; -import org.matsim.core.controler.PrepareForSimUtils; -import org.matsim.core.events.EventsUtils; -import org.matsim.core.mobsim.qsim.QSimBuilder; -import org.matsim.core.population.io.PopulationReader; -import org.matsim.core.scenario.MutableScenario; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.pt.transitSchedule.TransitScheduleReaderV1; -import org.matsim.pt.transitSchedule.api.TransitStopFacility; -import org.matsim.vehicles.MatsimVehicleReader; -import org.xml.sax.SAXException; - -/** - * @author mrieser / senozon - */ -public class OccupancyAnalyzerTest { - - @Test - public void test_SinglePersonOccupancy() throws SAXException, ParserConfigurationException, IOException { - Fixture f = new Fixture(); - String scheduleXml = "" + - "" + - "" + - "" + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " train" + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - ""; - new TransitScheduleReaderV1(f.scenario).parse(new ByteArrayInputStream(scheduleXml.getBytes())); - - String plansXml = "" + - "" + - "" + - "" + - " " + - " " + - " " + - " PT1===2===A===Aa===4" + - " " + - " " + - " " + - "" + - "" + - " " + - " " + - " " + - " " + - " " + - " " + - "" + - ""; - new PopulationReader(f.scenario).parse(new ByteArrayInputStream(plansXml.getBytes())); - - EventsManager eventsManager = EventsUtils.createEventsManager(); - OccupancyAnalyzer oa = new OccupancyAnalyzer(3600, 12*3600); - eventsManager.addHandler(oa); - - PrepareForSimUtils.createDefaultPrepareForSim(f.scenario).run(); - new QSimBuilder(f.scenario.getConfig()) // - .useDefaults() // - .build(f.scenario, eventsManager) // - .run(); - - Set> enterStops = oa.getBoardStopIds(); - Assert.assertEquals(1, enterStops.size()); - Assert.assertTrue(enterStops.contains(Id.create(2, TransitStopFacility.class))); - - Set> exitStops = oa.getAlightStopIds(); - Assert.assertEquals(1, exitStops.size()); - Assert.assertTrue(exitStops.contains(Id.create(4, TransitStopFacility.class))); - - int[] occupancy = oa.getOccupancyVolumesForStop(Id.create(1, TransitStopFacility.class)); - Assert.assertEquals(0, occupancy[6]); - occupancy = oa.getOccupancyVolumesForStop(Id.create(2, TransitStopFacility.class)); - Assert.assertEquals(1, occupancy[6]); - occupancy = oa.getOccupancyVolumesForStop(Id.create(3, TransitStopFacility.class)); - Assert.assertEquals(1, occupancy[6]); - occupancy = oa.getOccupancyVolumesForStop(Id.create(4, TransitStopFacility.class)); - Assert.assertEquals(0, occupancy[6]); - - Assert.assertEquals(0, oa.getBoardVolumesForStop(Id.create(1, TransitStopFacility.class))[6]); - Assert.assertEquals(1, oa.getBoardVolumesForStop(Id.create(2, TransitStopFacility.class))[6]); - Assert.assertEquals(0, oa.getBoardVolumesForStop(Id.create(3, TransitStopFacility.class))[6]); - Assert.assertEquals(0, oa.getBoardVolumesForStop(Id.create(4, TransitStopFacility.class))[6]); - - Assert.assertEquals(0, oa.getAlightVolumesForStop(Id.create(1, TransitStopFacility.class))[6]); - Assert.assertEquals(0, oa.getAlightVolumesForStop(Id.create(2, TransitStopFacility.class))[6]); - Assert.assertEquals(0, oa.getAlightVolumesForStop(Id.create(3, TransitStopFacility.class))[6]); - Assert.assertEquals(1, oa.getAlightVolumesForStop(Id.create(4, TransitStopFacility.class))[6]); - } - - private static class Fixture { - public final MutableScenario scenario; - public Fixture() throws SAXException, ParserConfigurationException, IOException { - // setup: config - final Config config = ConfigUtils.createConfig(); - config.transit().setUseTransit(true); - config.qsim().setEndTime(8.0*3600); - - this.scenario = (MutableScenario) ScenarioUtils.createScenario(config); - - // setup: network - Network network = this.scenario.getNetwork(); - Node node1 = network.getFactory().createNode(Id.create("1", Node.class), new Coord(0, 0)); - Node node2 = network.getFactory().createNode(Id.create("2", Node.class), new Coord(1000, 0)); - Node node3 = network.getFactory().createNode(Id.create("3", Node.class), new Coord(2000, 0)); - Node node4 = network.getFactory().createNode(Id.create("4", Node.class), new Coord(3000, 0)); - Node node5 = network.getFactory().createNode(Id.create("5", Node.class), new Coord(4000, 0)); - Node node6 = network.getFactory().createNode(Id.create("6", Node.class), new Coord(5000, 0)); - network.addNode(node1); - network.addNode(node2); - network.addNode(node3); - network.addNode(node4); - network.addNode(node5); - network.addNode(node6); - Link link1 = network.getFactory().createLink(Id.create("1", Link.class), node1, node2); - Link link2 = network.getFactory().createLink(Id.create("2", Link.class), node2, node3); - Link link3 = network.getFactory().createLink(Id.create("3", Link.class), node3, node4); - Link link4 = network.getFactory().createLink(Id.create("4", Link.class), node4, node5); - Link link5 = network.getFactory().createLink(Id.create("5", Link.class), node5, node6); - setDefaultLinkAttributes(link1); - setDefaultLinkAttributes(link2); - setDefaultLinkAttributes(link3); - setDefaultLinkAttributes(link4); - setDefaultLinkAttributes(link5); - network.addLink(link1); - network.addLink(link2); - network.addLink(link3); - network.addLink(link4); - network.addLink(link5); - - // setup: vehicles - String vehiclesXml = "" + - "" + - " " + - " Small Train" + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - " " + - ""; - new MatsimVehicleReader(this.scenario.getTransitVehicles()).readStream(new ByteArrayInputStream(vehiclesXml.getBytes()) ); - } - - private void setDefaultLinkAttributes(final Link link) { - link.setLength(1000.0); - link.setFreespeed(10.0); - link.setCapacity(3600.0); - link.setNumberOfLanes(1); - } - } -} diff --git a/matsim/src/test/java/org/matsim/pt/counts/PtAlightCountsComparisonAlgorithmTest.java b/matsim/src/test/java/org/matsim/pt/counts/PtAlightCountsComparisonAlgorithmTest.java deleted file mode 100644 index 4bcc4780526..00000000000 --- a/matsim/src/test/java/org/matsim/pt/counts/PtAlightCountsComparisonAlgorithmTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * PtBoardCountsComparisonAlgorithmTest.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2007 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -package org.matsim.pt.counts; - -import static org.junit.Assert.assertEquals; - -import java.util.List; - -import org.junit.Rule; -import org.junit.Test; -import org.matsim.counts.CountSimComparison; -import org.matsim.counts.algorithms.CountsComparisonAlgorithm; -import org.matsim.testcases.MatsimTestUtils; - - -public class PtAlightCountsComparisonAlgorithmTest { - - @Rule - public MatsimTestUtils utils = new MatsimTestUtils(); - - - - @Test public void testCompare() { - PtCountsFixture fixture = new PtAlightCountsFixture(); - fixture.setUp(); - - CountsComparisonAlgorithm cca = fixture.getCCA(); - cca.run(); - - List csc_list = cca.getComparison(); - - int cnt = 0; - for (CountSimComparison csc : csc_list) { - if (cnt != 8 && cnt!=32) { - assertEquals("Wrong sim value set", 0d, csc.getSimulationValue(), 0d); - } else if(cnt==8) { - assertEquals("Wrong sim value set", 500d, csc.getSimulationValue(), 0d); - }else{ - assertEquals("Wrong sim value set", 150d, csc.getSimulationValue(), 0d); - } - cnt++; - } - } - - - @Test public void testDistanceFilter() { - final PtCountsFixture fixture = new PtAlightCountsFixture(); - fixture.setUp(); - CountsComparisonAlgorithm cca = fixture.getCCA(); - - cca.setCountCoordUsingDistanceFilter(4000.0, "11"); - cca.run(); - - List csc_list = cca.getComparison(); - assertEquals("Distance filter not working", 24, csc_list.size()); - } -} diff --git a/matsim/src/test/java/org/matsim/pt/counts/PtAlightCountsFixture.java b/matsim/src/test/java/org/matsim/pt/counts/PtAlightCountsFixture.java deleted file mode 100644 index 45073f883cc..00000000000 --- a/matsim/src/test/java/org/matsim/pt/counts/PtAlightCountsFixture.java +++ /dev/null @@ -1,68 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * PtBoardCountsFixture.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2010 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -package org.matsim.pt.counts; - -import java.util.HashMap; -import java.util.Map; - -import org.matsim.api.core.v01.Id; -import org.matsim.counts.algorithms.CountsComparisonAlgorithm; -import org.matsim.pt.transitSchedule.api.TransitStopFacility; - -public class PtAlightCountsFixture extends PtCountsFixture { - - public PtAlightCountsFixture() { - super("inputAlightCountsFile"); - } - - @Override - public CountsComparisonAlgorithm getCCA() { - Map, int[]> alights = new HashMap<>(); - - int[] alightArrayStop3 = new int[24]; - alightArrayStop3[8] = 50; - alights.put(Id.create("stop3", TransitStopFacility.class), alightArrayStop3); - - int[] alightArrayStop4 = new int[24]; - alightArrayStop4[8] = 15; - alights.put(Id.create("stop4", TransitStopFacility.class), alightArrayStop4); - - this.oa.setAlights(alights); - CountsComparisonAlgorithm cca = new CountsComparisonAlgorithm(new CountsComparisonAlgorithm.VolumesForId() { - - @Override - public double[] getVolumesForStop(Id locationId) { - return copyFromIntArray(oa.getAlightVolumesForStop(locationId)); - } - - }, counts, network, Double.parseDouble(config.findParam(MODULE_NAME, "countsScaleFactor"))); - cca.setCountCoordUsingDistanceFilter(Double.valueOf(config.findParam(MODULE_NAME,"distanceFilter")), config.findParam(MODULE_NAME, "distanceFilterCenterNode")); - return cca; - } - - private static double[] copyFromIntArray(int[] source) { - double[] dest = new double[source.length]; - for(int i=0; i csc_list = cca.getComparison(); - - int cnt = 0; - for (CountSimComparison csc : csc_list) { - if (cnt != 8) { - assertEquals("Wrong sim value set", 0d, csc.getSimulationValue(), 0d); - } else { - assertEquals("Wrong sim value set", 650d, csc.getSimulationValue(), 0d); - } - cnt++; - } - } - - - @Test public void testDistanceFilter() { - PtCountsFixture fixture = new PtBoardCountsFixture(); - fixture.setUp(); - - CountsComparisonAlgorithm cca = fixture.getCCA(); - cca.setCountCoordUsingDistanceFilter(Double.valueOf(5000), "11"); - cca.run(); - - List csc_list = cca.getComparison(); - assertEquals("Distance filter not working", 24, csc_list.size()); - } -} diff --git a/matsim/src/test/java/org/matsim/pt/counts/PtBoardCountsFixture.java b/matsim/src/test/java/org/matsim/pt/counts/PtBoardCountsFixture.java deleted file mode 100644 index 80b65cf8139..00000000000 --- a/matsim/src/test/java/org/matsim/pt/counts/PtBoardCountsFixture.java +++ /dev/null @@ -1,63 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * PtBoardCountsFixture.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2010 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -package org.matsim.pt.counts; - -import java.util.HashMap; -import java.util.Map; - -import org.matsim.api.core.v01.Id; -import org.matsim.counts.algorithms.CountsComparisonAlgorithm; -import org.matsim.pt.transitSchedule.api.TransitStopFacility; - -public class PtBoardCountsFixture extends PtCountsFixture { - - public PtBoardCountsFixture() { - super("inputBoardCountsFile"); - } - - @Override - public CountsComparisonAlgorithm getCCA() { - Map, int[]> boards = new HashMap<>(); - int[] boardArray = new int[24]; - boardArray[8] = 65; - boards.put(Id.create("stop1", TransitStopFacility.class), boardArray); - this.oa.setBoards(boards); - CountsComparisonAlgorithm cca = new CountsComparisonAlgorithm(new CountsComparisonAlgorithm.VolumesForId() { - - @Override - public double[] getVolumesForStop(Id locationId) { - return copyFromIntArray(oa.getBoardVolumesForStop(locationId)); - } - - }, counts, network, Double.parseDouble(config.findParam(MODULE_NAME, "countsScaleFactor"))); - cca.setDistanceFilter(Double.valueOf(config.findParam(MODULE_NAME,"distanceFilter")), config.findParam(MODULE_NAME,"distanceFilterCenterNode")); - return cca; - } - - - private static double[] copyFromIntArray(int[] source) { - double[] dest = new double[source.length]; - for(int i=0; i ceateCountSimCompList() { - List csc_l = new Vector(24); - for (int i = 0; i < 24; i++) { - csc_l.add(new CountSimComparisonImpl(Id.create(100, Link.class), "", i + 1, 1.0,1.0)); - } - return csc_l; - } -} diff --git a/matsim/src/test/java/org/matsim/pt/counts/PtCountsLoadCurveGraphTest.java b/matsim/src/test/java/org/matsim/pt/counts/PtCountsLoadCurveGraphTest.java deleted file mode 100644 index 6c888007de3..00000000000 --- a/matsim/src/test/java/org/matsim/pt/counts/PtCountsLoadCurveGraphTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * PtCountsLoadCurveGraphTest.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2007 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -package org.matsim.pt.counts; - -import static org.junit.Assert.assertNotNull; - -import org.junit.Rule; -import org.junit.Test; -import org.matsim.counts.algorithms.graphs.CountsLoadCurveGraph; -import org.matsim.testcases.MatsimTestUtils; - -public class PtCountsLoadCurveGraphTest { - - @Rule - public MatsimTestUtils utils = new MatsimTestUtils(); - - - @Test public void testCreateBoardChart() { - PtCountsFixture fixture = new PtBoardCountsFixture(); - fixture.setUp(); - - CountsLoadCurveGraph eg = new CountsLoadCurveGraph(fixture - .ceateCountSimCompList(), 1, "testCreateChart"); - assertNotNull("No graph is created", eg.createChart(0)); - } - - - @Test public void testCreateAlightChart() { - PtCountsFixture fixture = new PtAlightCountsFixture(); - fixture.setUp(); - - CountsLoadCurveGraph eg = new CountsLoadCurveGraph(fixture - .ceateCountSimCompList(), 1, "testCreateChart"); - assertNotNull("No graph is created", eg.createChart(0)); - } - - - @Test public void testCreateOccupancyChart() { - PtCountsFixture fixture = new PtOccupancyCountsFixture(); - fixture.setUp(); - - CountsLoadCurveGraph eg = new CountsLoadCurveGraph(fixture - .ceateCountSimCompList(), 1, "testCreateChart"); - assertNotNull("No graph is created", eg.createChart(0)); - } -} diff --git a/matsim/src/test/java/org/matsim/pt/counts/PtCountsSimRealPerHourGraphTest.java b/matsim/src/test/java/org/matsim/pt/counts/PtCountsSimRealPerHourGraphTest.java deleted file mode 100644 index 147c430b567..00000000000 --- a/matsim/src/test/java/org/matsim/pt/counts/PtCountsSimRealPerHourGraphTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * PtCountsSimRealPerHourGraphTest.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2007 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -package org.matsim.pt.counts; - -import static org.junit.Assert.assertNotNull; - -import org.junit.Rule; -import org.junit.Test; -import org.matsim.pt.counts.obsolete.PtCountSimComparisonWriter.PtCountsType; -import org.matsim.pt.counts.obsolete.PtCountsSimRealPerHourGraph; -import org.matsim.testcases.MatsimTestUtils; - -public class PtCountsSimRealPerHourGraphTest { - - @Rule - public MatsimTestUtils utils = new MatsimTestUtils(); - - - - @Test public void testCreatBoardChart() { - PtCountsFixture fixture = new PtBoardCountsFixture(); - fixture.setUp(); - - PtCountsSimRealPerHourGraph eg = new PtCountsSimRealPerHourGraph(fixture.ceateCountSimCompList(), 1, "testCreateChart", PtCountsType.Boarding); - assertNotNull("No graph is created", eg.createChart(0)); - } - - - @Test public void testCreatAlightChart() { - PtCountsFixture fixture = new PtAlightCountsFixture(); - fixture.setUp(); - - PtCountsSimRealPerHourGraph eg = new PtCountsSimRealPerHourGraph(fixture.ceateCountSimCompList(), 1, "testCreateChart", PtCountsType.Alighting); - assertNotNull("No graph is created", eg.createChart(0)); - } - - - @Test public void testCreatOccupancyChart() { - PtCountsFixture fixture = new PtOccupancyCountsFixture(); - fixture.setUp(); - - PtCountsSimRealPerHourGraph eg = new PtCountsSimRealPerHourGraph(fixture.ceateCountSimCompList(), 1, "testCreateChart", PtCountsType.Occupancy); - assertNotNull("No graph is created", eg.createChart(0)); - } -} diff --git a/matsim/src/test/java/org/matsim/pt/counts/PtOccupancyCountsComparisonAlgorithmTest.java b/matsim/src/test/java/org/matsim/pt/counts/PtOccupancyCountsComparisonAlgorithmTest.java deleted file mode 100644 index ba4f59d8e0d..00000000000 --- a/matsim/src/test/java/org/matsim/pt/counts/PtOccupancyCountsComparisonAlgorithmTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * PtBoardCountsComparisonAlgorithmTest.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2007 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -package org.matsim.pt.counts; - -import static org.junit.Assert.assertEquals; - -import java.util.List; - -import org.junit.Rule; -import org.junit.Test; -import org.matsim.counts.CountSimComparison; -import org.matsim.counts.algorithms.CountsComparisonAlgorithm; -import org.matsim.testcases.MatsimTestUtils; - -public class PtOccupancyCountsComparisonAlgorithmTest { - - @Rule - public MatsimTestUtils utils = new MatsimTestUtils(); - - - - @Test public void testCompare() { - PtCountsFixture fixture = new PtOccupancyCountsFixture(); - fixture.setUp(); - - CountsComparisonAlgorithm cca = fixture.getCCA(); - cca.run(); - - List csc_list = cca.getComparison(); - - int cnt = 0; - for (CountSimComparison csc : csc_list) { - if (cnt != 8 && cnt != 32 && cnt != 56) { - assertEquals("Wrong sim value set", 0d, csc.getSimulationValue(), 0d); - } else if (cnt == 8 || cnt == 32) { - assertEquals("Wrong sim value set", 650d, csc.getSimulationValue(), 0d); - }else{ - assertEquals("Wrong sim value set", 150d, csc.getSimulationValue(), 0d); - } - cnt++; - } - } - - - @Test public void testDistanceFilter() { - PtCountsFixture fixture = new PtOccupancyCountsFixture(); - fixture.setUp(); - - CountsComparisonAlgorithm cca = fixture.getCCA(); - cca.setCountCoordUsingDistanceFilter(3000.0, "11"); - cca.run(); - - List csc_list = cca.getComparison(); - assertEquals("Distance filter not working", 72, csc_list.size()); - } -} diff --git a/matsim/src/test/java/org/matsim/pt/counts/PtOccupancyCountsFixture.java b/matsim/src/test/java/org/matsim/pt/counts/PtOccupancyCountsFixture.java deleted file mode 100644 index fbf17c7a35f..00000000000 --- a/matsim/src/test/java/org/matsim/pt/counts/PtOccupancyCountsFixture.java +++ /dev/null @@ -1,75 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * PtBoardCountsFixture.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2010 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -package org.matsim.pt.counts; - -import java.util.HashMap; -import java.util.Map; - -import org.matsim.api.core.v01.Id; -import org.matsim.counts.algorithms.CountsComparisonAlgorithm; -import org.matsim.pt.transitSchedule.api.TransitStopFacility; - -public class PtOccupancyCountsFixture extends PtCountsFixture { - - public PtOccupancyCountsFixture() { - super("inputOccupancyCountsFile"); - } - - @Override - public CountsComparisonAlgorithm getCCA() { - Map, int[]> occupancies = new HashMap<>(); - - int[] occupancyArrayStop1 = new int[24]; - occupancyArrayStop1[8] = 65; - occupancies.put(Id.create("stop1", TransitStopFacility.class), occupancyArrayStop1); - - int[] occupancyArrayStop2 = new int[24]; - occupancyArrayStop2[8] = 65; - occupancies.put(Id.create("stop2", TransitStopFacility.class), occupancyArrayStop2); - - int[] occupancyArrayStop3 = new int[24]; - occupancyArrayStop3[8] = 15; - occupancies.put(Id.create("stop3", TransitStopFacility.class), occupancyArrayStop3); - - int[] occupancyArrayStop4 = new int[24]; - occupancies.put(Id.create("stop4", TransitStopFacility.class), occupancyArrayStop4); - - this.oa.setOccupancies(occupancies); - CountsComparisonAlgorithm cca = new CountsComparisonAlgorithm(new CountsComparisonAlgorithm.VolumesForId() { - - @Override - public double[] getVolumesForStop(Id locationId) { - return copyFromIntArray(oa.getOccupancyVolumesForStop(locationId)); - } - - }, counts, network, Double.parseDouble(config.findParam(MODULE_NAME, "countsScaleFactor"))); - cca.setDistanceFilter(Double.valueOf(config.findParam(MODULE_NAME,"distanceFilter")), config.findParam(MODULE_NAME,"distanceFilterCenterNode")); - return cca; - } - - private static double[] copyFromIntArray(int[] source) { - double[] dest = new double[source.length]; - for(int i=0; i - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/matsim/src/test/resources/test/input/org/matsim/pt/counts/board.xml b/matsim/src/test/resources/test/input/org/matsim/pt/counts/board.xml deleted file mode 100644 index 381e85d2a75..00000000000 --- a/matsim/src/test/resources/test/input/org/matsim/pt/counts/board.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/matsim/src/test/resources/test/input/org/matsim/pt/counts/config.xml b/matsim/src/test/resources/test/input/org/matsim/pt/counts/config.xml deleted file mode 100644 index c50817201c1..00000000000 --- a/matsim/src/test/resources/test/input/org/matsim/pt/counts/config.xml +++ /dev/null @@ -1,220 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/matsim/src/test/resources/test/input/org/matsim/pt/counts/configLocal.xml b/matsim/src/test/resources/test/input/org/matsim/pt/counts/configLocal.xml deleted file mode 100644 index 938cc6b78fa..00000000000 --- a/matsim/src/test/resources/test/input/org/matsim/pt/counts/configLocal.xml +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/matsim/src/test/resources/test/input/org/matsim/pt/counts/occupancy.xml b/matsim/src/test/resources/test/input/org/matsim/pt/counts/occupancy.xml deleted file mode 100644 index c324013d5dc..00000000000 --- a/matsim/src/test/resources/test/input/org/matsim/pt/counts/occupancy.xml +++ /dev/null @@ -1,115 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/matsim/src/test/resources/test/input/org/matsim/pt/counts/ptNet.xml b/matsim/src/test/resources/test/input/org/matsim/pt/counts/ptNet.xml deleted file mode 100644 index 28a1af67ab5..00000000000 --- a/matsim/src/test/resources/test/input/org/matsim/pt/counts/ptNet.xml +++ /dev/null @@ -1,115 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/matsim/src/test/resources/test/input/org/matsim/pt/counts/ptPop.xml b/matsim/src/test/resources/test/input/org/matsim/pt/counts/ptPop.xml deleted file mode 100644 index c72e1d3c4b0..00000000000 --- a/matsim/src/test/resources/test/input/org/matsim/pt/counts/ptPop.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/matsim/src/test/resources/test/input/org/matsim/pt/counts/transitSchedule.xml b/matsim/src/test/resources/test/input/org/matsim/pt/counts/transitSchedule.xml deleted file mode 100644 index a52c4a22a81..00000000000 --- a/matsim/src/test/resources/test/input/org/matsim/pt/counts/transitSchedule.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - pt - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/matsim/src/test/resources/test/input/org/matsim/pt/counts/vehicles.xml b/matsim/src/test/resources/test/input/org/matsim/pt/counts/vehicles.xml deleted file mode 100644 index da59ba707bd..00000000000 --- a/matsim/src/test/resources/test/input/org/matsim/pt/counts/vehicles.xml +++ /dev/null @@ -1,81 +0,0 @@ - - - - - Bus - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -