@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 Counts<Link> get() { Counts<Link> calibrationCounts = new Counts<>(); new MatsimCountsReader(calibrationCounts).parse(config.getCountsFileURL(matsimConfig.getContext())); return calibrationCounts; } }
@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 }
public void testGetCounts() { final Counts counts = new Counts(); counts.createAndAddCount(Id.create(0, Link.class), "1"); assertEquals("Getting counts failed", 1, counts.getCounts().size()); } }
@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; } }
"</counts>\n"; Counts counts = new Counts(); MatsimCountsReader reader = new MatsimCountsReader(counts); ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
"</counts>\n"; Counts counts = new Counts(); MatsimCountsReader reader = new MatsimCountsReader(counts); ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
private Counts<Link> createDummyCounts() { final Counts<Link> counts = new Counts<Link>(); counts.setYear( 1988 ); for ( double i=0; i < 10; i+=1 ) { for ( double j=0; j < 10; j+=1 ) { final Count<Link> c = counts.createAndAddCount( Id.createLinkId( i+"-"+j ), i+"-"+j ); c.setCoord( new Coord( i , j ) ); c.createVolume( 1 , 0 ); } } return counts; }
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 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 testSECount() { AttributeFactory attributeFactory = new AttributeFactory(); final Counts counts = new Counts(); CountsReaderMatsimV1 reader = new CountsReaderMatsimV1(counts); reader.startTag("counts", attributeFactory.createCountsAttributes(), null); reader.startTag("count", attributeFactory.createCountAttributes(), null); assertEquals("Count attribute setting failed", "testNr", counts.getCount(Id.create(1, Link.class)).getCsLabel()); }
@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 ); }
public void testSECounts() { AttributeFactory attributeFactory = new AttributeFactory(); final Counts counts = new Counts(); CountsReaderMatsimV1 reader = new CountsReaderMatsimV1(counts); reader.startTag("counts", attributeFactory.createCountsAttributes(), null); assertEquals("Counts attribute setting failed", "testName", counts.getName()); assertEquals("Counts attribute setting failed", "testDesc", counts.getDescription()); assertEquals("Counts attribute setting failed", 2000, counts.getYear()); }
this.config.getOutputFormat().contains("all")) { String filename = controlerIO.getIterationFilename(event.getIteration(), "simulatedCounts.xml.gz"); Counts<Link> simCounts = new Counts<>(); simCounts.setDescription("sim values from iteration " + event.getIteration()); simCounts.setName("sim values from iteration " + event.getIteration()); simCounts.setYear(event.getIteration()); for (CountSimComparison countSimComparison : cca.getComparison()) {
public void testSEVolume() { AttributeFactory attributeFactory = new AttributeFactory(); final Counts counts = new Counts(); CountsReaderMatsimV1 reader = new CountsReaderMatsimV1(counts); reader.startTag("counts", attributeFactory.createCountsAttributes(), null); reader.startTag("count", attributeFactory.createCountAttributes(), null); reader.startTag("volume", attributeFactory.createVolumeAttributes(), null); assertEquals("Volume attribute setting failed", 100.0, counts.getCount(Id.create(1, Link.class)).getVolume(1).getValue(), EPSILON); } }
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"); }
/** * @throws SAXException * @throws ParserConfigurationException * @throws IOException * * @author mrieser */ @Test public void testWriteParse_nameIsNull() throws SAXException, ParserConfigurationException, IOException { CountsFixture f = new CountsFixture(); f.setUp(); f.counts.setName(null); Assert.assertNull(f.counts.getName()); String filename = this.utils.getOutputDirectory() + "counts.xml"; new CountsWriter(f.counts).write(filename); Counts counts2 = new Counts(); new CountsReaderMatsimV1(counts2).readFile(filename); Assert.assertEquals("", counts2.getName()); } }
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"); }
final Counts<Link> dumpedCounts = new Counts<>(); new MatsimCountsReader( dumpedCounts ).readFile( outputDirectory+"/output_counts.xml.gz" );