Skip to content

Commit

Permalink
fix: Handle only-walk trips in initial routing (#142)
Browse files Browse the repository at this point in the history
* fix: Handle only-walk trips in initial routing

* update to latest code base

* update changelog
  • Loading branch information
sebhoerl authored Dec 5, 2023
1 parent c2bc9a4 commit bf6de83
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -55,9 +58,31 @@ public void run(Plan plan, boolean replaceExistingRoutes, Set<String> modes) {
List<? extends PlanElement> 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<? extends PlanElement> fixOnlyWalk(String mainMode, Facility fromFacility, Facility toFacility,
double departureTime, Person person, List<? extends PlanElement> 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);
}
}

0 comments on commit bf6de83

Please sign in to comment.