Add minimumSpanningForestAlgorithm to Gruphi
This commit is contained in:
		
							parent
							
								
									f1303fe37b
								
							
						
					
					
						commit
						6d4a8b26e6
					
				
					 3 changed files with 24 additions and 2 deletions
				
			
		|  | @ -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<Node, Double> getShortestPathsAlgorithm(); | ||||
| 
 | ||||
|     /** | ||||
|      * @return A {@link MinimumSpanningForestAlgorithm} for the spanning tree calculation | ||||
|      */ | ||||
|     MinimumSpanningForestAlgorithm<Node, Double> getMinimumSpanningForestAlgorithm(); | ||||
| } | ||||
|  |  | |||
|  | @ -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<Node, Node> neighbourPredicate; | ||||
|     private DirectedGraphFactory<Node, Double> directedGraphFactory; | ||||
|     private ShortestPathsAlgorithm<Node, Double> shortestPathsAlgorithm; | ||||
|     private MinimumSpanningForestAlgorithm<Node, Double> minimumSpanningForestAlgorithm; | ||||
| 
 | ||||
|     public GruphiBuilder setFrameDelay(Long frameDelay) { | ||||
|         this.frameDelay = frameDelay; | ||||
|  | @ -43,7 +45,12 @@ public class GruphiBuilder { | |||
|         return this; | ||||
|     } | ||||
| 
 | ||||
|     public GruphiBuilder setMinimumSpanningForestAlgorithm(MinimumSpanningForestAlgorithm<Node, Double> 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); | ||||
|     } | ||||
| } | ||||
|  | @ -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<Node, Double> shortestPathsAlgorithm; | ||||
| 
 | ||||
|     private final MinimumSpanningForestAlgorithm<Node, Double> minimumSpanningForestAlgorithm; | ||||
| 
 | ||||
|     public GruphiImpl(Long frameDelay, | ||||
|                       Double velocity, | ||||
|                       Double gridSpacing, | ||||
|                       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.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<Node, Double> getShortestPathsAlgorithm() { | ||||
|         return shortestPathsAlgorithm; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public MinimumSpanningForestAlgorithm<Node, Double> getMinimumSpanningForestAlgorithm() { | ||||
|         return minimumSpanningForestAlgorithm; | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Reference in a new issue