@Override public void startCount(final Count count, final BufferedWriter out) throws IOException { out.write("\t<count"); out.write(" loc_id=\"" + count.getId() + "\""); out.write(" cs_id=\"" + count.getCsLabel() + "\""); if (count.getCoord() != null) { final Coord coord = coordinateTransformation.transform( count.getCoord() ); out.write(" x=\"" + coord.getX() + "\""); out.write(" y=\"" + coord.getY() + "\""); } out.write(">\n"); }
/** * Creates the List with the counts vs sim values stored in the * countAttribute Attribute of this class. */ private void compare() { for (Count<Link> count : this.counts.getCounts().values()) { if (!distanceFilter.isInRange(count)) { continue; } double[] volumes = this.volumesPerLinkPerHour.getVolumesForStop(Id.create(count.getId(), TransitStopFacility.class)); if (volumes == null || volumes.length == 0) { log.warn("No volumes for count location: " + count.getId().toString()); continue; } for (int hour = 1; hour <= 24; hour++) { Volume volume = count.getVolume(hour); if (volume != null) { double countValue = volume.getValue(); double simValue=volumes[hour-1]; simValue *= this.countsScaleFactor; this.result.add(new CountSimComparisonImpl(count.getId(), count.getCsLabel(), hour, countValue, simValue)); } } } }
public void testGetVolumes() { Count count = new Count(Id.create(0, Link.class), "1"); count.createVolume(1, 100.0); Iterator<Volume> vol_it = count.getVolumes().values().iterator(); while (vol_it.hasNext()) { Volume v = vol_it.next(); assertTrue("Getting volumes failed", v.getValue() == 100.0); } } }
for (CountSimComparison countSimComparison : cca.getComparison()) { if (simCounts.getCount(countSimComparison.getId()) == null) { simCounts.createAndAddCount(countSimComparison.getId(), counts.getCount(countSimComparison.getId()).getCsLabel()); simCounts.getCount(countSimComparison.getId()).setCoord(counts.getCount(countSimComparison.getId()).getCoord()); simCounts.getCount(countSimComparison.getId()).createVolume(countSimComparison.getHour(), countSimComparison.getSimulationValue());
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); writer.write((anOcuppancy) + TAB); writer.write(count.getCoord().toString() + TAB + count.getCsLabel() + NL);
public void testGetVolume() { Count count = new Count(Id.create(0, Link.class), "1"); count.createVolume(1, 100.0); assertTrue("Getting volume failed", count.getVolume(1).getValue() == 100.0); }
@Override public boolean isInRange(Count<Link> count) { double dist = CoordUtils.calcEuclideanDistance(count.getCoord(), centerCoord); return dist < distance; } };
while (c_it.hasNext()) { Count c = c_it.next(); Assert.assertNotNull(c.getId()); Iterator<Volume> vol_it = c.getVolumes().values().iterator(); while (vol_it.hasNext()) { Volume v = vol_it.next();
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"); }
for (Volume volume : entry.getValue().getVolumes().values()){
public void testCreateVolume() { Count count = new Count(Id.create(0, Link.class), "1"); Volume volume = count.createVolume(1, 100.0); assertTrue("Creation and initialization of volume failed", volume.getHourOfDayStartingWithOne()==1); assertTrue("Creation and initialization of volume failed", volume.getValue()==100.0); }
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; }
@Override public boolean isInRange(Count<Link> count) { Link l = network.getLinks().get(count.getId()); if (l == null) { log.warn("Cannot find requested link: " + count.getId().toString()); return false; } double dist = CoordUtils.calcEuclideanDistance(l.getCoord(), centerCoord); return dist < distance; }
@Override public int compare(final Count c1, final Count c2) { // This seemed to be intended for a rather special case with a rather special // numbering of counts... michaz mar 10 // int i1 = Integer.parseInt(c1.getCsId().substring(c1.getCsId().length()-3)); // int i2 = Integer.parseInt(c2.getCsId().substring(c2.getCsId().length()-3)); // if (i1 < i2) return -1; // else if (i1 > i2) return 1; // else return 0; return c1.getCsLabel().compareTo(c2.getCsLabel()); } }
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); } }
private void startVolume(final Attributes meta) { if (this.currcount != null) { this.currcount.createVolume(Integer.parseInt(meta.getValue("h")), Double.parseDouble(meta.getValue("val"))); } }
/** * @param linkId the link to which the counting station is assigned, must be unique * @param stationName some additional identifier for humans, e.g. the original name/id of the counting station * @return the created Count object, or {@linkplain RuntimeException} if it could not be created because it already exists */ public final Count<T> createAndAddCount(final Id<T> linkId, final String stationName) { // check id string for uniqueness if (this.counts.containsKey(linkId)) { throw new RuntimeException("There is already a counts object for location " + linkId); } Count<T> c = new Count<>(linkId, stationName); this.counts.put(linkId, c); return c; }
private void startCount(final Attributes meta) { String locId = meta.getValue("loc_id"); this.currcount = this.counts.createAndAddCount(Id.create(locId, Link.class), meta.getValue("cs_id")); String x = meta.getValue("x"); String y = meta.getValue("y"); if (x != null && y != null) { this.currcount.setCoord( coordinateTransformation.transform( new Coord( Double.parseDouble(x), Double.parseDouble(y)))); } }
private void assertCountsAreReprojectedCorrectly( Counts<Link> originalCounts, Counts<Link> reprojectedCounts) { Assert.assertEquals( "unexpected number of counts", originalCounts.getCounts().size(), reprojectedCounts.getCounts().size() ); for ( Id<Link> id : originalCounts.getCounts().keySet() ) { final Coord original = originalCounts.getCount( id ).getCoord(); final Coord transformed = reprojectedCounts.getCount( id ).getCoord(); Assert.assertEquals( "wrong reprojected X value", original.getX() + 1000 , transformed.getX(), MatsimTestUtils.EPSILON ); Assert.assertEquals( "wrong reprojected Y value", original.getY() + 1000 , transformed.getY(), MatsimTestUtils.EPSILON ); } }