Skip to content

Commit

Permalink
configurable crs for filter agent class
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Aug 8, 2024
1 parent 89ea146 commit 0b10118
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/main/java/org/matsim/prepare/FilterRelevantAgents.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.matsim.api.core.v01.population.Plan;
import org.matsim.api.core.v01.population.Population;
import org.matsim.application.MATSimAppCommand;
import org.matsim.application.options.CrsOptions;
import org.matsim.application.options.ShpOptions;
import org.matsim.core.network.NetworkUtils;
import org.matsim.core.network.algorithms.TransportModeNetworkFilter;
Expand Down Expand Up @@ -41,8 +42,8 @@


@CommandLine.Command(
name = "filter-relevant-agents",
description = "Filter agents that have any activities or routes within the shp file."
name = "filter-relevant-agents",
description = "Filter agents that have any activities or routes within the shp file."
)
public class FilterRelevantAgents implements MATSimAppCommand, PersonAlgorithm {

Expand All @@ -63,6 +64,9 @@ public class FilterRelevantAgents implements MATSimAppCommand, PersonAlgorithm {
@CommandLine.Mixin
private ShpOptions shp;

@CommandLine.Mixin
private CrsOptions crs = new CrsOptions(OpenBerlinScenario.CRS);

private ActivityFacilities facilities;
private Network network;
private CoordinateTransformation ct;
Expand All @@ -75,6 +79,16 @@ public static void main(String[] args) {
new FilterRelevantAgents().execute(args);
}

private static LeastCostPathCalculator createRouter(Network network) {

FreeSpeedTravelTime travelTime = new FreeSpeedTravelTime();
LeastCostPathCalculatorFactory factory = new SpeedyALTFactory();

OnlyTimeDependentTravelDisutility travelDisutility = new OnlyTimeDependentTravelDisutility(travelTime);

return factory.createPathCalculator(network, travelDisutility, travelTime);
}

@Override
public Integer call() throws Exception {

Expand All @@ -89,11 +103,10 @@ public Integer call() throws Exception {
filter.filter(network, Set.of(TransportMode.car));

geometry = shp.getGeometry();
ct = shp.createTransformation(OpenBerlinScenario.CRS);
ct = shp.createTransformation(crs.getInputCRS());

facilities = FacilitiesUtils.createActivityFacilities();
new MatsimFacilitiesReader(OpenBerlinScenario.CRS, OpenBerlinScenario.CRS, facilities)
.readFile(facilityPath.toString());
new MatsimFacilitiesReader(crs.getInputCRS(), crs.getInputCRS(), facilities).readFile(facilityPath.toString());

ctxs = ThreadLocal.withInitial(() -> this.createRouter(network));
toRemove = ConcurrentHashMap.newKeySet();
Expand Down Expand Up @@ -174,14 +187,4 @@ private Coord getCoordinate(Activity act) {

return coord;
}

private static LeastCostPathCalculator createRouter(Network network) {

FreeSpeedTravelTime travelTime = new FreeSpeedTravelTime();
LeastCostPathCalculatorFactory factory = new SpeedyALTFactory();

OnlyTimeDependentTravelDisutility travelDisutility = new OnlyTimeDependentTravelDisutility(travelTime);

return factory.createPathCalculator(network, travelDisutility, travelTime);
}
}

0 comments on commit 0b10118

Please sign in to comment.