misc/persolijn

osm-routing/src/main/java/osm/planner/Planner.java in master
Repositories | Summary | Log | Files

Planner.java (1269B) download


 1package osm.planner;
 2
 3import java.util.Map;
 4
 5import osm.common.Edge;
 6import osm.message.Node;
 7import osm.routing.RoutingGraph;
 8import 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 */
16public 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}