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