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"); }
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 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 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()); }
@Test public void testDepartures_Single() { TransitSchedule schedule = new TransitScheduleFactoryImpl().createTransitSchedule(); TransitScheduleReaderV1 reader = new TransitScheduleReaderV1(schedule, new RouteFactories()); Stack<String> context = new Stack<String>();
@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 testRouteProfileRoute_NoLink() { 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); // now the other stuff Id<TransitLine> lineId = Id.create("1", TransitLine.class); reader.startTag(Constants.TRANSIT_LINE, new AttributesBuilder().add(Constants.ID, lineId.toString()).get(), context); context.push(Constants.TRANSIT_LINE); Id<TransitRoute> routeId1 = Id.create("1", TransitRoute.class); reader.startTag(Constants.TRANSIT_ROUTE, new AttributesBuilder().add(Constants.ID, routeId1.toString()).get(), context); context.push(Constants.TRANSIT_ROUTE); // by definition of the file format, transitRoute *must* have transportMode, routeProfile and departures defined reader.startTag(Constants.TRANSPORT_MODE, AttributesBuilder.getEmpty(), context); reader.endTag(Constants.TRANSPORT_MODE, "bus", context); reader.startTag(Constants.ROUTE_PROFILE, AttributesBuilder.getEmpty(), context); // route profile can be empty, but must exist reader.endTag(Constants.ROUTE_PROFILE, EMPTY_STRING, context); reader.startTag(Constants.ROUTE, AttributesBuilder.getEmpty(), context); reader.endTag(Constants.ROUTE, EMPTY_STRING, context); reader.endTag(Constants.ROUTE_PROFILE, EMPTY_STRING, context); reader.startTag(Constants.DEPARTURES, AttributesBuilder.getEmpty(), context); // departures can be empty, but must exist reader.endTag(Constants.DEPARTURES, EMPTY_STRING, context); reader.endTag(context.pop(), EMPTY_STRING, context); // TRANSIT_ROUTE reader.endTag(context.pop(), EMPTY_STRING, context); // TRANSIT_LINE reader.endTag(context.pop(), EMPTY_STRING, context); // TRANSIT_SCHEDULE TransitRoute route = schedule.getTransitLines().get(lineId).getRoutes().get(routeId1); assertNull(route.getRoute()); }
@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()); }
@Test public void testStopFacility_withName() { 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.NAME, "some stop name").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); assertEquals("some stop name", stop.getName()); }
@Test public void testTransitRoute_Single() { TransitSchedule schedule = new TransitScheduleFactoryImpl().createTransitSchedule(); TransitScheduleReaderV1 reader = new TransitScheduleReaderV1(schedule, new RouteFactories()); Stack<String> context = new Stack<String>();
@Test public void testStopFacility_Minimalistic() { 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").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); assertNull(stop.getLinkId()); assertNull(stop.getName()); assertFalse(stop.getIsBlockingLane()); }
@Test public void testDepartures_Multiple() { TransitSchedule schedule = new TransitScheduleFactoryImpl().createTransitSchedule(); TransitScheduleReaderV1 reader = new TransitScheduleReaderV1(schedule, new RouteFactories()); Stack<String> context = new Stack<String>();
@Test public void testTransitRoute_Multiple() { TransitSchedule schedule = new TransitScheduleFactoryImpl().createTransitSchedule(); TransitScheduleReaderV1 reader = new TransitScheduleReaderV1(schedule, new RouteFactories()); Stack<String> context = new Stack<String>();
@Test public void testStopFacility_withBadLink() { TransitSchedule schedule = new TransitScheduleFactoryImpl().createTransitSchedule(); Network network = (Network) NetworkUtils.createNetwork(); Node node1 = NetworkUtils.createAndAddNode(network, Id.create(1, Node.class), new Coord((double) 10, (double) 5)); Node node2 = NetworkUtils.createAndAddNode(network, Id.create(2, Node.class), new Coord((double) 5, (double) 11)); final Node fromNode = node1; final Node toNode = node2; NetworkUtils.createAndAddLink(network,Id.create(3, Link.class), fromNode, toNode, (double) 1000, 10.0, 2000.0, 1.0 ); 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.LINK_REF_ID, "4").get(); reader.startTag(Constants.STOP_FACILITY, atts, context); reader.endTag(Constants.STOP_FACILITY, "", context); context.pop(); reader.endTag(Constants.TRANSIT_STOPS, "", context); context.pop(); reader.endTag(Constants.TRANSIT_SCHEDULE, "", context); TransitStopFacility stop = schedule.getFacilities().get(Id.create("stop1", TransitStopFacility.class)); assertEquals(Id.create("4", Link.class), stop.getLinkId()); assertNull(network.getLinks().get(stop.getLinkId())); }
@Test public void testStopFacility_Multiple() { 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").get(); reader.startTag(Constants.STOP_FACILITY, atts, context); reader.endTag(Constants.STOP_FACILITY, EMPTY_STRING, context); atts = new AttributesBuilder().add(Constants.ID, "stop2"). add(Constants.X, "51").add(Constants.Y, "42").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(2, schedule.getFacilities().size()); TransitStopFacility stop1 = schedule.getFacilities().get(Id.create("stop1", TransitStopFacility.class)); assertNotNull(stop1); assertEquals(79.0, stop1.getCoord().getX(), MatsimTestCase.EPSILON); assertEquals(80.0, stop1.getCoord().getY(), MatsimTestCase.EPSILON); TransitStopFacility stop2 = schedule.getFacilities().get(Id.create("stop2", TransitStopFacility.class)); assertNotNull(stop2); assertEquals(51.0, stop2.getCoord().getX(), MatsimTestCase.EPSILON); assertEquals(42.0, stop2.getCoord().getY(), MatsimTestCase.EPSILON); }
@Test public void testStopFacility_withLink() { TransitSchedule schedule = new TransitScheduleFactoryImpl().createTransitSchedule(); Network network = (Network) NetworkUtils.createNetwork(); Node node1 = NetworkUtils.createAndAddNode(network, Id.create(1, Node.class), new Coord((double) 10, (double) 5)); Node node2 = NetworkUtils.createAndAddNode(network, Id.create(2, Node.class), new Coord((double) 5, (double) 11)); final Node fromNode = node1; final Node toNode = node2; Link link3 = NetworkUtils.createAndAddLink(network,Id.create(3, Link.class), fromNode, toNode, (double) 1000, 10.0, 2000.0, 1.0 ); 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.LINK_REF_ID, "3").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); assertEquals(link3.getId(), stop.getLinkId()); }