Add ShortestPathAlgorithm to Gruphi
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
package de.oshgnacknak.gruphi;
|
package de.oshgnacknak.gruphi;
|
||||||
|
|
||||||
|
import h07.algorithm.ShortestPathsAlgorithm;
|
||||||
import h07.graph.DirectedGraphFactory;
|
import h07.graph.DirectedGraphFactory;
|
||||||
|
|
||||||
import java.util.function.BiPredicate;
|
import java.util.function.BiPredicate;
|
||||||
@ -32,4 +33,9 @@ public interface Gruphi {
|
|||||||
* @return A {@link DirectedGraphFactory} to create the initial {@link h07.graph.DirectedGraph}
|
* @return A {@link DirectedGraphFactory} to create the initial {@link h07.graph.DirectedGraph}
|
||||||
*/
|
*/
|
||||||
DirectedGraphFactory<Node, Double> getDirectedGraphFactory();
|
DirectedGraphFactory<Node, Double> getDirectedGraphFactory();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return A {@link ShortestPathsAlgorithm} for the path finding
|
||||||
|
*/
|
||||||
|
ShortestPathsAlgorithm<Node, Double> getShortestPathsAlgorithm();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package de.oshgnacknak.gruphi;
|
package de.oshgnacknak.gruphi;
|
||||||
|
|
||||||
|
import h07.algorithm.ShortestPathsAlgorithm;
|
||||||
import h07.graph.DirectedGraphFactory;
|
import h07.graph.DirectedGraphFactory;
|
||||||
|
|
||||||
import java.util.function.BiPredicate;
|
import java.util.function.BiPredicate;
|
||||||
@ -10,6 +11,7 @@ public class GruphiBuilder {
|
|||||||
private Double gridSpacing;
|
private Double gridSpacing;
|
||||||
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;
|
||||||
|
|
||||||
public GruphiBuilder setFrameDelay(Long frameDelay) {
|
public GruphiBuilder setFrameDelay(Long frameDelay) {
|
||||||
this.frameDelay = frameDelay;
|
this.frameDelay = frameDelay;
|
||||||
@ -36,7 +38,12 @@ public class GruphiBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GruphiBuilder setShortestPathsAlgorithm(ShortestPathsAlgorithm<Node, Double> shortestPathsAlgorithm) {
|
||||||
|
this.shortestPathsAlgorithm = shortestPathsAlgorithm;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public GruphiImpl createGruphi() {
|
public GruphiImpl createGruphi() {
|
||||||
return new GruphiImpl(frameDelay, velocity, gridSpacing, neighbourPredicate, directedGraphFactory);
|
return new GruphiImpl(frameDelay, velocity, gridSpacing, neighbourPredicate, directedGraphFactory, shortestPathsAlgorithm);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package de.oshgnacknak.gruphi;
|
package de.oshgnacknak.gruphi;
|
||||||
|
|
||||||
|
import h07.algorithm.ShortestPathsAlgorithm;
|
||||||
import h07.graph.DirectedGraphFactory;
|
import h07.graph.DirectedGraphFactory;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -21,16 +22,19 @@ public class GruphiImpl implements Gruphi {
|
|||||||
|
|
||||||
private final DirectedGraphFactory<Node, Double> directedGraphFactory;
|
private final DirectedGraphFactory<Node, Double> directedGraphFactory;
|
||||||
|
|
||||||
|
private final ShortestPathsAlgorithm<Node, Double> shortestPathsAlgorithm;
|
||||||
|
|
||||||
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) {
|
DirectedGraphFactory<Node, Double> directedGraphFactory, ShortestPathsAlgorithm<Node, Double> shortestPathsAlgorithm) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean defaultAreNeighbours(Node a, Node b) {
|
private boolean defaultAreNeighbours(Node a, Node b) {
|
||||||
@ -61,4 +65,9 @@ public class GruphiImpl implements Gruphi {
|
|||||||
public DirectedGraphFactory<Node, Double> getDirectedGraphFactory() {
|
public DirectedGraphFactory<Node, Double> getDirectedGraphFactory() {
|
||||||
return directedGraphFactory;
|
return directedGraphFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ShortestPathsAlgorithm<Node, Double> getShortestPathsAlgorithm() {
|
||||||
|
return shortestPathsAlgorithm;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user