private void addPTransitScheduleToOriginalOne(TransitSchedule baseSchedule, TransitSchedule pSchedule) { if(pSchedule == null){ log.info("pSchedule does not exist, doing nothing"); return; } for (TransitStopFacility pStop : pSchedule.getFacilities().values()) { if (!baseSchedule.getFacilities().containsKey(pStop.getId())) { baseSchedule.addStopFacility(pStop); currentExclusivePFacilityIDs.add(pStop.getId()); } } for (TransitLine pLine : pSchedule.getTransitLines().values()) { if (!baseSchedule.getTransitLines().containsKey(pLine.getId())) { baseSchedule.addTransitLine(pLine); currentExclusivePTransitLineIDs.add(pLine.getId()); } } }
@Override public TransitLine createEmptyLineFromOperator(Id<Operator> id) { return this.scheduleWithStopsOnly.getFactory().createTransitLine(Id.create(id, TransitLine.class)); }
private void writeData() throws IOException, UncheckedIOException { this.writeXmlHead(); this.writeDoctype(Constants.TRANSIT_SCHEDULE, "http://www.matsim.org/files/dtd/transitSchedule_v2.dtd"); this.writeStartTag(Constants.TRANSIT_SCHEDULE, null); this.writer.write(NL); this.attributesWriter.writeAttributes( "\t" , this.writer , this.schedule.getAttributes() ); this.writeTransitStops(); this.writeMinimalTransferTimes(); for (TransitLine line : this.schedule.getTransitLines().values()) { writeTransitLine(line); } this.writeEndTag(Constants.TRANSIT_SCHEDULE); this.close(); }
@Inject public TransitPerformanceFromEventBasedRouterInterfaces(WaitTime waitTimes, StopStopTime stopStopTimes, TransitSchedule transitSchedule) { this.waitTimes = waitTimes; this.stopStopTimes = stopStopTimes; this.transitLines = transitSchedule.getTransitLines(); this.stopFacilities = transitSchedule.getFacilities(); }
private void removePreviousPTransitScheduleFromOriginalOne(TransitSchedule transitSchedule) { for (Id<TransitLine> transitLineId : currentExclusivePTransitLineIDs) { transitSchedule.removeTransitLine(transitSchedule.getTransitLines().get(transitLineId)); } currentExclusivePTransitLineIDs.clear(); for (Id<TransitStopFacility> facilityId : currentExclusivePFacilityIDs) { transitSchedule.removeStopFacility(transitSchedule.getFacilities().get(facilityId)); } currentExclusivePFacilityIDs.clear(); }
private void createTransitSchedule() { TransitSchedule schedule = this.scenario.getTransitSchedule(); TransitScheduleFactory builder = schedule.getFactory(); TransitStopFacility[] stops = new TransitStopFacility[nOfLinks]; ArrayList<TransitRouteStop> stopList = new ArrayList<>(nOfLinks); for (int i = 0; i < nOfLinks; i++) { stops[i] = builder.createTransitStopFacility(Id.create(i, TransitStopFacility.class), new Coord((i + 1) * 500, 0), stopsBlockLane); stops[i].setLinkId(Id.create(i, Link.class)); schedule.addStopFacility(stops[i]); TransitRouteStop stop = builder.createTransitRouteStop(stops[i], i * 50, i * 50 + 10); stopList.add(stop); } Link startLink = this.scenario.getNetwork().getLinks().get(Id.create(0, Link.class)); Link endLink = this.scenario.getNetwork().getLinks().get(Id.create(nOfLinks - 1, Link.class)); NetworkRoute networkRoute = this.scenario.getPopulation().getFactory().getRouteFactories().createRoute(NetworkRoute.class, startLink.getId(), endLink.getId()); ArrayList<Id<Link>> linkList = new ArrayList<>(nOfLinks - 2); for (int i = 1; i < nOfLinks -1; i++) { linkList.add(Id.create(i, Link.class)); } networkRoute.setLinkIds(startLink.getId(), linkList, endLink.getId()); TransitRoute tRoute = builder.createTransitRoute(Id.create(1, TransitRoute.class), networkRoute, stopList, "bus"); TransitLine tLine = builder.createTransitLine(Id.create(1, TransitLine.class)); tLine.addRoute(tRoute); schedule.addTransitLine(tLine); for (int i = 0; i < nOfBuses; i++ ) { Departure dep = builder.createDeparture(Id.create(i, Departure.class), departureTime + i*heading + (i == delayedBus ? delay : 0)); dep.setVehicleId(Id.create(i, Vehicle.class)); tRoute.addDeparture(dep); } }
@Inject public TransitPerformanceFromPSimSpecificImplementation(TransitPerformance transitPerformance, TransitSchedule transitSchedule) { this.transitPerformance = transitPerformance; this.transitLines = transitSchedule.getTransitLines(); }
schedule.getAttributes().putAttribute("source", "myImagination"); stop2.setStopAreaId(Id.create("GZ", TransitStopArea.class)); schedule.addStopFacility(stop1); schedule.addStopFacility(stop2); schedule.getMinimalTransferTimes().set(stop1.getId(), stop2.getId(), 300.0); schedule.getMinimalTransferTimes().set(stop2.getId(), stop1.getId(), 360.0); schedule.addTransitLine(line1); Assert.assertEquals("myImagination", schedule2.getAttributes().getAttribute("source")); TransitStopFacility stop1 = schedule2.getFacilities().get(Id.create(1, TransitStopFacility.class)); Assert.assertTrue(AttributesUtils.isEmpty(stop1.getAttributes())); TransitStopFacility stop2 = schedule2.getFacilities().get(Id.create(2, TransitStopFacility.class)); Assert.assertFalse(AttributesUtils.isEmpty(stop2.getAttributes())); Assert.assertEquals("thin", stop2.getAttributes().getAttribute("air")); 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); TransitLine line1 = schedule2.getTransitLines().get(Id.create("blue", TransitLine.class)); Assert.assertNotNull(line1); Assert.assertFalse(AttributesUtils.isEmpty(line1.getAttributes()));
@Override public Collection<TransitStopFacility> getAllPStops() { return this.scheduleWithStopsOnly.getFacilities().values(); }
new Coord(Double.parseDouble(atts.getValue(Constants.X)), Double.parseDouble(atts.getValue(Constants.Y)), Double.parseDouble(atts.getValue(Constants.Z))); TransitStopFacility stop = this.schedule.getFactory().createTransitStopFacility( Id.create(atts.getValue(Constants.ID), TransitStopFacility.class), this.coordinateTransformation.transform(coord), this.schedule.addStopFacility(stop); } else if (Constants.TRANSIT_LINE.equals(name)) { Id<TransitLine> id = Id.create(atts.getValue(Constants.ID), TransitLine.class); this.currentTransitLine = this.schedule.getFactory().createTransitLine(id); this.currentAttributes = this.currentTransitLine.getAttributes(); if (atts.getValue(Constants.NAME) != null) { this.currentTransitLine.setName(atts.getValue(Constants.NAME)); this.schedule.addTransitLine(this.currentTransitLine); } else if (Constants.TRANSIT_ROUTE.equals(name)) { Id<TransitRoute> id = Id.create(atts.getValue(Constants.ID), TransitRoute.class); TransitStopFacility facility = this.schedule.getFacilities().get(id); if (facility == null) { throw new RuntimeException("no stop/facility with id " + atts.getValue(Constants.REF_ID)); 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); this.attributesDelegate.startTag(name, atts, context, this.currentAttributes);
void notifyIterationStarts(IterationStartsEvent event) { this.strategyManager.updateStrategies(event.getIteration()); // Adapt number of operators this.handleBankruptOperators(event.getIteration()); // Replan all operators for (Operator operator : this.operators) { operator.replan(this.strategyManager, event.getIteration()); } // Collect current lines offered // why is the following done twice (see notifyScoring)? this.pTransitSchedule = new TransitScheduleFactoryImpl().createTransitSchedule(); for (TransitStopFacility stop : this.pStopsOnly.getFacilities().values()) { this.pTransitSchedule.addStopFacility(stop); } for (Operator operator : this.operators) { this.pTransitSchedule.addTransitLine(operator.getCurrentTransitLine()); } // Reset the franchise system this.franchise.reset(this.operators); }
@Test public void testAddTransitLine() { TransitSchedule schedule = new TransitScheduleImpl(new TransitScheduleFactoryImpl()); TransitLine line1 = new TransitLineImpl(Id.create(1, TransitLine.class)); TransitLine line2 = new TransitLineImpl(Id.create(2, TransitLine.class)); assertEquals(0, schedule.getTransitLines().size()); schedule.addTransitLine(line1); assertEquals(1, schedule.getTransitLines().size()); assertEquals(line1, schedule.getTransitLines().get(line1.getId())); schedule.addTransitLine(line2); assertEquals(2, schedule.getTransitLines().size()); assertEquals(line1, schedule.getTransitLines().get(line1.getId())); assertEquals(line2, schedule.getTransitLines().get(line2.getId())); }
private int addStopOnLink(Link link) { if(link == null){ return 0; } if(linkToNodeNotInServiceArea(link)){ return 0; } if (linkHasAlreadyAFormalPTStopFromTheGivenSchedule(link)) { return 0; } if (link.getFreespeed() >= this.pConfigGroup.getSpeedLimitForStops()) { return 0; } if (this.linkId2StopFacilityMap.get(link.getId()) != null) { log.warn("Link " + link.getId() + " has already a stop. This should not happen. Check code."); return 0; } Id<TransitStopFacility> stopId = Id.create(this.pConfigGroup.getPIdentifier() + link.getId(), TransitStopFacility.class); TransitStopFacility stop = this.transitSchedule.getFactory().createTransitStopFacility(stopId, link.getToNode().getCoord(), false); stop.setLinkId(link.getId()); this.transitSchedule.addStopFacility(stop); return 1; }
if (this.transitSchedule.getFacilities().get(Id.create(pConfigGroup.getPIdentifier() + link.getId().toString(), TransitStopFacility.class)) != null) { log.warn("Link " + link.getId() + " has already a stop. This should not happen. Check code."); return 0; TransitStopFacility stop = this.transitSchedule.getFactory().createTransitStopFacility(stopId, link.getToNode().getCoord(), false); stop.setLinkId(link.getId()); this.transitSchedule.addStopFacility(stop); return 1;
@Test public void testAddStopFacility() { TransitSchedule schedule = new TransitScheduleImpl(new TransitScheduleFactoryImpl()); TransitStopFacility stop1 = new TransitStopFacilityImpl(Id.create(1, TransitStopFacility.class), new Coord((double) 0, (double) 0), false); TransitStopFacility stop2 = new TransitStopFacilityImpl(Id.create(2, TransitStopFacility.class), new Coord((double) 1, (double) 1), false); assertEquals(0, schedule.getFacilities().size()); schedule.addStopFacility(stop1); assertEquals(1, schedule.getFacilities().size()); assertEquals(stop1, schedule.getFacilities().get(stop1.getId())); schedule.addStopFacility(stop2); assertEquals(2, schedule.getFacilities().size()); assertEquals(stop1, schedule.getFacilities().get(stop1.getId())); assertEquals(stop2, schedule.getFacilities().get(stop2.getId())); }
@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()); }
TransitRouteStop routeStop = this.scheduleWithStopsOnly.getFactory().createTransitRouteStop(startStop, runningTime, runningTime); stops.add(routeStop); if(this.scheduleWithStopsOnly.getFacilities().get(Id.create(this.pIdentifier + link.getId(), TransitStopFacility.class)) == null){ continue; routeStop = this.scheduleWithStopsOnly.getFactory().createTransitRouteStop(this.scheduleWithStopsOnly.getFacilities().get(Id.create(this.pIdentifier + link.getId(), TransitStopFacility.class)), runningTime, runningTime); stops.add(routeStop); routeStop = this.scheduleWithStopsOnly.getFactory().createTransitRouteStop(startStop, runningTime, runningTime); stops.add(routeStop); TransitRoute transitRoute = this.scheduleWithStopsOnly.getFactory().createTransitRoute(routeID, route, stops, this.transportMode);
stop2.setName("S + U Nirgendwo"); stop4.setName("Irgendwo"); schedule1.addStopFacility(stop1); schedule1.addStopFacility(stop2); schedule1.addStopFacility(stop3); schedule1.addStopFacility(stop4); line1.addRoute(route1); schedule1.addTransitLine(line1);
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; }
TransitScheduleFactory sb = this.schedule.getFactory(); tLine.addRoute(tRoute); this.schedule.addTransitLine(tLine); tLine.addRoute(tRoute); this.schedule.addTransitLine(tLine); tLine.addRoute(tRoute); this.schedule.addTransitLine(tLine);