Java Code Examples for org.matsim.api.core.v01.network.Network#getLinks()
The following examples show how to use
org.matsim.api.core.v01.network.Network#getLinks() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScheduleTools.java From pt2matsim with GNU General Public License v2.0 | 6 votes |
/** * Add mode "pt" to any link of the network that is * passed by any transitRoute of the schedule. */ public static void addPTModeToNetwork(TransitSchedule schedule, Network network) { log.info("... Adding mode \"pt\" to all links with public transit"); Map<Id<Link>, ? extends Link> networkLinks = network.getLinks(); Set<Id<Link>> transitLinkIds = new HashSet<>(); for(TransitLine line : schedule.getTransitLines().values()) { for(TransitRoute transitRoute : line.getRoutes().values()) { if(transitRoute.getRoute() != null) { transitLinkIds.addAll(getTransitRouteLinkIds(transitRoute)); } } } for(Id<Link> transitLinkId : transitLinkIds) { Link transitLink = networkLinks.get(transitLinkId); if(!transitLink.getAllowedModes().contains(TransportMode.pt)) { Set<String> modes = new HashSet<>(transitLink.getAllowedModes()); modes.add(TransportMode.pt); transitLink.setAllowedModes(modes); } } }
Example 2
Source File: NetworkTools.java From pt2matsim with GNU General Public License v2.0 | 5 votes |
/** * @return the network links from a given list of link ids */ public static List<Link> getLinksFromIds(Network network, List<Id<Link>> linkIds) { Map<Id<Link>, ? extends Link> links = network.getLinks(); List<Link> list = new ArrayList<>(); for(Id<Link> linkId : linkIds) { list.add(links.get(linkId)); } return list; }
Example 3
Source File: ScheduleCleaner.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
/** * Removes links that are not used by public transit. Links which have a mode defined * in modesToKeep are kept regardless of public transit usage. Opposite links of used * links are kept if keepOppositeLinks is true. */ public static void removeNotUsedTransitLinks(TransitSchedule schedule, Network network, Set<String> modesToKeep, boolean keepOppositeLinks) { log.info("... Removing links that are not used by public transit"); Set<Id<Link>> usedTransitLinkIds = new HashSet<>(); for(TransitLine line : schedule.getTransitLines().values()) { for(TransitRoute route : line.getRoutes().values()) { if(route.getRoute() != null) usedTransitLinkIds.addAll(ScheduleTools.getTransitRouteLinkIds(route)); } } Map<Id<Link>, ? extends Link> links = network.getLinks(); if(keepOppositeLinks) { for(Id<Link> linkId : new HashSet<>(usedTransitLinkIds)) { Link oppositeLink = NetworkTools.getOppositeLink(links.get(linkId)); if(oppositeLink != null) usedTransitLinkIds.add(oppositeLink.getId()); } } int linksRemoved = 0; for(Link link : new HashSet<>(network.getLinks().values())) { // only remove link if there are only modes to remove on it if(!org.matsim.pt2matsim.tools.MiscUtils.collectionsShareMinOneStringEntry(link.getAllowedModes(), modesToKeep) && !usedTransitLinkIds.contains(link.getId())) { network.removeLink(link.getId()); linksRemoved++; } // only retain modes that are actually used else if(org.matsim.pt2matsim.tools.MiscUtils.collectionsShareMinOneStringEntry(link.getAllowedModes(), modesToKeep) && !usedTransitLinkIds.contains(link.getId())) { link.setAllowedModes(MiscUtils.getSharedSetStringEntries(link.getAllowedModes(), modesToKeep)); } } // removing nodes for(Node n : new HashSet<>(network.getNodes().values())) { if(n.getOutLinks().size() == 0 && n.getInLinks().size() == 0) { network.removeNode(n.getId()); } } log.info(" " + linksRemoved + " links removed"); }