From 5e87ae86a14cbe216b15bffe72772d2b2a160700 Mon Sep 17 00:00:00 2001 From: Lasse Westh-Nielsen Date: Tue, 2 Jan 2024 13:36:06 +0100 Subject: [PATCH] migrating SPSP Dijkstra mutate to being reusable --- .../PathFindingAlgorithmsFacade.java | 17 ++++++++ .../ShortestPathDijkstraMutateProc.java | 12 +++--- .../PathFindingProcedureFacade.java | 39 +++++++++++++------ 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/applications/algorithms/path-finding/src/main/java/org/neo4j/gds/applications/algorithms/pathfinding/PathFindingAlgorithmsFacade.java b/applications/algorithms/path-finding/src/main/java/org/neo4j/gds/applications/algorithms/pathfinding/PathFindingAlgorithmsFacade.java index a00f496b70..ed166a24a8 100644 --- a/applications/algorithms/path-finding/src/main/java/org/neo4j/gds/applications/algorithms/pathfinding/PathFindingAlgorithmsFacade.java +++ b/applications/algorithms/path-finding/src/main/java/org/neo4j/gds/applications/algorithms/pathfinding/PathFindingAlgorithmsFacade.java @@ -26,6 +26,7 @@ import org.neo4j.gds.paths.dijkstra.PathFindingResult; import org.neo4j.gds.paths.dijkstra.config.AllShortestPathsDijkstraMutateConfig; import org.neo4j.gds.paths.dijkstra.config.AllShortestPathsDijkstraStreamConfig; +import org.neo4j.gds.paths.dijkstra.config.ShortestPathDijkstraMutateConfig; import org.neo4j.gds.paths.dijkstra.config.ShortestPathDijkstraStreamConfig; import java.util.Optional; @@ -74,6 +75,22 @@ public RESULT singlePairShortestPathAStarStream( ); } + public RESULT singlePairShortestPathDijkstraMutate( + GraphName graphName, + ShortestPathDijkstraMutateConfig configuration, + ResultBuilder resultBuilder + ) { + return algorithmProcessingTemplate.processAlgorithm( + graphName, + configuration, + "Dijkstra", + () -> new DijkstraMemoryEstimateDefinition().memoryEstimation(configuration), + graph -> pathFindingAlgorithms.singlePairShortestPathDijkstra(graph, configuration), + Optional.of(new ShortestPathMutateStep(configuration)), + resultBuilder + ); + } + public RESULT singlePairShortestPathDijkstraStream( GraphName graphName, ShortestPathDijkstraStreamConfig configuration, diff --git a/proc/path-finding/src/main/java/org/neo4j/gds/paths/sourcetarget/ShortestPathDijkstraMutateProc.java b/proc/path-finding/src/main/java/org/neo4j/gds/paths/sourcetarget/ShortestPathDijkstraMutateProc.java index 4143275cb9..5d91405621 100644 --- a/proc/path-finding/src/main/java/org/neo4j/gds/paths/sourcetarget/ShortestPathDijkstraMutateProc.java +++ b/proc/path-finding/src/main/java/org/neo4j/gds/paths/sourcetarget/ShortestPathDijkstraMutateProc.java @@ -21,9 +21,10 @@ import org.neo4j.gds.BaseProc; import org.neo4j.gds.executor.MemoryEstimationExecutor; -import org.neo4j.gds.executor.ProcedureExecutor; +import org.neo4j.gds.procedures.GraphDataScience; import org.neo4j.gds.procedures.pathfinding.PathFindingMutateResult; import org.neo4j.gds.results.MemoryEstimateResult; +import org.neo4j.procedure.Context; import org.neo4j.procedure.Description; import org.neo4j.procedure.Name; import org.neo4j.procedure.Procedure; @@ -35,6 +36,8 @@ import static org.neo4j.procedure.Mode.READ; public class ShortestPathDijkstraMutateProc extends BaseProc { + @Context + public GraphDataScience facade; @Procedure(name = "gds.shortestPath.dijkstra.mutate", mode = READ) @Description(DIJKSTRA_DESCRIPTION) @@ -42,10 +45,7 @@ public Stream mutate( @Name(value = "graphName") String graphName, @Name(value = "configuration", defaultValue = "{}") Map configuration ) { - return new ProcedureExecutor<>( - new ShortestPathDijkstraMutateSpec(), - executionContext() - ).compute(graphName, configuration); + return facade.pathFinding().singlePairShortestPathDijkstraMutate(graphName, configuration); } @Procedure(name = "gds.shortestPath.dijkstra.mutate.estimate", mode = READ) @@ -60,6 +60,4 @@ public Stream estimate( transactionContext() ).computeEstimate(graphNameOrConfiguration, algoConfiguration); } - - } diff --git a/procedures/facade/src/main/java/org/neo4j/gds/procedures/pathfinding/PathFindingProcedureFacade.java b/procedures/facade/src/main/java/org/neo4j/gds/procedures/pathfinding/PathFindingProcedureFacade.java index 248d13fd33..4d763d516c 100644 --- a/procedures/facade/src/main/java/org/neo4j/gds/procedures/pathfinding/PathFindingProcedureFacade.java +++ b/procedures/facade/src/main/java/org/neo4j/gds/procedures/pathfinding/PathFindingProcedureFacade.java @@ -30,6 +30,7 @@ import org.neo4j.gds.paths.dijkstra.PathFindingResult; import org.neo4j.gds.paths.dijkstra.config.AllShortestPathsDijkstraMutateConfig; import org.neo4j.gds.paths.dijkstra.config.AllShortestPathsDijkstraStreamConfig; +import org.neo4j.gds.paths.dijkstra.config.ShortestPathDijkstraMutateConfig; import org.neo4j.gds.paths.dijkstra.config.ShortestPathDijkstraStreamConfig; import org.neo4j.gds.procedures.algorithms.ConfigurationCreator; @@ -70,37 +71,51 @@ public PathFindingProcedureFacade( } public Stream singlePairShortestPathAStarStream( - String graphNameAsString, - Map rawConfiguration + String graphName, + Map configuration ) { return runStreamAlgorithm( - graphNameAsString, - rawConfiguration, + graphName, + configuration, ShortestPathAStarStreamConfig::of, facade::singlePairShortestPathAStarStream ); } + public Stream singlePairShortestPathDijkstraMutate( + String graphName, + Map configuration + ) { + return Stream.of( + runMutateAlgorithm( + graphName, + configuration, + ShortestPathDijkstraMutateConfig::of, + facade::singlePairShortestPathDijkstraMutate + ) + ); + } + public Stream singlePairShortestPathDijkstraStream( - String graphNameAsString, - Map rawConfiguration + String graphName, + Map configuration ) { return runStreamAlgorithm( - graphNameAsString, - rawConfiguration, + graphName, + configuration, ShortestPathDijkstraStreamConfig::of, facade::singlePairShortestPathDijkstraStream ); } public Stream singleSourceShortestPathDijkstraMutate( - String graphNameAsString, - Map rawConfiguration + String graphName, + Map configuration ) { return Stream.of( runMutateAlgorithm( - graphNameAsString, - rawConfiguration, + graphName, + configuration, AllShortestPathsDijkstraMutateConfig::of, facade::singleSourceShortestPathDijkstraMutate )