All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentripplanner.routing.algorithm.filterchain.deletionflagger.TransitGeneralizedCostFilter Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
package org.opentripplanner.routing.algorithm.filterchain.deletionflagger;

import java.util.stream.Collectors;
import org.opentripplanner.model.plan.Itinerary;

import java.util.List;
import java.util.OptionalDouble;
import java.util.function.DoubleFunction;

/**
 * This filter remove all transit results which have a generalized-cost higher than
 * the max-limit computed by the {@link #costLimitFunction}.
 * 

* @see org.opentripplanner.routing.api.request.ItineraryFilterParameters#transitGeneralizedCostLimit */ public class TransitGeneralizedCostFilter implements ItineraryDeletionFlagger { private final DoubleFunction costLimitFunction; public TransitGeneralizedCostFilter(DoubleFunction costLimitFunction) { this.costLimitFunction = costLimitFunction; } @Override public String name() { return "transit-cost-filter"; } @Override public List getFlaggedItineraries(List itineraries) { OptionalDouble minGeneralizedCost = itineraries .stream() .filter(Itinerary::hasTransit) .mapToDouble(it -> it.generalizedCost) .min(); if(minGeneralizedCost.isEmpty()) { return List.of(); } final double maxLimit = costLimitFunction.apply(minGeneralizedCost.getAsDouble()); return itineraries.stream() .filter( it -> it.hasTransit() && it.generalizedCost > maxLimit) .collect(Collectors.toList()); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy