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()); } } }
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);
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);
/** * 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; }
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); }
void notifyScoring(ScoringEvent event) { if (this.subsidy != null) { subsidy.computeSubsidy(); } Map<Id<Vehicle>, PScoreContainer> driverId2ScoreMap = this.scorePlansHandler.getDriverId2ScoreMap(); for (Operator operator : this.operators) { operator.score(driverId2ScoreMap, subsidy, routeDesignScoreManager); } // why is the following done twice (see notifyIterationstarts)? 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()); } writeScheduleToFile(this.pTransitSchedule, event.getServices().getControlerIO().getIterationFilename(event.getIteration(), "transitScheduleScored.xml.gz")); }
@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())); }
@Test public void testAddTransitLineException() { TransitSchedule schedule = new TransitScheduleImpl(new TransitScheduleFactoryImpl()); TransitLine line1a = new TransitLineImpl(Id.create(1, TransitLine.class)); TransitLine line1b = new TransitLineImpl(Id.create(1, TransitLine.class)); assertEquals(0, schedule.getTransitLines().size()); schedule.addTransitLine(line1a); assertEquals(1, schedule.getTransitLines().size()); assertEquals(line1a, schedule.getTransitLines().get(line1a.getId())); try { // try to add a line with same id schedule.addTransitLine(line1b); fail("missing exception."); } catch (IllegalArgumentException e) { log.info("catched expected exception.", e); } assertEquals(1, schedule.getTransitLines().size()); assertEquals(line1a, schedule.getTransitLines().get(line1a.getId())); try { // try to add a line a second time schedule.addTransitLine(line1a); fail("missing exception."); } catch (IllegalArgumentException e) { log.info("catched expected exception.", e); } assertEquals(1, schedule.getTransitLines().size()); assertEquals(line1a, schedule.getTransitLines().get(line1a.getId())); }
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); } }
schedule.addTransitLine(tLine1); schedule.addTransitLine(tLine2);
tRoute1.addDeparture(builder.createDeparture(Id.create(6, Departure.class), Time.parseTime("07:25:00"))); schedule.addTransitLine(tLine1); tRoute2.addDeparture(builder.createDeparture(Id.create(3, Departure.class), Time.parseTime("07:22:00"))); schedule.addTransitLine(tLine2);
TransitRoute route1 = f.createTransitRoute(Id.create("1", TransitRoute.class), null, stops, "pt"); line1.addRoute(route1); schedule.addTransitLine(line1); route1.addDeparture(f.createDeparture(Id.create("1", Departure.class), 6.0*3600)); TransitRoute route2 = f.createTransitRoute(Id.create("2", TransitRoute.class), null, stops2, "pt"); line2.addRoute(route2); schedule.addTransitLine(line2); route2.addDeparture(f.createDeparture(Id.create("2", Departure.class), 6.0*3600 - 60));
@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()); } }
@Test public void testRemoveTransitLine() { TransitSchedule schedule = new TransitScheduleImpl(new TransitScheduleFactoryImpl()); TransitLine line1 = new TransitLineImpl(Id.create(1, TransitLine.class)); TransitLine line1b = new TransitLineImpl(Id.create(1, TransitLine.class)); schedule.addTransitLine(line1); Assert.assertFalse(schedule.removeTransitLine(line1b)); Assert.assertTrue(schedule.removeTransitLine(line1)); Assert.assertFalse(schedule.removeTransitLine(line1)); }
this.pTransitSchedule.addTransitLine(operator.getCurrentTransitLine());
/** * 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()); }
protected void buildRedLine() { this.redLine = this.builder.createTransitLine(Id.create("red", TransitLine.class)); this.schedule.addTransitLine(this.redLine);
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(); }
protected void buildGreenLine() { this.greenLine = this.builder.createTransitLine(Id.create("green", TransitLine.class)); this.schedule.addTransitLine(this.greenLine);
schedule.addTransitLine(tLine1);