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

org.opentripplanner.astar.strategy.MaxCountSkipEdgeStrategy Maven / Gradle / Ivy

The newest version!
package org.opentripplanner.astar.strategy;

import java.util.function.Predicate;
import org.opentripplanner.astar.spi.AStarEdge;
import org.opentripplanner.astar.spi.AStarState;
import org.opentripplanner.astar.spi.SkipEdgeStrategy;

/**
 * Skips edges when the specified number of desired vertices have been visited.
 */
public class MaxCountSkipEdgeStrategy<
  State extends AStarState, Edge extends AStarEdge
>
  implements SkipEdgeStrategy {

  private final int maxCount;
  private final Predicate shouldIncreaseCount;

  private int visited;

  public MaxCountSkipEdgeStrategy(int count, Predicate shouldIncreaseCount) {
    this.maxCount = count;
    this.shouldIncreaseCount = shouldIncreaseCount;
    this.visited = 0;
  }

  @Override
  public boolean shouldSkipEdge(State current, Edge edge) {
    if (shouldIncreaseCount.test(current)) {
      visited++;
    }
    return visited > maxCount;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy