@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 Counts<Link> get() { Counts<Link> calibrationCounts = new Counts<>(); new MatsimCountsReader(calibrationCounts).parse(config.getCountsFileURL(matsimConfig.getContext())); return calibrationCounts; } }
@Provides @Singleton Counts<Link> provideLinkCounts(Scenario scenario, CountsConfigGroup config) { Counts<Link> counts = (Counts<Link>) scenario.getScenarioElement(Counts.ELEMENT_NAME); if (counts != null) { return counts; } else { counts = new Counts<>(); if (config.getCountsFileName() != null) { final String inputCRS = config.getInputCRS(); final String internalCRS = scenario.getConfig().global().getCoordinateSystem(); MatsimCountsReader counts_parser; if (inputCRS == null) { counts_parser = new MatsimCountsReader(counts); } else { log.info( "re-projecting counts from "+inputCRS+" to "+internalCRS+" for import" ); final CoordinateTransformation transformation = TransformationFactory.getCoordinateTransformation( inputCRS, internalCRS ); counts_parser = new MatsimCountsReader( transformation , counts ); } counts_parser.parse(config.getCountsFileURL(scenario.getConfig().getContext())); } return counts; } }
@Test public void testDefaultYear_empty() { Counts counts = new Counts(); ByteArrayOutputStream out = new ByteArrayOutputStream(); new CountsWriter(counts).write(out); Counts counts2 = new Counts(); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); new MatsimCountsReader(counts2).parse(in); // there should not have been an Exception }
MatsimCountsReader reader = new MatsimCountsReader(counts); ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); reader.parse(stream);
MatsimCountsReader reader = new MatsimCountsReader(counts); ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); reader.parse(stream);
@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.getCalibratedItems())); events.addHandler(ptStep); }
public void testSEElementCounts() throws SAXException { AttributeFactory attributeFactory = new AttributeFactory(); final Counts counts = new Counts(); MatsimCountsReader reader = new MatsimCountsReader(counts); reader.setDoctype("counts_v1.xsd"); reader.startElement("", "counts", "counts", attributeFactory.createCountsAttributes()); assertEquals("Counts attribute setting failed", "testName", counts.getName()); assertEquals("Counts attribute setting failed", "testDesc", counts.getDescription()); assertEquals("Counts attribute setting failed", 2000, counts.getYear()); try { reader.endElement("", "counts", "counts"); } catch (SAXException e) { throw new RuntimeException(e); } }
@Test public void testOutput() { final String file = utils.getOutputDirectory()+"/counts.xml"; final Counts<Link> originalCounts = createDummyCounts(); new CountsWriter( new Transformation() , originalCounts ).write( file ); final Counts<Link> reprojectedCounts = new Counts(); new MatsimCountsReader( reprojectedCounts ).readFile( file ); assertCountsAreReprojectedCorrectly( originalCounts , reprojectedCounts ); }
@Test public void testInput() { final String file = utils.getOutputDirectory()+"/counts.xml"; final Counts<Link> originalCounts = createDummyCounts(); new CountsWriter( originalCounts ).write( file ); final Counts<Link> reprojectedCounts = new Counts(); new MatsimCountsReader( new Transformation() , reprojectedCounts ).readFile( file ); assertCountsAreReprojectedCorrectly( originalCounts , reprojectedCounts ); }
public void setUp() { String configFile = "test/input/org/matsim/pt/counts/config.xml"; this.config = ConfigUtils.loadConfig(configFile); MatsimRandom.reset(config.global().getRandomSeed()); this.scenario = ScenarioUtils.createScenario(config); config = scenario.getConfig(); new MatsimCountsReader(this.counts).readFile(config.findParam(MODULE_NAME, countFileParamName)); this.network = scenario.getNetwork(); new MatsimNetworkReader(scenario.getNetwork()).readFile(config.network().getInputFile()); }
public void setUp() { String configFile = "test/input/org/matsim/counts/config.xml"; Config config = ConfigUtils.loadConfig(configFile); MatsimRandom.reset(config.global().getRandomSeed()); this.scenario = ScenarioUtils.createScenario(config); MatsimCountsReader counts_parser = new MatsimCountsReader(this.counts); counts_parser.readFile(config.counts().getCountsFileName()); this.network = scenario.getNetwork(); new MatsimNetworkReader(scenario.getNetwork()).readFile(config.network().getInputFile()); }
public void testSEElementCountWithoutCoords() throws SAXException { AttributeFactory attributeFactory = new AttributeFactory(); final Counts counts = new Counts(); MatsimCountsReader reader = new MatsimCountsReader(counts); reader.setDoctype("counts_v1.xsd"); reader.startElement("", "counts", "counts", attributeFactory.createCountsAttributes()); reader.startElement("", "count", "count", attributeFactory.createCountAttributes()); Count count = counts.getCount(Id.create(1, Link.class)); assertEquals("Count attribute setting failed", "testNr", count.getCsLabel()); assertNull("Count attributes x,y should not be set", count.getCoord()); reader.endElement("", "count", "count"); reader.endElement("", "counts", "counts"); }
public void testSEElementVolume() throws SAXException { AttributeFactory attributeFactory = new AttributeFactory(); final Counts counts = new Counts(); MatsimCountsReader reader = new MatsimCountsReader(counts); reader.setDoctype("counts_v1.xsd"); reader.startElement("", "counts", "counts", attributeFactory.createCountsAttributes()); reader.startElement("", "count", "count", attributeFactory.createCountAttributes()); reader.startElement("", "volume", "volume", attributeFactory.createVolumeAttributes()); assertEquals("Volume attribute setting failed", 100.0, counts.getCount(Id.create(1, Link.class)).getVolume(1).getValue(), EPSILON); reader.endElement("", "volume", "volume"); reader.endElement("", "count", "count"); reader.endElement("", "counts", "counts"); } }
public void testSEElementCountWithCoords() throws SAXException { AttributeFactory attributeFactory = new AttributeFactory(); final Counts counts = new Counts(); MatsimCountsReader reader = new MatsimCountsReader(counts); reader.setDoctype("counts_v1.xsd"); reader.startElement("", "counts", "counts", attributeFactory.createCountsAttributes()); reader.startElement("", "count", "count", attributeFactory.createCountAttributesWithCoords()); Count count = counts.getCount(Id.create(1, Link.class)); assertNotNull("Count attribute x,y setting failed", count.getCoord()); assertEquals("Count attribute x setting failed", 123.456, count.getCoord().getX(), EPSILON); assertEquals("Count attribute y setting failed", 987.654, count.getCoord().getY(), EPSILON); reader.endElement("", "count", "count"); reader.endElement("", "counts", "counts"); }
new MatsimCountsReader( dumpedCounts ).readFile( outputDirectory+"/output_counts.xml.gz" );