private void writeMinimalTransferTimes() { List<Tuple<String, String>> attributes = new ArrayList<>(5); MinimalTransferTimes.MinimalTransferTimesIterator iter = this.schedule.getMinimalTransferTimes().iterator(); if (iter.hasNext()) { this.writeStartTag(Constants.MINIMAL_TRANSFER_TIMES, attributes); while (iter.hasNext()) { iter.next(); attributes.clear(); attributes.add(createTuple(Constants.FROM_STOP, iter.getFromStopId().toString())); attributes.add(createTuple(Constants.TO_STOP, iter.getToStopId().toString())); attributes.add(createTuple(Constants.TRANSFER_TIME, iter.getSeconds())); this.writeStartTag(Constants.RELATION, attributes, true); } this.writeEndTag(Constants.MINIMAL_TRANSFER_TIMES); } }
Id<TransitStopFacility> toStop = Id.create(atts.getValue(Constants.TO_STOP), TransitStopFacility.class); double transferTime = Time.parseTime(atts.getValue(Constants.TRANSFER_TIME)); this.schedule.getMinimalTransferTimes().set(fromStop, toStop, transferTime); } else if (Constants.ATTRIBUTE.equals(name)) { this.attributesDelegate.startTag(name, atts, context, this.currentAttributes);
public static ValidationResult validateTransfers(final TransitSchedule schedule) { ValidationResult result = new ValidationResult(); MinimalTransferTimes transferTimes = schedule.getMinimalTransferTimes(); MinimalTransferTimes.MinimalTransferTimesIterator iter = transferTimes.iterator(); Set<Id> missingFromStops = new HashSet<>(); Set<Id> missingToStops = new HashSet<>(); while (iter.hasNext()) { iter.next(); Id<TransitStopFacility> fromStopId = iter.getFromStopId(); Id<TransitStopFacility> toStopId = iter.getToStopId(); double transferTime = iter.getSeconds(); if (fromStopId == null && toStopId == null) { result.addError("Minimal Transfer Times: both fromStop and toStop are null."); } else if (fromStopId == null) { result.addError("Minimal Transfer Times: fromStop = null, toStop " + toStopId + "."); } else if (toStopId == null) { result.addError("Minimal Transfer Times: fromStop " + fromStopId + ", toStop = null."); } if (transferTime <= 0) { result.addWarning("Minimal Transfer Times: fromStop " + fromStopId + " toStop " + toStopId + " with transferTime = " + transferTime); } if (schedule.getFacilities().get(fromStopId) == null && missingFromStops.add(fromStopId)) { result.addError("Minimal Transfer Times: fromStop " + fromStopId + " does not exist in schedule."); } if (schedule.getFacilities().get(toStopId) == null && missingToStops.add(toStopId)) { result.addError("Minimal Transfer Times: toStop " + toStopId + " does not exist in schedule."); } } return result; }
@Test public void testValidator_Transfers_missingStop() { Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); TransitSchedule schedule = scenario.getTransitSchedule(); TransitScheduleFactory factory = schedule.getFactory(); Id<TransitStopFacility> id1 = Id.create("stop1", TransitStopFacility.class); Id<TransitStopFacility> id2 = Id.create("stop2", TransitStopFacility.class); Id<TransitStopFacility> id3 = Id.create("stop3", TransitStopFacility.class); Id<TransitStopFacility> id4 = Id.create("stop4", TransitStopFacility.class); schedule.addStopFacility(factory.createTransitStopFacility(id1, new Coord(10000, 10000), false)); schedule.addStopFacility(factory.createTransitStopFacility(id2, new Coord(20000, 10000), false)); schedule.getMinimalTransferTimes().set(id1, id3, 120); TransitScheduleValidator.ValidationResult result = TransitScheduleValidator.validateTransfers(schedule); Assert.assertEquals("Should warn against missing stop3.", 1, result.getIssues().size()); Assert.assertTrue("Message should contain hint about stop3 being missing. " + result.getIssues().get(0).getMessage(), result.getIssues().get(0).getMessage().contains("stop3")); schedule.getMinimalTransferTimes().remove(id1, id3); schedule.getMinimalTransferTimes().set(id4, id2, 120); result = TransitScheduleValidator.validateTransfers(schedule); Assert.assertEquals("Should warn against missing stop4.", 1, result.getIssues().size()); Assert.assertTrue("Message should contain hint about stop4 being missing. " + result.getIssues().get(0).getMessage(), result.getIssues().get(0).getMessage().contains("stop4")); }
@Test public void testValidator_Transfers_implausibleTime() { Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); TransitSchedule schedule = scenario.getTransitSchedule(); TransitScheduleFactory factory = schedule.getFactory(); Id<TransitStopFacility> id1 = Id.create(1, TransitStopFacility.class); Id<TransitStopFacility> id2 = Id.create(2, TransitStopFacility.class); Id<TransitStopFacility> id3 = Id.create(3, TransitStopFacility.class); Id<TransitStopFacility> id4 = Id.create(4, TransitStopFacility.class); schedule.addStopFacility(factory.createTransitStopFacility(id1, new Coord(10000, 10000), false)); schedule.addStopFacility(factory.createTransitStopFacility(id2, new Coord(20000, 10000), false)); schedule.getMinimalTransferTimes().set(id1, id2, 120); TransitScheduleValidator.ValidationResult result = TransitScheduleValidator.validateTransfers(schedule); Assert.assertTrue(result.getIssues().isEmpty()); schedule.getMinimalTransferTimes().set(id1, id2, 0); result = TransitScheduleValidator.validateTransfers(schedule); Assert.assertEquals("Should warn against implausible transfer time.", 1, result.getIssues().size()); }
schedule.addStopFacility(stop2); schedule.getMinimalTransferTimes().set(stop1.getId(), stop2.getId(), 300.0); schedule.getMinimalTransferTimes().set(stop2.getId(), stop1.getId(), 360.0); Assert.assertEquals(300, schedule2.getMinimalTransferTimes().get(stop1.getId(), stop2.getId()), 0.0); Assert.assertEquals(360, schedule2.getMinimalTransferTimes().get(stop2.getId(), stop1.getId()), 0.0); Assert.assertEquals(Double.NaN, schedule2.getMinimalTransferTimes().get(stop1.getId(), stop1.getId()), 0.0);