Planner.java (1269B)
1 package osm.planner; 2 3 import java.util.Map; 4 5 import osm.common.Edge; 6 import osm.message.Node; 7 import osm.routing.RoutingGraph; 8 import osm.routing.entity.Passenger; 9 10 /** 11 * A concrete implementation of the base planner for a graph with nodes of type 12 * {@link Node} and edges of type {@link Edge}. 13 * This implementation calculates the path score based on the average passenger 14 * distance and the total length of the route. 15 */ 16 public class Planner extends BasePlanner<Node, Edge> { 17 18 /** 19 * Calculates the path score based on the specified routing graph, route length, 20 * and passenger distances. 21 * 22 * @param graph The routing graph. 23 * @param length The length of the calculated route. 24 * @param passengers A map containing passengers and their respective distances. 25 * @return The calculated path score, considering the average passenger distance 26 * and the total route length. 27 */ 28 @Override 29 protected long getPathScore(RoutingGraph<Node, Edge> graph, long length, Map<Passenger<Node>, Long> passengers) { 30 return Math.round( 31 passengers.values().stream().mapToDouble(v -> (double) v).sum() 32 / passengers.values().size()) 33 + length; 34 } 35 }