From b89ad74a799c2eb37b1af14d09796e5c2eb66731 Mon Sep 17 00:00:00 2001 From: marecabo <23156476+marecabo@users.noreply.github.com> Date: Mon, 18 Mar 2024 12:28:36 +0100 Subject: [PATCH 1/2] Move estimateWaitingTime(List elements) to PTWaitingTimeEstimator interface --- .../utils/PTWaitingTimeEstimator.java | 19 +++++++++++++++++++ .../utils/ScheduleWaitingTimeEstimator.java | 19 ------------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/contribs/discrete_mode_choice/src/main/java/org/matsim/contribs/discrete_mode_choice/components/utils/PTWaitingTimeEstimator.java b/contribs/discrete_mode_choice/src/main/java/org/matsim/contribs/discrete_mode_choice/components/utils/PTWaitingTimeEstimator.java index 2b4da256f0b..a253763488a 100644 --- a/contribs/discrete_mode_choice/src/main/java/org/matsim/contribs/discrete_mode_choice/components/utils/PTWaitingTimeEstimator.java +++ b/contribs/discrete_mode_choice/src/main/java/org/matsim/contribs/discrete_mode_choice/components/utils/PTWaitingTimeEstimator.java @@ -1,5 +1,10 @@ package org.matsim.contribs.discrete_mode_choice.components.utils; +import java.util.List; + +import org.matsim.api.core.v01.TransportMode; +import org.matsim.api.core.v01.population.Leg; +import org.matsim.api.core.v01.population.PlanElement; import org.matsim.pt.routes.TransitPassengerRoute; /** @@ -11,5 +16,19 @@ * @author sebhoerl */ public interface PTWaitingTimeEstimator { + double estimateWaitingTime(double departureTime, TransitPassengerRoute route); + + default double estimateWaitingTime(List elements) { + double totalWaitingTime = 0.0; + + for (PlanElement element : elements) { + if (element instanceof Leg leg && leg.getMode().equals(TransportMode.pt)) { + TransitPassengerRoute route = (TransitPassengerRoute) leg.getRoute(); + totalWaitingTime += this.estimateWaitingTime(leg.getDepartureTime().seconds(), route); + } + } + + return totalWaitingTime; + } } diff --git a/contribs/discrete_mode_choice/src/main/java/org/matsim/contribs/discrete_mode_choice/components/utils/ScheduleWaitingTimeEstimator.java b/contribs/discrete_mode_choice/src/main/java/org/matsim/contribs/discrete_mode_choice/components/utils/ScheduleWaitingTimeEstimator.java index 2ab5bfe10ca..78e9d45ee97 100644 --- a/contribs/discrete_mode_choice/src/main/java/org/matsim/contribs/discrete_mode_choice/components/utils/ScheduleWaitingTimeEstimator.java +++ b/contribs/discrete_mode_choice/src/main/java/org/matsim/contribs/discrete_mode_choice/components/utils/ScheduleWaitingTimeEstimator.java @@ -8,8 +8,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.population.Leg; -import org.matsim.api.core.v01.population.PlanElement; import org.matsim.core.utils.collections.Tuple; import org.matsim.core.utils.misc.OptionalTime; import org.matsim.core.utils.misc.Time; @@ -54,23 +52,6 @@ private Tuple, Id> createId(TransitLine transitLin return new Tuple<>(transitLine.getId(), transitRoute.getId()); } - public double estimateWaitingTime(List elements) { - double totalWaitingTime = 0.0; - - for (PlanElement element : elements) { - if (element instanceof Leg) { - Leg leg = (Leg) element; - - if (leg.getMode().equals("pt")) { - TransitPassengerRoute route = (TransitPassengerRoute) leg.getRoute(); - totalWaitingTime += estimateWaitingTime(leg.getDepartureTime().seconds(), route); - } - } - } - - return totalWaitingTime; - } - @Override public double estimateWaitingTime(double agentDepartureTime, TransitPassengerRoute route) { TransitLine transitLine = transitSchedule.getTransitLines().get(route.getLineId()); From e1ba68d7b9d8a70ae14dae4f7d34bd8dbf322643 Mon Sep 17 00:00:00 2001 From: marecabo <23156476+marecabo@users.noreply.github.com> Date: Mon, 18 Mar 2024 12:44:56 +0100 Subject: [PATCH 2/2] Do not use default method in interface --- .../utils/NullWaitingTimeEstimator.java | 10 ++++++++++ .../utils/PTWaitingTimeEstimator.java | 14 +------------- .../utils/ScheduleWaitingTimeEstimator.java | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/contribs/discrete_mode_choice/src/main/java/org/matsim/contribs/discrete_mode_choice/components/utils/NullWaitingTimeEstimator.java b/contribs/discrete_mode_choice/src/main/java/org/matsim/contribs/discrete_mode_choice/components/utils/NullWaitingTimeEstimator.java index 445451713ca..e003a9f09e9 100644 --- a/contribs/discrete_mode_choice/src/main/java/org/matsim/contribs/discrete_mode_choice/components/utils/NullWaitingTimeEstimator.java +++ b/contribs/discrete_mode_choice/src/main/java/org/matsim/contribs/discrete_mode_choice/components/utils/NullWaitingTimeEstimator.java @@ -1,5 +1,8 @@ package org.matsim.contribs.discrete_mode_choice.components.utils; +import java.util.List; + +import org.matsim.api.core.v01.population.PlanElement; import org.matsim.pt.routes.TransitPassengerRoute; /** @@ -9,8 +12,15 @@ * @author sebhoerl */ public class NullWaitingTimeEstimator implements PTWaitingTimeEstimator { + @Override public double estimateWaitingTime(double agentDepartureTime, TransitPassengerRoute route) { return 0.0; } + + @Override + public double estimateWaitingTime(List elements) { + return 0.0; + } + } diff --git a/contribs/discrete_mode_choice/src/main/java/org/matsim/contribs/discrete_mode_choice/components/utils/PTWaitingTimeEstimator.java b/contribs/discrete_mode_choice/src/main/java/org/matsim/contribs/discrete_mode_choice/components/utils/PTWaitingTimeEstimator.java index a253763488a..25804cddb95 100644 --- a/contribs/discrete_mode_choice/src/main/java/org/matsim/contribs/discrete_mode_choice/components/utils/PTWaitingTimeEstimator.java +++ b/contribs/discrete_mode_choice/src/main/java/org/matsim/contribs/discrete_mode_choice/components/utils/PTWaitingTimeEstimator.java @@ -2,8 +2,6 @@ import java.util.List; -import org.matsim.api.core.v01.TransportMode; -import org.matsim.api.core.v01.population.Leg; import org.matsim.api.core.v01.population.PlanElement; import org.matsim.pt.routes.TransitPassengerRoute; @@ -19,16 +17,6 @@ public interface PTWaitingTimeEstimator { double estimateWaitingTime(double departureTime, TransitPassengerRoute route); - default double estimateWaitingTime(List elements) { - double totalWaitingTime = 0.0; + double estimateWaitingTime(List elements); - for (PlanElement element : elements) { - if (element instanceof Leg leg && leg.getMode().equals(TransportMode.pt)) { - TransitPassengerRoute route = (TransitPassengerRoute) leg.getRoute(); - totalWaitingTime += this.estimateWaitingTime(leg.getDepartureTime().seconds(), route); - } - } - - return totalWaitingTime; - } } diff --git a/contribs/discrete_mode_choice/src/main/java/org/matsim/contribs/discrete_mode_choice/components/utils/ScheduleWaitingTimeEstimator.java b/contribs/discrete_mode_choice/src/main/java/org/matsim/contribs/discrete_mode_choice/components/utils/ScheduleWaitingTimeEstimator.java index 78e9d45ee97..6fc60d7ad73 100644 --- a/contribs/discrete_mode_choice/src/main/java/org/matsim/contribs/discrete_mode_choice/components/utils/ScheduleWaitingTimeEstimator.java +++ b/contribs/discrete_mode_choice/src/main/java/org/matsim/contribs/discrete_mode_choice/components/utils/ScheduleWaitingTimeEstimator.java @@ -8,6 +8,9 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.TransportMode; +import org.matsim.api.core.v01.population.Leg; +import org.matsim.api.core.v01.population.PlanElement; import org.matsim.core.utils.collections.Tuple; import org.matsim.core.utils.misc.OptionalTime; import org.matsim.core.utils.misc.Time; @@ -52,6 +55,20 @@ private Tuple, Id> createId(TransitLine transitLin return new Tuple<>(transitLine.getId(), transitRoute.getId()); } + @Override + public double estimateWaitingTime(List elements) { + double totalWaitingTime = 0.0; + + for (PlanElement element : elements) { + if (element instanceof Leg leg && leg.getMode().equals(TransportMode.pt)) { + TransitPassengerRoute route = (TransitPassengerRoute) leg.getRoute(); + totalWaitingTime += this.estimateWaitingTime(leg.getDepartureTime().seconds(), route); + } + } + + return totalWaitingTime; + } + @Override public double estimateWaitingTime(double agentDepartureTime, TransitPassengerRoute route) { TransitLine transitLine = transitSchedule.getTransitLines().get(route.getLineId());