Skip to content

Commit

Permalink
add functionality to use mode filtered network
Browse files Browse the repository at this point in the history
  • Loading branch information
simei94 committed Sep 1, 2022
1 parent 6b7ec8d commit 72528b6
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.network.NetworkUtils;
import org.matsim.core.network.algorithms.TransportModeNetworkFilter;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.core.utils.geometry.CoordUtils;
import org.matsim.core.utils.geometry.geotools.MGC;
Expand All @@ -20,7 +21,9 @@
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

@CommandLine.Command(
name = "create-drt-stops",
Expand All @@ -37,6 +40,9 @@ public class CreateDrtStopsFromNetwork implements MATSimAppCommand {
private String mode;
// mode = "drt", "av" or other specific drt operator mode

@CommandLine.Option(names = "--modeFilteredNetwork", defaultValue = "false", description = "Use mode filtered network for stops generation")
private boolean modeFilteredNetwork;

@CommandLine.Option(names = "--min-distance", description = "minimal distance between two stops in m", defaultValue = "100.")
private double minDistance;

Expand Down Expand Up @@ -67,6 +73,20 @@ public Integer call() throws Exception {
return 2;
}

if(modeFilteredNetwork) {
Network filteredNetwork = NetworkUtils.createNetwork();
Set<String> modes = new HashSet<>();
modes.add(mode);

TransportModeNetworkFilter filter = new TransportModeNetworkFilter(network);
filter.filter(filteredNetwork, modes);

network = filteredNetwork;

log.info("Using a network filtered by mode " + mode + ". " +
"If you do not want to use the filtered network do not use the option --modeFilteredNetwork.");
}

for(Node node : network.getNodes().values()) {
//we dont want pt nodes included as pt has a separate network + no dead ends
if(MGC.coord2Point(node.getCoord()).within(drtServiceArea) && (node.getInLinks().size() + node.getOutLinks().size() > 2)
Expand Down

0 comments on commit 72528b6

Please sign in to comment.