@Override public TransitLine createEmptyLineFromOperator(Id<Operator> id) { return this.scheduleWithStopsOnly.getFactory().createTransitLine(Id.create(id, TransitLine.class)); }
@Override public TransitLine createEmptyLineFromOperator(Id<Operator> id) { return this.scheduleWithStopsOnly.getFactory().createTransitLine(Id.create(id, TransitLine.class)); }
@Override public TransitLine createEmptyLineFromOperator(Id<Operator> id) { return this.scheduleWithStopsOnly.getFactory().createTransitLine(Id.create(id, TransitLine.class)); }
@Override public TransitLine createEmptyLineFromOperator(Id<Operator> id) { return this.scheduleWithStopsOnly.getFactory().createTransitLine(Id.create(id, TransitLine.class)); }
@Override public void endTag(final String name, final String content, final Stack<String> context) { if (Constants.DESCRIPTION.equals(name) && Constants.TRANSIT_ROUTE.equals(context.peek())) { this.currentTransitRoute.description = content; } else if (Constants.TRANSPORT_MODE.equals(name)) { this.currentTransitRoute.mode = content.intern(); } else if (Constants.TRANSIT_ROUTE.equals(name)) { List<TransitRouteStop> stops = new ArrayList<TransitRouteStop>(this.currentTransitRoute.stops.size()); for (TempStop tStop : this.currentTransitRoute.stops) { TransitRouteStopImpl routeStop = new TransitRouteStopImpl(tStop.stop, tStop.arrival, tStop.departure); stops.add(routeStop); routeStop.setAwaitDepartureTime(tStop.awaitDeparture); } NetworkRoute route = null; if (this.currentRouteProfile.firstLinkId != null) { if (this.currentRouteProfile.lastLinkId == null) { this.currentRouteProfile.lastLinkId = this.currentRouteProfile.firstLinkId; } route = this.routeFactory.createRoute(NetworkRoute.class, this.currentRouteProfile.firstLinkId, this.currentRouteProfile.lastLinkId); route.setLinkIds(this.currentRouteProfile.firstLinkId, this.currentRouteProfile.linkIds, this.currentRouteProfile.lastLinkId); } TransitRoute transitRoute = this.schedule.getFactory().createTransitRoute(this.currentTransitRoute.id, route, stops, this.currentTransitRoute.mode); transitRoute.setDescription(this.currentTransitRoute.description); for (Departure departure : this.currentTransitRoute.departures.values()) { transitRoute.addDeparture(departure); } this.currentTransitLine.addRoute(transitRoute); } }
TransitLine line = this.scheduleWithStopsOnly.getFactory().createTransitLine(pLineId); routeId = Id.create(pLineId + "-" + routeId, TransitRoute.class); TransitRoute transitRoute = createRoute(routeId, stopsToBeServed.get(0), stopsToBeServed.get(1), startTime); for (int i = 0; i < numberOfVehicles; i++) { for (double j = startTime + i * headway; j < endTime; ) { Departure departure = this.scheduleWithStopsOnly.getFactory().createDeparture(Id.create(n, Departure.class), j); departure.setVehicleId(Id.create(transitRoute.getId().toString() + "-" + i, Vehicle.class)); transitRoute.addDeparture(departure);
private TransitLine createTransitLine(Id<TransitLine> pLineId, double startTime, double endTime, int numberOfVehicles, ArrayList<TransitStopFacility> stopsToBeServed, Id<TransitRoute> routeId){ // initialize TransitLine line = this.scheduleWithStopsOnly.getFactory().createTransitLine(pLineId); routeId = Id.create(pLineId + "-" + routeId, TransitRoute.class); TransitRoute transitRoute = createRoute(routeId, stopsToBeServed); // register route line.addRoute(transitRoute); // add departures int n = 0; /* After finishing one tour, vehicles wait the driver rest time and then start the next tour immediately. * So, headway is a function of the number of vehicles and the time spent on one tour of the TransitRoute. */ int headway = (int) (transitRoute.getStops().get(transitRoute.getStops().size() - 1).getDepartureOffset() + this.driverRestTime) / numberOfVehicles; for (int i = 0; i < numberOfVehicles; i++) { for (double j = startTime + i * headway; j <= endTime; ) { Departure departure = this.scheduleWithStopsOnly.getFactory().createDeparture(Id.create(n, Departure.class), j); departure.setVehicleId(Id.create(transitRoute.getId().toString() + "-" + i, Vehicle.class)); transitRoute.addDeparture(departure); j += transitRoute.getStops().get(transitRoute.getStops().size() - 1).getDepartureOffset() + this.driverRestTime; n++; } } // log.info("added " + n + " departures"); return line; }
/** * Merges all routes of a transit line that have the same sequence of stops. Does not respect the time profile of the routes. * * @param transitSchedule to be modified. * @return A copy of the transit schedule with transit lines merged. */ public static TransitSchedule mergeSimilarRoutes(TransitSchedule transitScheduleOrig){ printStatistic(transitScheduleOrig); TransitScheduleFactory transitScheduleFactory = transitScheduleOrig.getFactory(); TransitSchedule transitSchedule = transitScheduleFactory.createTransitSchedule(); for (TransitStopFacility stop : transitScheduleOrig.getFacilities().values()) { transitSchedule.addStopFacility(stop); } for (TransitLine oldLine : transitScheduleOrig.getTransitLines().values()) { TransitLine newLine = mergeTransitLine(transitScheduleFactory, oldLine); transitSchedule.addTransitLine(newLine); } printStatistic(transitSchedule); return transitSchedule; }
private TransitLine createTransitLine(Id<TransitLine> lineId, double startTime, double endTime, int numberOfVehicles, ArrayList<TransitStopFacility> stopsToBeServed, Id<TransitRoute> routeId){ // initialize TransitLine line = this.scheduleWithStopsOnly.getFactory().createTransitLine(lineId); routeId = Id.create(lineId + "-" + routeId, TransitRoute.class); TransitRoute transitRoute = createRoute(routeId, stopsToBeServed); // register route line.addRoute(transitRoute); // add departures int n = 0; /* After finishing one tour, vehicles wait the driver rest time and then start the next tour immediately. * So, headway is a function of the number of vehicles and the time spent on one tour of the TransitRoute. */ int headway = (int) (transitRoute.getStops().get(transitRoute.getStops().size() - 1).getDepartureOffset() + this.driverRestTime) / numberOfVehicles; for (int i = 0; i < numberOfVehicles; i++) { for (double j = startTime + i * headway; j <= endTime; ) { Departure departure = this.scheduleWithStopsOnly.getFactory().createDeparture(Id.create(n, Departure.class), j); departure.setVehicleId(Id.create(transitRoute.getId().toString() + "-" + i, Vehicle.class)); transitRoute.addDeparture(departure); j += transitRoute.getStops().get(transitRoute.getStops().size() - 1).getDepartureOffset() + this.driverRestTime; n++; } } // log.info("added " + n + " departures"); return line; }
@Test public void testInitialization() { TransitScheduleFactory builder = new TransitScheduleFactoryImpl(); TransitSchedule schedule = new TransitScheduleImpl(builder); assertEquals(builder, schedule.getFactory()); }
@Test public void testCreateTransitSchedule() { TransitScheduleFactory builder = createTransitScheduleBuilder(); TransitSchedule schedule = builder.createTransitSchedule(); Assert.assertEquals(builder, schedule.getFactory()); }
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; }
TransitStopFacility stop = this.transitSchedule.getFactory().createTransitStopFacility(stopId, link.getToNode().getCoord(), false); stop.setLinkId(link.getId()); this.transitSchedule.addStopFacility(stop);
TransitStopFacility stop = this.transitSchedule.getFactory().createTransitStopFacility(stopId, link.getToNode().getCoord(), false); stop.setLinkId(link.getId()); this.transitSchedule.addStopFacility(stop);
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); } }
public Fixture() { this.config = ConfigUtils.createConfig(); this.config.transit().setUseTransit(true); ScenarioBuilder scBuilder = new ScenarioBuilder(config) ; this.scenario = (MutableScenario) scBuilder.build() ; this.network = this.scenario.getNetwork(); this.schedule = this.scenario.getTransitSchedule(); this.builder = this.schedule.getFactory(); }
@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()); }
private void addSimpleTransitServices(Scenario scenario) { TransitSchedule schedule = scenario.getTransitSchedule(); TransitScheduleFactory f = schedule.getFactory(); final double x = -6000; TransitStopFacility stopFacility1 = f.createTransitStopFacility(Id.create(1, TransitStopFacility.class), new Coord(x, (double) 1500), false); stopFacility1.setLinkId(Id.create(14, Link.class)); final double y = -4000; TransitStopFacility stopFacility2 = f.createTransitStopFacility(Id.create(2, TransitStopFacility.class), new Coord((double) 5000, y), false); stopFacility2.setLinkId(Id.create(21, Link.class)); schedule.addStopFacility(stopFacility1); schedule.addStopFacility(stopFacility2); TransitLine line1 = f.createTransitLine(Id.create(1, TransitLine.class)); NetworkRoute netRoute = RouteUtils.createLinkNetworkRouteImpl(Id.create("14", Link.class), new Id[] { Id.create("20", Link.class) }, Id.create("21", Link.class)); List<TransitRouteStop> stops = new ArrayList<TransitRouteStop>(); stops.add(f.createTransitRouteStop(stopFacility1, Time.UNDEFINED_TIME, 0)); stops.add(f.createTransitRouteStop(stopFacility2, 180, Time.UNDEFINED_TIME)); TransitRoute route1 = f.createTransitRoute(Id.create(1, TransitRoute.class), netRoute, stops, "bus"); line1.addRoute(route1); schedule.addTransitLine(line1); for (int i = 0; i < 20; i++) { route1.addDeparture(f.createDeparture(Id.create(i, Departure.class), 6.0 * 3600 + i * 600)); } new CreateVehiclesForSchedule(schedule, scenario.getTransitVehicles()).run(); }
@Test public void testInitializationDeparture() { Config config = ConfigUtils.createConfig(); config.transit().setUseTransit(true); Scenario scenario = ScenarioUtils.createScenario(config); EventsManager eventsManager = EventsUtils.createEventsManager(); TransitStopAgentTracker tracker = new TransitStopAgentTracker(eventsManager); PrepareForSimUtils.createDefaultPrepareForSim(scenario).run(); QSim tqsim = new QSimBuilder(scenario.getConfig()) // .useDefaults() // .build(scenario, eventsManager); TransitQSimEngine trEngine = new TransitQSimEngine(tqsim) ; tqsim.addMobsimEngine(trEngine); TransitScheduleFactory builder = scenario.getTransitSchedule().getFactory(); TransitLine tLine = builder.createTransitLine(Id.create("L", TransitLine.class)); NetworkRoute route = RouteUtils.createLinkNetworkRouteImpl(null, null); TransitRoute tRoute = builder.createTransitRoute(Id.create("L1", TransitRoute.class), route, Collections.<TransitRouteStop>emptyList(), "bus"); double depTime = 9876.5; Departure dep = builder.createDeparture(Id.create("L1.1", Departure.class), depTime); tRoute.addDeparture(dep); tLine.addRoute(tRoute); AbstractTransitDriverAgent driver = new TransitDriverAgentImpl(new SingletonUmlaufBuilderImpl(Collections.singleton(tLine)).build().get(0), TransportMode.car, tracker, trEngine.getInternalInterface()); assertEquals(depTime, driver.getActivityEndTime(), MatsimTestCase.EPSILON); }