RoutingStrategy.java (1662B)
1 package osm.routing; 2 3 import java.util.Collection; 4 import java.util.Map; 5 import java.util.stream.Collectors; 6 7 import osm.routing.RoutingGraph.Route; 8 9 /** 10 * Represents a routing strategy for finding the optimal route between two 11 * points on a graph. 12 * 13 * @param <N> The type of nodes in the graph. 14 * @param <E> The type of edges connecting the nodes. 15 */ 16 @FunctionalInterface 17 public interface RoutingStrategy<N extends RoutingNode<N>, E extends RoutingEdge<N>> { 18 19 /** 20 * Finds the optimal route between the start node and a collection of target 21 * nodes using the default offset value of 0. 22 * 23 * @param router The routing graph. 24 * @param targets The target nodes and their distances. 25 * @param start The starting node. 26 * @return A Route object representing the optimal route from the start to a 27 * target node. 28 */ 29 default Route<N> route(RoutingGraph<N, E> router, Collection<N> targets, N start, long offset) { 30 Map<N, Long> targetMap = targets.stream().collect(Collectors.toMap(k -> k, v -> 0L)); 31 return route(router, targetMap, start, offset); 32 } 33 34 /** 35 * Finds the optimal route between the start node and a collection of target 36 * nodes with a specified offset value. 37 * 38 * @param router The routing graph. 39 * @param targets The target nodes and their distances. 40 * @param start The starting node. 41 * @param offset The offset value. 42 * @return A Route object representing the optimal route from the start to a 43 * target node. 44 */ 45 Route<N> route(RoutingGraph<N, E> router, Map<N, Long> targets, N start, long offset); 46 }