From bf6de834aa86b6e0068010c616244e308765d896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=B6rl?= Date: Tue, 5 Dec 2023 08:23:52 +0100 Subject: [PATCH] fix: Handle only-walk trips in initial routing (#142) * fix: Handle only-walk trips in initial routing * update to latest code base * update changelog --- CHANGELOG.md | 4 ++- .../core/scenario/routing/PlanRouter.java | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b151a0381..1827423ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,9 @@ This change log is written in descending order. Changes that happen after versio included in the (note yet determined) next version number. **Development version** - + +- Convert initial-routing only-walk legs to actual walk (instead of transit) +- Don't put activities on motorway/trunk/link in the network - Updated to MATSim 14 - Isolated the mode choice model in a standalone runnable script - Fixed LegIndex count between iterations in legs analysis diff --git a/core/src/main/java/org/eqasim/core/scenario/routing/PlanRouter.java b/core/src/main/java/org/eqasim/core/scenario/routing/PlanRouter.java index bff821f49..c66f9a082 100644 --- a/core/src/main/java/org/eqasim/core/scenario/routing/PlanRouter.java +++ b/core/src/main/java/org/eqasim/core/scenario/routing/PlanRouter.java @@ -3,7 +3,9 @@ import java.util.List; import java.util.Set; +import org.matsim.api.core.v01.TransportMode; import org.matsim.api.core.v01.population.Leg; +import org.matsim.api.core.v01.population.Person; import org.matsim.api.core.v01.population.Plan; import org.matsim.api.core.v01.population.PlanElement; import org.matsim.core.router.TripRouter; @@ -13,6 +15,7 @@ import org.matsim.facilities.ActivityFacilities; import org.matsim.facilities.FacilitiesUtils; import org.matsim.facilities.Facility; +import org.matsim.utils.objectattributes.attributable.Attributes; import com.google.inject.Inject; @@ -55,9 +58,31 @@ public void run(Plan plan, boolean replaceExistingRoutes, Set modes) { List newElements = tripRouter.calcRoute(mainMode, fromFacility, toFacility, departureTime.seconds(), plan.getPerson(), trip.getTripAttributes()); + // Fix in case we have a transit trip that is only walk + newElements = fixOnlyWalk(mainMode, fromFacility, toFacility, departureTime.seconds(), + plan.getPerson(), newElements, trip.getTripAttributes()); + TripRouter.insertTrip(plan, trip.getOriginActivity(), newElements, trip.getDestinationActivity()); } } } } + + private List fixOnlyWalk(String mainMode, Facility fromFacility, Facility toFacility, + double departureTime, Person person, List elements, Attributes attributes) { + // No need to fix if already walk + if (mainMode.equals(TransportMode.walk)) { + return elements; + } + + // No need to fix if we have a non-walk leg + for (Leg leg : TripStructureUtils.getLegs(elements)) { + if (!leg.getMode().equals(TransportMode.walk)) { + return elements; + } + } + + // We have only walk legs + return tripRouter.calcRoute(TransportMode.walk, fromFacility, toFacility, departureTime, person, attributes); + } }