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"); }
/** * 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"); }
@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); } }
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 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); } }
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(); }
@Test public void testInitialization() { TransitScheduleFactory builder = new TransitScheduleFactoryImpl(); TransitSchedule schedule = new TransitScheduleImpl(builder); assertEquals(builder, schedule.getFactory()); }
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())); }
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 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 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()); }
@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_Multiple() { 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> lineId1 = Id.create("23", TransitLine.class); reader.startTag(Constants.TRANSIT_LINE, new AttributesBuilder().add(Constants.ID, lineId1.toString()).get(), context); reader.endTag(Constants.TRANSIT_LINE, EMPTY_STRING, context);// TRANSIT_LINE Id<TransitLine> lineId2 = Id.create("42", TransitLine.class); reader.startTag(Constants.TRANSIT_LINE, new AttributesBuilder().add(Constants.ID, lineId2.toString()).get(), context); reader.endTag(Constants.TRANSIT_LINE, EMPTY_STRING, context);// TRANSIT_LINE reader.endTag(context.pop(), EMPTY_STRING, context);// TRANSIT_SCHEDULE assertEquals(2, schedule.getTransitLines().size()); TransitLine line1 = schedule.getTransitLines().get(lineId1); assertNotNull(line1); assertEquals(lineId1, line1.getId()); TransitLine line2 = schedule.getTransitLines().get(lineId2); assertNotNull(line2); assertEquals(lineId2, line2.getId()); }
public void testGetAgentsAtStopImmutable() { EventsManager events = EventsUtils.createEventsManager(); TransitStopAgentTracker tracker = new TransitStopAgentTracker(events); TransitScheduleFactory builder = new TransitScheduleFactoryImpl(); PTPassengerAgent agent1 = new FakeAgent(null, null); TransitStopFacility stop1 = builder.createTransitStopFacility(Id.create(1, TransitStopFacility.class), new Coord((double) 2, (double) 3), false); try { tracker.getAgentsAtFacility(stop1.getId()).add(agent1); fail("missing exception, empty list should be immutable."); } catch (UnsupportedOperationException e) { log.info("catched expected exception.", e); } tracker.addAgentToStop(10, agent1, stop1.getId()); try { tracker.getAgentsAtFacility(stop1.getId()).remove(0); fail("missing exception, non-empty list should be immutable."); } catch (UnsupportedOperationException e) { log.info("catched expected exception.", e); } } }
@Test public void testTransitRoute_Description() { TransitSchedule schedule = new TransitScheduleFactoryImpl().createTransitSchedule(); TransitScheduleReaderV1 reader = new TransitScheduleReaderV1(schedule, new RouteFactories()); Stack<String> context = new Stack<String>();
@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())); }
@Test public void testStopFacility_isBlocking() { TransitSchedule schedule = new TransitScheduleFactoryImpl().createTransitSchedule(); TransitScheduleReaderV1 reader = new TransitScheduleReaderV1(schedule, new RouteFactories()); Stack<String> context = new Stack<String>(); Attributes emptyAtts = AttributesBuilder.getEmpty(); reader.startTag(Constants.TRANSIT_SCHEDULE, emptyAtts, context); context.push(Constants.TRANSIT_SCHEDULE); reader.startTag(Constants.TRANSIT_STOPS, emptyAtts, context); context.push(Constants.TRANSIT_STOPS); Attributes atts = new AttributesBuilder().add(Constants.ID, "stop1"). add(Constants.X, "79").add(Constants.Y, "80").add(Constants.IS_BLOCKING, "true").get(); reader.startTag(Constants.STOP_FACILITY, atts, context); reader.endTag(Constants.STOP_FACILITY, EMPTY_STRING, context); reader.endTag(context.pop(), EMPTY_STRING, context);// TRANSIT_STOPS reader.endTag(context.pop(), EMPTY_STRING, context);// TRANSIT_SCHEDULE assertEquals(1, schedule.getFacilities().size()); TransitStopFacility stop = schedule.getFacilities().get(Id.create("stop1", TransitStopFacility.class)); assertNotNull(stop); assertEquals(79.0, stop.getCoord().getX(), MatsimTestCase.EPSILON); assertEquals(80.0, stop.getCoord().getY(), MatsimTestCase.EPSILON); assertTrue(stop.getIsBlockingLane()); }