Skip to content

Commit

Permalink
Move estimateWaitingTime(List<PlanElement> elements) to PTWaitingTime…
Browse files Browse the repository at this point in the history
…Estimator interface
  • Loading branch information
marecabo committed Mar 18, 2024
1 parent 95bdede commit b89ad74
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand All @@ -11,5 +16,19 @@
* @author sebhoerl
*/
public interface PTWaitingTimeEstimator {

double estimateWaitingTime(double departureTime, TransitPassengerRoute route);

default double estimateWaitingTime(List<? extends PlanElement> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,23 +52,6 @@ private Tuple<Id<TransitLine>, Id<TransitRoute>> createId(TransitLine transitLin
return new Tuple<>(transitLine.getId(), transitRoute.getId());
}

public double estimateWaitingTime(List<? extends PlanElement> 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());
Expand Down

0 comments on commit b89ad74

Please sign in to comment.