Skip to content

Commit

Permalink
Merge pull request #3351 from matsim-org/skim-matrices-with-custom-tr…
Browse files Browse the repository at this point in the history
…avel-time-object

Allow custom travel time objects in CalculateSkimMatrices
  • Loading branch information
steffenaxer authored Jul 4, 2024
2 parents 7fc08d6 + eba4326 commit cb853ee
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
import java.util.function.BiPredicate;
import java.util.function.Predicate;
import java.util.function.ToDoubleFunction;

import javax.annotation.Nullable;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.geotools.api.feature.simple.SimpleFeature;
Expand Down Expand Up @@ -350,8 +353,8 @@ public final FloatMatrix<String> calculateBeelineMatrix() {
return BeelineDistanceMatrix.calculateBeelineDistanceMatrix(this.coordsPerZone.keySet(), coordsPerZone, numberOfThreads);
}

public final void calculateAndWriteNetworkMatrices(String networkFilename, String eventsFilename, double[] times, Config config, String outputPrefix, Predicate<Link> xy2linksPredicate)
throws IOException {
public final void calculateAndWriteNetworkMatrices(String networkFilename, @Nullable String eventsFilename,
double[] times, Config config, String outputPrefix, Predicate<Link> xy2linksPredicate) throws IOException {
String prefix = outputPrefix == null ? "" : outputPrefix;
var netIndicators = prepareAndCalculateNetworkMatrices(networkFilename, eventsFilename, times, config, xy2linksPredicate);
writeNetworkMatricesAsCSV(netIndicators, prefix);
Expand All @@ -363,7 +366,8 @@ public final void writeNetworkMatricesAsCSV(NetworkIndicators<String> netIndicat
FloatMatrixIO.writeAsCSV(netIndicators.distanceMatrix, outputDirectory + "/" + prefix + CAR_DISTANCES_FILENAME);
}

public final NetworkIndicators<String> prepareAndCalculateNetworkMatrices(String networkFilename, String eventsFilename, double[] times, Config config, Predicate<Link> xy2linksPredicate) {
public final NetworkIndicators<String> prepareAndCalculateNetworkMatrices(String networkFilename,
@Nullable String eventsFilename, double[] times, Config config, Predicate<Link> xy2linksPredicate) {
Scenario scenario = ScenarioUtils.createScenario(config);
log.info("loading network from " + networkFilename);
new MatsimNetworkReader(scenario.getNetwork()).readFile(networkFilename);
Expand All @@ -382,11 +386,16 @@ public final NetworkIndicators<String> prepareAndCalculateNetworkMatrices(String
log.info("No events specified. Travel Times will be calculated with free speed travel times.");
}

return prepareAndCalculateNetworkMatrices(scenario.getNetwork(), tt, times, config, xy2linksPredicate);
}

public final NetworkIndicators<String> prepareAndCalculateNetworkMatrices(Network network, TravelTime tt,
double[] times, Config config, Predicate<Link> xy2linksPredicate) {
TravelDisutility td = new OnlyTimeDependentTravelDisutility(tt);

log.info("extracting car-only network");
final Network carNetwork = NetworkUtils.createNetwork(config);
new TransportModeNetworkFilter(scenario.getNetwork()).filter(carNetwork, Collections.singleton(TransportMode.car));
new TransportModeNetworkFilter(network).filter(carNetwork, Collections.singleton(TransportMode.car));

log.info("filter car-only network for assigning links to locations");
final Network xy2linksNetwork = extractXy2LinksNetwork(carNetwork, xy2linksPredicate, config);
Expand Down

0 comments on commit cb853ee

Please sign in to comment.