Add minimumSpanningForestAlgorithm to Gruphi

This commit is contained in:
2021-09-05 22:45:15 +02:00
parent f1303fe37b
commit 6d4a8b26e6
3 changed files with 24 additions and 2 deletions

View File

@ -1,5 +1,6 @@
package de.oshgnacknak.gruphi; package de.oshgnacknak.gruphi;
import h07.algorithm.MinimumSpanningForestAlgorithm;
import h07.algorithm.ShortestPathsAlgorithm; import h07.algorithm.ShortestPathsAlgorithm;
import h07.graph.DirectedGraphFactory; import h07.graph.DirectedGraphFactory;
@ -38,4 +39,9 @@ public interface Gruphi {
* @return A {@link ShortestPathsAlgorithm} for the path finding * @return A {@link ShortestPathsAlgorithm} for the path finding
*/ */
ShortestPathsAlgorithm<Node, Double> getShortestPathsAlgorithm(); ShortestPathsAlgorithm<Node, Double> getShortestPathsAlgorithm();
/**
* @return A {@link MinimumSpanningForestAlgorithm} for the spanning tree calculation
*/
MinimumSpanningForestAlgorithm<Node, Double> getMinimumSpanningForestAlgorithm();
} }

View File

@ -1,5 +1,6 @@
package de.oshgnacknak.gruphi; package de.oshgnacknak.gruphi;
import h07.algorithm.MinimumSpanningForestAlgorithm;
import h07.algorithm.ShortestPathsAlgorithm; import h07.algorithm.ShortestPathsAlgorithm;
import h07.graph.DirectedGraphFactory; import h07.graph.DirectedGraphFactory;
@ -12,6 +13,7 @@ public class GruphiBuilder {
private BiPredicate<Node, Node> neighbourPredicate; private BiPredicate<Node, Node> neighbourPredicate;
private DirectedGraphFactory<Node, Double> directedGraphFactory; private DirectedGraphFactory<Node, Double> directedGraphFactory;
private ShortestPathsAlgorithm<Node, Double> shortestPathsAlgorithm; private ShortestPathsAlgorithm<Node, Double> shortestPathsAlgorithm;
private MinimumSpanningForestAlgorithm<Node, Double> minimumSpanningForestAlgorithm;
public GruphiBuilder setFrameDelay(Long frameDelay) { public GruphiBuilder setFrameDelay(Long frameDelay) {
this.frameDelay = frameDelay; this.frameDelay = frameDelay;
@ -43,7 +45,12 @@ public class GruphiBuilder {
return this; return this;
} }
public GruphiBuilder setMinimumSpanningForestAlgorithm(MinimumSpanningForestAlgorithm<Node, Double> minimumSpanningForestAlgorithm) {
this.minimumSpanningForestAlgorithm = minimumSpanningForestAlgorithm;
return this;
}
public GruphiImpl createGruphi() { public GruphiImpl createGruphi() {
return new GruphiImpl(frameDelay, velocity, gridSpacing, neighbourPredicate, directedGraphFactory, shortestPathsAlgorithm); return new GruphiImpl(frameDelay, velocity, gridSpacing, neighbourPredicate, directedGraphFactory, shortestPathsAlgorithm, minimumSpanningForestAlgorithm);
} }
} }

View File

@ -1,5 +1,6 @@
package de.oshgnacknak.gruphi; package de.oshgnacknak.gruphi;
import h07.algorithm.MinimumSpanningForestAlgorithm;
import h07.algorithm.ShortestPathsAlgorithm; import h07.algorithm.ShortestPathsAlgorithm;
import h07.graph.DirectedGraphFactory; import h07.graph.DirectedGraphFactory;
@ -24,17 +25,20 @@ public class GruphiImpl implements Gruphi {
private final ShortestPathsAlgorithm<Node, Double> shortestPathsAlgorithm; private final ShortestPathsAlgorithm<Node, Double> shortestPathsAlgorithm;
private final MinimumSpanningForestAlgorithm<Node, Double> minimumSpanningForestAlgorithm;
public GruphiImpl(Long frameDelay, public GruphiImpl(Long frameDelay,
Double velocity, Double velocity,
Double gridSpacing, Double gridSpacing,
BiPredicate<Node, Node> neighbourPredicate, BiPredicate<Node, Node> neighbourPredicate,
DirectedGraphFactory<Node, Double> directedGraphFactory, ShortestPathsAlgorithm<Node, Double> shortestPathsAlgorithm) { DirectedGraphFactory<Node, Double> directedGraphFactory, ShortestPathsAlgorithm<Node, Double> shortestPathsAlgorithm, MinimumSpanningForestAlgorithm<Node, Double> minimumSpanningForestAlgorithm) {
this.frameDelay = frameDelay == null ? DEFAULT_FRAME_DELAY : frameDelay; this.frameDelay = frameDelay == null ? DEFAULT_FRAME_DELAY : frameDelay;
this.velocity = velocity == null ? DEFAULT_VELOCITY : velocity; this.velocity = velocity == null ? DEFAULT_VELOCITY : velocity;
this.gridSpacing = gridSpacing == null ? DEFAULT_GRID_SPACING : gridSpacing; this.gridSpacing = gridSpacing == null ? DEFAULT_GRID_SPACING : gridSpacing;
this.neighbourPredicate = neighbourPredicate == null ? this::defaultAreNeighbours : neighbourPredicate; this.neighbourPredicate = neighbourPredicate == null ? this::defaultAreNeighbours : neighbourPredicate;
this.directedGraphFactory = Objects.requireNonNull(directedGraphFactory, "A directedGraphFactory must be set"); this.directedGraphFactory = Objects.requireNonNull(directedGraphFactory, "A directedGraphFactory must be set");
this.shortestPathsAlgorithm = shortestPathsAlgorithm; this.shortestPathsAlgorithm = shortestPathsAlgorithm;
this.minimumSpanningForestAlgorithm = minimumSpanningForestAlgorithm;
} }
private boolean defaultAreNeighbours(Node a, Node b) { private boolean defaultAreNeighbours(Node a, Node b) {
@ -70,4 +74,9 @@ public class GruphiImpl implements Gruphi {
public ShortestPathsAlgorithm<Node, Double> getShortestPathsAlgorithm() { public ShortestPathsAlgorithm<Node, Double> getShortestPathsAlgorithm() {
return shortestPathsAlgorithm; return shortestPathsAlgorithm;
} }
@Override
public MinimumSpanningForestAlgorithm<Node, Double> getMinimumSpanningForestAlgorithm() {
return minimumSpanningForestAlgorithm;
}
} }