private boolean linkHasAlreadyAFormalPTStopFromTheGivenSchedule(Link link) { if (this.linkId2StopFacilityMap.containsKey(link.getId())) { // There is already a stop at this link, used by formal public transport - Use this one instead this.transitSchedule.addStopFacility(this.linkId2StopFacilityMap.get(link.getId())); return true; } else { return false; } }
private boolean linkHasAlreadyAFormalPTStopFromTheGivenSchedule(Link link) { if (this.linkId2StopFacilityMap.containsKey(link.getId())) { // There is already a stop at this link, used by formal public transport - Use this one instead this.transitSchedule.addStopFacility(this.linkId2StopFacilityMap.get(link.getId())); return true; } else { return false; } }
private boolean linkHasAlreadyAFormalPTStopFromTheGivenSchedule(Link link) { if (this.linkId2StopFacilityMap.containsKey(link.getId())) { // There is already a stop at this link, used by formal public transport - Use this one instead this.transitSchedule.addStopFacility(this.linkId2StopFacilityMap.get(link.getId())); return true; } else { return false; } }
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()); } } }
/** * 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; }
copies.add(newFacility); this.nodes.put(newFacility, toNode); this.schedule.addStopFacility(newFacility); toStop.setStopFacility(newFacility); this.stopFacilities.put(connection, newFacility);
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; }
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")); }
TransitStopFacility stop = this.transitSchedule.getFactory().createTransitStopFacility(stopId, link.getToNode().getCoord(), false); stop.setLinkId(link.getId()); this.transitSchedule.addStopFacility(stop); return 1;
TransitStopFacility stop = this.transitSchedule.getFactory().createTransitStopFacility(stopId, link.getToNode().getCoord(), false); stop.setLinkId(link.getId()); this.transitSchedule.addStopFacility(stop); return 1;
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); } }
@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 testAddStopFacilityException() { TransitSchedule schedule = new TransitScheduleImpl(new TransitScheduleFactoryImpl()); TransitStopFacility stop1a = new TransitStopFacilityImpl(Id.create(1, TransitStopFacility.class), new Coord((double) 2, (double) 2), false); TransitStopFacility stop1b = new TransitStopFacilityImpl(Id.create(1, TransitStopFacility.class), new Coord((double) 3, (double) 3), false); assertEquals(0, schedule.getFacilities().size()); schedule.addStopFacility(stop1a); assertEquals(1, schedule.getFacilities().size()); assertEquals(stop1a, schedule.getFacilities().get(stop1a.getId())); try { // try to add a line with same id schedule.addStopFacility(stop1b); fail("missing exception."); } catch (IllegalArgumentException e) { log.info("catched expected exception.", e); } assertEquals(1, schedule.getFacilities().size()); assertEquals(stop1a, schedule.getFacilities().get(stop1a.getId())); try { // try to add a line a second time schedule.addStopFacility(stop1a); fail("missing exception."); } catch (IllegalArgumentException e) { log.info("catched expected exception.", e); } assertEquals(1, schedule.getFacilities().size()); assertEquals(stop1a, schedule.getFacilities().get(stop1a.getId())); }
@Test public void testValidator_Transfers_missingStop() { Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); TransitSchedule schedule = scenario.getTransitSchedule(); TransitScheduleFactory factory = schedule.getFactory(); Id<TransitStopFacility> id1 = Id.create("stop1", TransitStopFacility.class); Id<TransitStopFacility> id2 = Id.create("stop2", TransitStopFacility.class); Id<TransitStopFacility> id3 = Id.create("stop3", TransitStopFacility.class); Id<TransitStopFacility> id4 = Id.create("stop4", TransitStopFacility.class); schedule.addStopFacility(factory.createTransitStopFacility(id1, new Coord(10000, 10000), false)); schedule.addStopFacility(factory.createTransitStopFacility(id2, new Coord(20000, 10000), false)); schedule.getMinimalTransferTimes().set(id1, id3, 120); TransitScheduleValidator.ValidationResult result = TransitScheduleValidator.validateTransfers(schedule); Assert.assertEquals("Should warn against missing stop3.", 1, result.getIssues().size()); Assert.assertTrue("Message should contain hint about stop3 being missing. " + result.getIssues().get(0).getMessage(), result.getIssues().get(0).getMessage().contains("stop3")); schedule.getMinimalTransferTimes().remove(id1, id3); schedule.getMinimalTransferTimes().set(id4, id2, 120); result = TransitScheduleValidator.validateTransfers(schedule); Assert.assertEquals("Should warn against missing stop4.", 1, result.getIssues().size()); Assert.assertTrue("Message should contain hint about stop4 being missing. " + result.getIssues().get(0).getMessage(), result.getIssues().get(0).getMessage().contains("stop4")); }
TransitStopFacility f5 = f.createTransitStopFacility(Id.create("5", TransitStopFacility.class), new Coord((double) 2000, (double) 0), false); schedule.addStopFacility(f1); schedule.addStopFacility(f2); schedule.addStopFacility(f3); schedule.addStopFacility(f4); schedule.addStopFacility(f5);
@Test public void testValidator_Transfers_implausibleTime() { Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); TransitSchedule schedule = scenario.getTransitSchedule(); TransitScheduleFactory factory = schedule.getFactory(); Id<TransitStopFacility> id1 = Id.create(1, TransitStopFacility.class); Id<TransitStopFacility> id2 = Id.create(2, TransitStopFacility.class); Id<TransitStopFacility> id3 = Id.create(3, TransitStopFacility.class); Id<TransitStopFacility> id4 = Id.create(4, TransitStopFacility.class); schedule.addStopFacility(factory.createTransitStopFacility(id1, new Coord(10000, 10000), false)); schedule.addStopFacility(factory.createTransitStopFacility(id2, new Coord(20000, 10000), false)); schedule.getMinimalTransferTimes().set(id1, id2, 120); TransitScheduleValidator.ValidationResult result = TransitScheduleValidator.validateTransfers(schedule); Assert.assertTrue(result.getIssues().isEmpty()); schedule.getMinimalTransferTimes().set(id1, id2, 0); result = TransitScheduleValidator.validateTransfers(schedule); Assert.assertEquals("Should warn against implausible transfer time.", 1, result.getIssues().size()); }
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(); }
this.pTransitSchedule.addStopFacility(stop);
@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)); }