diff --git a/src/main/java/de/oshgnacknak/gruphi/Gruphi.java b/src/main/java/de/oshgnacknak/gruphi/Gruphi.java index 383495e..35ea981 100644 --- a/src/main/java/de/oshgnacknak/gruphi/Gruphi.java +++ b/src/main/java/de/oshgnacknak/gruphi/Gruphi.java @@ -1,5 +1,6 @@ package de.oshgnacknak.gruphi; +import h07.algorithm.MinimumSpanningForestAlgorithm; import h07.algorithm.ShortestPathsAlgorithm; import h07.graph.DirectedGraphFactory; @@ -38,4 +39,9 @@ public interface Gruphi { * @return A {@link ShortestPathsAlgorithm} for the path finding */ ShortestPathsAlgorithm getShortestPathsAlgorithm(); + + /** + * @return A {@link MinimumSpanningForestAlgorithm} for the spanning tree calculation + */ + MinimumSpanningForestAlgorithm getMinimumSpanningForestAlgorithm(); } diff --git a/src/main/java/de/oshgnacknak/gruphi/GruphiBuilder.java b/src/main/java/de/oshgnacknak/gruphi/GruphiBuilder.java index eed3b66..4b60364 100644 --- a/src/main/java/de/oshgnacknak/gruphi/GruphiBuilder.java +++ b/src/main/java/de/oshgnacknak/gruphi/GruphiBuilder.java @@ -1,5 +1,6 @@ package de.oshgnacknak.gruphi; +import h07.algorithm.MinimumSpanningForestAlgorithm; import h07.algorithm.ShortestPathsAlgorithm; import h07.graph.DirectedGraphFactory; @@ -12,6 +13,7 @@ public class GruphiBuilder { private BiPredicate neighbourPredicate; private DirectedGraphFactory directedGraphFactory; private ShortestPathsAlgorithm shortestPathsAlgorithm; + private MinimumSpanningForestAlgorithm minimumSpanningForestAlgorithm; public GruphiBuilder setFrameDelay(Long frameDelay) { this.frameDelay = frameDelay; @@ -43,7 +45,12 @@ public class GruphiBuilder { return this; } + public GruphiBuilder setMinimumSpanningForestAlgorithm(MinimumSpanningForestAlgorithm minimumSpanningForestAlgorithm) { + this.minimumSpanningForestAlgorithm = minimumSpanningForestAlgorithm; + return this; + } + public GruphiImpl createGruphi() { - return new GruphiImpl(frameDelay, velocity, gridSpacing, neighbourPredicate, directedGraphFactory, shortestPathsAlgorithm); + return new GruphiImpl(frameDelay, velocity, gridSpacing, neighbourPredicate, directedGraphFactory, shortestPathsAlgorithm, minimumSpanningForestAlgorithm); } } \ No newline at end of file diff --git a/src/main/java/de/oshgnacknak/gruphi/GruphiImpl.java b/src/main/java/de/oshgnacknak/gruphi/GruphiImpl.java index 6cd8bce..c360a2c 100644 --- a/src/main/java/de/oshgnacknak/gruphi/GruphiImpl.java +++ b/src/main/java/de/oshgnacknak/gruphi/GruphiImpl.java @@ -1,5 +1,6 @@ package de.oshgnacknak.gruphi; +import h07.algorithm.MinimumSpanningForestAlgorithm; import h07.algorithm.ShortestPathsAlgorithm; import h07.graph.DirectedGraphFactory; @@ -24,17 +25,20 @@ public class GruphiImpl implements Gruphi { private final ShortestPathsAlgorithm shortestPathsAlgorithm; + private final MinimumSpanningForestAlgorithm minimumSpanningForestAlgorithm; + public GruphiImpl(Long frameDelay, Double velocity, Double gridSpacing, BiPredicate neighbourPredicate, - DirectedGraphFactory directedGraphFactory, ShortestPathsAlgorithm shortestPathsAlgorithm) { + DirectedGraphFactory directedGraphFactory, ShortestPathsAlgorithm shortestPathsAlgorithm, MinimumSpanningForestAlgorithm minimumSpanningForestAlgorithm) { this.frameDelay = frameDelay == null ? DEFAULT_FRAME_DELAY : frameDelay; this.velocity = velocity == null ? DEFAULT_VELOCITY : velocity; this.gridSpacing = gridSpacing == null ? DEFAULT_GRID_SPACING : gridSpacing; this.neighbourPredicate = neighbourPredicate == null ? this::defaultAreNeighbours : neighbourPredicate; this.directedGraphFactory = Objects.requireNonNull(directedGraphFactory, "A directedGraphFactory must be set"); this.shortestPathsAlgorithm = shortestPathsAlgorithm; + this.minimumSpanningForestAlgorithm = minimumSpanningForestAlgorithm; } private boolean defaultAreNeighbours(Node a, Node b) { @@ -70,4 +74,9 @@ public class GruphiImpl implements Gruphi { public ShortestPathsAlgorithm getShortestPathsAlgorithm() { return shortestPathsAlgorithm; } + + @Override + public MinimumSpanningForestAlgorithm getMinimumSpanningForestAlgorithm() { + return minimumSpanningForestAlgorithm; + } }