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); } }
/** * 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 static TransitLine mergeTransitLine(TransitScheduleFactory transitScheduleFactory, TransitLine oldLine) { TransitLine newLine = transitScheduleFactory.createTransitLine(oldLine.getId()); Departure newDeparture = transitScheduleFactory.createDeparture(newDepartureId, oldDeparture.getDepartureTime()); newDeparture.setVehicleId(oldDeparture.getVehicleId()); mergeDestination.addDeparture(newDeparture);
routeStop = this.scheduleWithStopsOnly.getFactory().createTransitRouteStop(tempStopsToBeServed.get(0), runningTime, runningTime); stops.add(routeStop); continue; routeStop = this.scheduleWithStopsOnly.getFactory().createTransitRouteStop(this.linkId2StopFacilityMap.get(link.getId()), runningTime, runningTime); stops.add(routeStop); routeStop = this.scheduleWithStopsOnly.getFactory().createTransitRouteStop(tempStopsToBeServed.get(0), runningTime, runningTime); stops.add(routeStop); TransitRoute transitRoute = this.scheduleWithStopsOnly.getFactory().createTransitRoute(routeID, route, stops, this.transportMode); return transitRoute;
boolean isBlocking = Boolean.parseBoolean(atts.getValue(Constants.IS_BLOCKING)); TransitStopFacility stop = schedule.getFactory().createTransitStopFacility( Id.create( atts.getValue(Constants.ID), } else if (Constants.TRANSIT_LINE.equals(name)) { Id<TransitLine> id = Id.create(atts.getValue(Constants.ID), TransitLine.class); this.currentTransitLine = schedule.getFactory().createTransitLine(id); if (atts.getValue(Constants.NAME) != null) { this.currentTransitLine.setName(atts.getValue(Constants.NAME));
public void testInitializationDeparture() { TransitScheduleFactory builder = new TransitScheduleFactoryImpl(); TransitLine tLine = builder.createTransitLine(Id.create("L", TransitLine.class)); NetworkRoute route = RouteUtils.createLinkNetworkRouteImpl(null, null); TransitRoute tRoute = builder.createTransitRoute(Id.create("L", 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); Umlauf umlauf = buildUmlauf(tLine); EventsManager events = EventsUtils.createEventsManager(); TransitStopAgentTracker tracker = new TransitStopAgentTracker(events); Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); PrepareForSimUtils.createDefaultPrepareForSim(scenario).run(); QSim tqsim = new QSimBuilder(scenario.getConfig()) // .useDefaults() // .build(scenario, events); TransitQSimEngine trEngine = new TransitQSimEngine(tqsim) ; tqsim.addMobsimEngine(trEngine); AbstractTransitDriverAgent driver = new TransitDriverAgentImpl(umlauf, TransportMode.car, tracker, trEngine.getInternalInterface()); assertEquals(depTime, driver.getActivityEndTime(), MatsimTestCase.EPSILON); }
public void testInitializationStops() { TransitScheduleFactory builder = new TransitScheduleFactoryImpl(); TransitStopFacility stop1 = builder.createTransitStopFacility(Id.create(1, TransitStopFacility.class), new Coord(5, 11), false); TransitStopFacility stop2 = builder.createTransitStopFacility(Id.create(2, TransitStopFacility.class), new Coord(18, 7), false); Link link1 = new FakeLink(Id.create(3, Link.class)); Link link2 = new FakeLink(Id.create(4, Link.class)); stop1.setLinkId(link1.getId()); stop2.setLinkId(link2.getId()); TransitLine line = builder.createTransitLine(Id.create(5, TransitLine.class)); TransitRoute tRoute = builder.createTransitRoute(Id.create(6, TransitRoute.class), null, Collections.<TransitRouteStop>emptyList(), "bus"); ExperimentalTransitRoute route = new ExperimentalTransitRoute(stop1, line, tRoute, stop2); assertEquals(stop1.getId(), route.getAccessStopId()); assertEquals(line.getId(), route.getLineId()); assertEquals(tRoute.getId(), route.getRouteId()); assertEquals(stop2.getId(), route.getEgressStopId()); assertEquals(link1.getId(), route.getStartLinkId()); assertEquals(link2.getId(), route.getEndLinkId()); }
TransitStopFacility newFacility = this.schedule.getFactory().createTransitStopFacility(newId, toFacility.getCoord(), toFacility.getIsBlockingLane()); newFacility.setStopAreaId(Id.create(toFacility.getId(), TransitStopArea.class)); newFacility.setLinkId(link.getId());
@Override public TransitLine createEmptyLineFromOperator(Id<Operator> id) { return this.scheduleWithStopsOnly.getFactory().createTransitLine(Id.create(id, TransitLine.class)); }
/** * Tests that the default format written is in v2 format. * * @throws IOException * @throws SAXException * @throws ParserConfigurationException */ @Test public void testDefaultV2() throws IOException, SAXException, ParserConfigurationException { String filename = this.utils.getOutputDirectory() + "schedule.xml"; TransitScheduleFactory builder = new TransitScheduleFactoryImpl(); TransitSchedule schedule = builder.createTransitSchedule(); TransitLine line = builder.createTransitLine(Id.create(1, TransitLine.class)); schedule.addTransitLine(line); TransitScheduleWriter writer = new TransitScheduleWriter(schedule); writer.writeFile(filename); TransitScheduleFactory builder2 = new TransitScheduleFactoryImpl(); TransitSchedule schedule2 = builder2.createTransitSchedule(); new TransitScheduleReaderV2(schedule2, new RouteFactories()).readFile(filename); Assert.assertEquals(1, schedule2.getTransitLines().size()); }
@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); } }
@Test public void testCreateDeparture() { TransitScheduleFactory builder = createTransitScheduleBuilder(); Id<Departure> id = Id.create(8, Departure.class); double time = 9.0*3600; Departure dep = builder.createDeparture(id, time); Assert.assertEquals(id, dep.getId()); Assert.assertEquals(time, dep.getDepartureTime(), MatsimTestUtils.EPSILON); }
@Test public void testCreateTransitRouteStop() { TransitScheduleFactory builder = createTransitScheduleBuilder(); TransitStopFacility stopFacility = new TransitStopFacilityImpl(Id.create(5, TransitStopFacility.class), new Coord((double) 6, (double) 6), false); double arrivalOffset = 23; double departureOffset = 42; TransitRouteStop stop = builder.createTransitRouteStop(stopFacility, 23, 42); Assert.assertEquals(stopFacility, stop.getStopFacility()); Assert.assertEquals(arrivalOffset, stop.getArrivalOffset(), MatsimTestUtils.EPSILON); Assert.assertEquals(departureOffset, stop.getDepartureOffset(), MatsimTestUtils.EPSILON); }
@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); }
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), } 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) {
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);
routeStop = this.scheduleWithStopsOnly.getFactory().createTransitRouteStop(tempStopsToBeServed.get(0), runningTime, runningTime); stops.add(routeStop); routeStop = this.scheduleWithStopsOnly.getFactory().createTransitRouteStop(this.linkId2StopFacilityMap.get(link.getId()), runningTime, runningTime); stops.add(routeStop); routeStop = this.scheduleWithStopsOnly.getFactory().createTransitRouteStop(tempStopsToBeServed.get(0), runningTime, runningTime); stops.add(routeStop); TransitRoute transitRoute = this.scheduleWithStopsOnly.getFactory().createTransitRoute(routeID, route, stops, this.transportMode); return transitRoute;
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; }
@Override public TransitLine createEmptyLineFromOperator(Id<Operator> id) { return this.scheduleWithStopsOnly.getFactory().createTransitLine(Id.create(id, TransitLine.class)); }
@Test public void testTransitLineName() { String filename = this.utils.getOutputDirectory() + "schedule.xml"; TransitScheduleFactory builder = new TransitScheduleFactoryImpl(); TransitSchedule schedule = builder.createTransitSchedule(); TransitLine line = builder.createTransitLine(Id.create(1, TransitLine.class)); line.setName("Blue line"); schedule.addTransitLine(line); TransitScheduleWriter writer = new TransitScheduleWriter(schedule); writer.writeFile(filename); TransitScheduleFactory builder2 = new TransitScheduleFactoryImpl(); TransitSchedule schedule2 = builder2.createTransitSchedule(); new TransitScheduleReaderV1(schedule2, new RouteFactories()).readFile(filename); Assert.assertEquals(1, schedule2.getTransitLines().size()); Assert.assertEquals("Blue line", schedule2.getTransitLines().get(Id.create(1, TransitLine.class)).getName()); } }