From b087d76c7089ae35cc54924a2c6e50d64b639649 Mon Sep 17 00:00:00 2001 From: simei94 <67737999+simei94@users.noreply.github.com> Date: Tue, 13 Feb 2024 04:52:04 -0600 Subject: [PATCH] add run param option for input facilities (#3106) Co-authored-by: rakow --- .../prepare/population/XYToLinks.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/contribs/application/src/main/java/org/matsim/application/prepare/population/XYToLinks.java b/contribs/application/src/main/java/org/matsim/application/prepare/population/XYToLinks.java index ec9ada3bad5..83aefa033e0 100644 --- a/contribs/application/src/main/java/org/matsim/application/prepare/population/XYToLinks.java +++ b/contribs/application/src/main/java/org/matsim/application/prepare/population/XYToLinks.java @@ -1,15 +1,20 @@ package org.matsim.application.prepare.population; +import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.TransportMode; import org.matsim.api.core.v01.network.Network; import org.matsim.api.core.v01.population.Population; import org.matsim.application.MATSimAppCommand; +import org.matsim.core.config.ConfigUtils; import org.matsim.core.network.NetworkUtils; import org.matsim.core.network.algorithms.TransportModeNetworkFilter; import org.matsim.core.population.PopulationUtils; import org.matsim.core.population.algorithms.ParallelPersonAlgorithmUtils; import org.matsim.core.population.algorithms.XY2Links; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.facilities.ActivityFacilities; import org.matsim.facilities.FacilitiesUtils; +import org.matsim.facilities.MatsimFacilitiesReader; import picocli.CommandLine; import java.nio.file.Path; @@ -29,6 +34,9 @@ public class XYToLinks implements MATSimAppCommand { @CommandLine.Option(names = "--car-only", description = "Convert to car-only network", defaultValue = "false") private boolean carOnly; + @CommandLine.Option(names = "--facilities", description = "Input facilities. Necessary if activities already were assigned facility ids.") + private Path inputFacilities; + @Override public Integer call() throws Exception { @@ -42,7 +50,16 @@ public Integer call() throws Exception { network = carOnlyNetwork; } - XY2Links algo = new XY2Links(network, FacilitiesUtils.createActivityFacilities()); + ActivityFacilities facilities = FacilitiesUtils.createActivityFacilities(); + + if (inputFacilities != null) { + Scenario scenario = ScenarioUtils.loadScenario(ConfigUtils.createConfig()); + MatsimFacilitiesReader reader = new MatsimFacilitiesReader(scenario); + reader.parse(inputFacilities.toUri().toURL()); + facilities = scenario.getActivityFacilities(); + } + + XY2Links algo = new XY2Links(network, facilities); Population population = PopulationUtils.readPopulation(input.toString());