/** * Merges all routes of a transit line that have the same sequence of stops. Does not respect the time profile of the routes. * * @param oldLine The transit line containing the routes to be merged. * @return A copy of the transit line with its transit routes merged. */ public static TransitLine mergeTransitLine(TransitLine oldLine) { return mergeTransitLine(new TransitScheduleFactoryImpl(), oldLine); }
protected TransitScheduleFactory createTransitScheduleBuilder() { return new TransitScheduleFactoryImpl(); }
private void run(){ this.transitSchedule = new TransitScheduleFactoryImpl().createTransitSchedule(); int stopsAdded = 0; for (Link link : this.net.getLinks().values()) { if(link.getAllowedModes().contains(TransportMode.car)){ stopsAdded += addStopOnLink(link); } } log.info("Added " + stopsAdded + " additional stops for paratransit services"); }
private void run(){ this.transitSchedule = new TransitScheduleFactoryImpl().createTransitSchedule(); int stopsAdded = 0; for (Link link : this.net.getLinks().values()) { if(link.getAllowedModes().contains(TransportMode.car)){ stopsAdded += addStopOnLink(link); } } log.info("Added " + stopsAdded + " additional stops for paratransit services"); }
private void run(){ this.transitSchedule = new TransitScheduleFactoryImpl().createTransitSchedule(); int stopsAdded = 0; /* handle all (merged) links between junction */ for (Link link : this.intersectionSimplifiedRoadNetwork.getLinks().values()) { if(link.getAllowedModes().contains(TransportMode.car)){ stopsAdded += addStopForSimplifiedNetworkLink(link); } } log.info("Added " + stopsAdded + " additional stops for paratransit services"); }
@Test public void testGetTransitLinesImmutable() { TransitSchedule schedule = new TransitScheduleImpl(new TransitScheduleFactoryImpl()); TransitLine line1 = new TransitLineImpl(Id.create(1, TransitLine.class)); try { schedule.getTransitLines().put(line1.getId(), line1); fail("missing exception."); } catch (UnsupportedOperationException e) { log.info("catched expected exception.", e); } }
@Test public void testGetFacilitiesImmutable() { TransitSchedule schedule = new TransitScheduleImpl(new TransitScheduleFactoryImpl()); TransitStopFacility stop1 = new TransitStopFacilityImpl(Id.create(1, TransitStopFacility.class), new Coord((double) 0, (double) 0), false); try { schedule.getFacilities().put(stop1.getId(), stop1); fail("missing exception."); } catch (UnsupportedOperationException e) { log.info("catched expected exception.", e); } }
@Test public void testInitialization() { TransitScheduleFactory builder = new TransitScheduleFactoryImpl(); TransitSchedule schedule = new TransitScheduleImpl(builder); assertEquals(builder, schedule.getFactory()); }
MutableScenario(Config config) { this.config = config; this.network = NetworkUtils.createNetwork(this.config); this.population = PopulationUtils.createPopulation(this.config, this.network); this.facilities = new ActivityFacilitiesImpl(); this.households = new HouseholdsImpl(); this.lanes = LanesUtils.createLanesContainer(); this.vehicles = VehicleUtils.createVehiclesContainer(); this.transitVehicles = VehicleUtils.createVehiclesContainer(); this.transitSchedule = new TransitScheduleFactoryImpl().createTransitSchedule(); this.config.network().setLocked(); }
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 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 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)); }
@Test public void testTransitLine_Single() { TransitSchedule schedule = new TransitScheduleFactoryImpl().createTransitSchedule(); TransitScheduleReaderV1 reader = new TransitScheduleReaderV1(schedule, new RouteFactories()); Stack<String> context = new Stack<String>(); reader.startTag(Constants.TRANSIT_SCHEDULE, AttributesBuilder.getEmpty(), context); context.push(Constants.TRANSIT_SCHEDULE); Id<TransitLine> lineId = Id.create("23", TransitLine.class); reader.startTag(Constants.TRANSIT_LINE, new AttributesBuilder().add(Constants.ID, lineId.toString()).get(), context); reader.endTag(Constants.TRANSIT_LINE, EMPTY_STRING, context);// TRANSIT_LINE reader.endTag(context.pop(), EMPTY_STRING, context);// TRANSIT_SCHEDULE assertEquals(1, schedule.getTransitLines().size()); TransitLine line = schedule.getTransitLines().get(lineId); assertNotNull(line); assertEquals(lineId, line.getId()); }
/** * 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()); }
@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 testRemoveStopFacility() { TransitSchedule schedule = new TransitScheduleImpl(new TransitScheduleFactoryImpl()); TransitStopFacility stop1 = new TransitStopFacilityImpl(Id.create(1, TransitStopFacility.class), new Coord((double) 0, (double) 0), false); TransitStopFacility stop1b = new TransitStopFacilityImpl(Id.create(1, TransitStopFacility.class), new Coord((double) 10, (double) 10), false); schedule.addStopFacility(stop1); Assert.assertFalse(schedule.removeStopFacility(stop1b)); Assert.assertTrue(schedule.removeStopFacility(stop1)); Assert.assertFalse(schedule.removeStopFacility(stop1)); }
public void testAddAgent() { EventsManager events = EventsUtils.createEventsManager(); TransitStopAgentTracker tracker = new TransitStopAgentTracker(events); TransitScheduleFactory builder = new TransitScheduleFactoryImpl(); PTPassengerAgent agent1 = new FakeAgent(null, null); PTPassengerAgent agent2 = new FakeAgent(null, null); PTPassengerAgent agent3 = new FakeAgent(null, null); TransitStopFacility stop1 = builder.createTransitStopFacility(Id.create(1, TransitStopFacility.class), new Coord((double) 2, (double) 3), false); TransitStopFacility stop2 = builder.createTransitStopFacility(Id.create(2, TransitStopFacility.class), new Coord((double) 3, (double) 4), false); assertFalse(tracker.getAgentsAtFacility(stop1.getId()).contains(agent1)); tracker.addAgentToStop(10, agent1, stop1.getId()); assertTrue(tracker.getAgentsAtFacility(stop1.getId()).contains(agent1)); assertFalse(tracker.getAgentsAtFacility(stop2.getId()).contains(agent1)); assertFalse(tracker.getAgentsAtFacility(stop1.getId()).contains(agent2)); tracker.addAgentToStop(10, agent2, stop1.getId()); assertTrue(tracker.getAgentsAtFacility(stop1.getId()).contains(agent2)); tracker.addAgentToStop(10, agent3, stop2.getId()); assertFalse(tracker.getAgentsAtFacility(stop1.getId()).contains(agent3)); assertFalse(tracker.getAgentsAtFacility(stop2.getId()).contains(agent1)); assertFalse(tracker.getAgentsAtFacility(stop2.getId()).contains(agent2)); assertTrue(tracker.getAgentsAtFacility(stop2.getId()).contains(agent3)); }
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()); }