private ArtificiallyConnectedStopFacility getArtificiallyConnectedStopFacility( TransitStopFacility facility) { if (!artificiallyConnectedStopFacilities.containsKey(facility.getId())) { artificiallyConnectedStopFacilities.put( facility.getId(), new ArtificiallyConnectedStopFacility(facility)); } return artificiallyConnectedStopFacilities.get(facility.getId()); }
ArtificiallyConnectedStopFacility(TransitStopFacility facility) { myNode = networkFactory.createNode( Id.create(prefix + facility.getId(), Node.class), facility.getCoord()); myLink = getNewLink(myNode, myNode); facility.setLinkId(myLink.getId()); }
/** * Link the pt-stations in the schedule to the closest network links. Thereby modifies * this.schedule. */ protected void linkStationsToNetwork() { log.info("Linking pt stations to network..."); Counter counter = new Counter("route # "); Set<TransitStopFacility> newFacilities = new HashSet<>(); for (TransitStopFacility facility : this.schedule.getFacilities().values()) { final Id<Link> closestLink = findClosestLink(facility); if (closestLink != null) { // link stop-facilities to the respective links. List<Id<TransitStopFacility>> localLinkedFacilities = new ArrayList<>(); facility.setLinkId(closestLink); localLinkedFacilities.add(facility.getId()); // if street-link has opposite direction or if we searched for all links in area, then split // stop-position before linking. final List<Id<Link>> oppositeDirectionLinks = getOppositeDirection(closestLink); if (oppositeDirectionLinks != null && !oppositeDirectionLinks.isEmpty()) { TransitStopFacility[] newStopFacilities = multiplyStop(facility, oppositeDirectionLinks.size()); for (int i = 0; i < oppositeDirectionLinks.size(); i++) { newStopFacilities[i + 1].setLinkId(oppositeDirectionLinks.get(i)); localLinkedFacilities.add(newStopFacilities[i + 1].getId()); newFacilities.add(newStopFacilities[i + 1]); } } linkedStopFacilitiesTree.put(facility.getId(), localLinkedFacilities); } counter.incCounter(); } for (TransitStopFacility facility : newFacilities) { this.schedule.addStopFacility(facility); } counter.printCounter(); log.info("Linking pt stations to network... done."); for (List<Id<TransitStopFacility>> facilityList : linkedStopFacilitiesTree.values()) { for (Id<TransitStopFacility> facilityId : facilityList) { linkedStopFacilities.add(facilityId); } } }
private void setConnectedStopFacilitiesToIsBlocking() { Set<TransitStopFacility> facilitiesToExchange = new HashSet<>(); for (TransitStopFacility oldFacility : this.schedule.getFacilities().values()) { if (this.network .getLinks() .get(oldFacility.getLinkId()) .getAllowedModes() .contains(TransportMode.car)) { TransitStopFacility newFacility = this.scheduleFactory.createTransitStopFacility( oldFacility.getId(), oldFacility.getCoord(), true); newFacility.setName(oldFacility.getName()); newFacility.setLinkId(oldFacility.getLinkId()); newFacility.setStopPostAreaId(oldFacility.getStopPostAreaId()); facilitiesToExchange.add(newFacility); } } for (TransitStopFacility facility : facilitiesToExchange) { TransitStopFacility facilityToRemove = this.schedule.getFacilities().get(facility.getId()); this.schedule.removeStopFacility(facilityToRemove); this.schedule.addStopFacility(facility); } }
/** * Create and add to schedule new stops with the id-endings "_1" to "_numberOfCopies" by copying * the provided stopFacility. * * @param stopFacility which will be copied. The original becomes the first element of the * returned array. * @param numberOfCopies of stopFacility which are created. * @return TransitStopFacilities stopFacility, and copies stop_1 to stop_numberOfCopies */ private TransitStopFacility[] multiplyStop(TransitStopFacility stopFacility, int numberOfCopies) { TransitStopFacility[] facilities = new TransitStopFacility[numberOfCopies + 1]; facilities[0] = stopFacility; for (int i = 1; i <= numberOfCopies; i++) { // Copy facility at stopFacility: Id<TransitStopFacility> idNewFacility = Id.create(stopFacility.getId().toString() + "_" + i, TransitStopFacility.class); TransitStopFacility newFacility = this.scheduleFactory.createTransitStopFacility( idNewFacility, stopFacility.getCoord(), stopFacility.getIsBlockingLane()); newFacility.setName(stopFacility.getName()); // Add new facility to schedule and to array: facilities[i] = newFacility; } return facilities; }