Skip to content

Commit

Permalink
Merge pull request #3174 from marecabo/interface-PTWaitingTimeEstimator
Browse files Browse the repository at this point in the history
Move method to PTWaitingTimeEstimator interface
  • Loading branch information
marecabo authored Mar 18, 2024
2 parents 4180bcd + 60ca603 commit fd6f562
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand All @@ -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<? extends PlanElement> elements) {
return 0.0;
}

}
Original file line number Diff line number Diff line change
@@ -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;

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

double estimateWaitingTime(double departureTime, TransitPassengerRoute route);

double estimateWaitingTime(List<? extends PlanElement> elements);

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;
Expand Down Expand Up @@ -54,17 +55,14 @@ private Tuple<Id<TransitLine>, Id<TransitRoute>> createId(TransitLine transitLin
return new Tuple<>(transitLine.getId(), transitRoute.getId());
}

@Override
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);
}
if (element instanceof Leg leg && leg.getMode().equals(TransportMode.pt)) {
TransitPassengerRoute route = (TransitPassengerRoute) leg.getRoute();
totalWaitingTime += this.estimateWaitingTime(leg.getDepartureTime().seconds(), route);
}
}

Expand Down

0 comments on commit fd6f562

Please sign in to comment.