MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / computePaths

Method computePaths

src/main/java/field/utility/Dijkstra.java:25–46  ·  view source on GitHub ↗
(t_vertex source)

Source from the content-addressed store, hash-verified

23 Map<t_vertex, Pair<t_vertex, t_edge>> previous = new HashMap<>();
24
25 public void computePaths(t_vertex source) {
26 minDistance.put(source, 0f);
27 PriorityQueue<t_vertex> vertexQueue = new PriorityQueue<>((o1, o2) -> Float.compare(minDistance.computeIfAbsent(o1, (k) -> Float.POSITIVE_INFINITY), minDistance.computeIfAbsent(o2, (k) -> Float.POSITIVE_INFINITY)));
28
29 vertexQueue.add(source);
30
31 while (!vertexQueue.isEmpty()) {
32 t_vertex u = vertexQueue.poll();
33 for (t_edge e : edgesFor.apply(u)) {
34 t_vertex v = output.apply(e);
35 double weight = length.apply(e).doubleValue();
36 double min = minDistance.computeIfAbsent(u, (k) -> Float.POSITIVE_INFINITY);
37 double distanceThroughU = min + weight;
38 if (distanceThroughU < minDistance.computeIfAbsent(v, (k) -> Float.POSITIVE_INFINITY)) {
39 vertexQueue.remove(v);
40 minDistance.put(v, (float) distanceThroughU);
41 previous.put(v, new Pair<>(u, e));
42 vertexQueue.add(v);
43 }
44 }
45 }
46 }
47
48 public List<Pair<t_vertex, t_edge>> getShortestPathTo(t_vertex target) {
49 if (!previous.containsKey(target)) return null;

Callers 1

getConversionMethod · 0.95

Calls 8

computeIfAbsentMethod · 0.80
applyMethod · 0.65
putMethod · 0.45
compareMethod · 0.45
addMethod · 0.45
isEmptyMethod · 0.45
pollMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected