Skip to content

Commit

Permalink
migrating SPSP Dijkstra mutate to being reusable
Browse files Browse the repository at this point in the history
  • Loading branch information
lassewesth committed Jan 2, 2024
1 parent 47f3afe commit 5e87ae8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,6 +75,22 @@ public <RESULT> RESULT singlePairShortestPathAStarStream(
);
}

public <RESULT> RESULT singlePairShortestPathDijkstraMutate(
GraphName graphName,
ShortestPathDijkstraMutateConfig configuration,
ResultBuilder<PathFindingResult, RESULT> resultBuilder
) {
return algorithmProcessingTemplate.processAlgorithm(
graphName,
configuration,
"Dijkstra",
() -> new DijkstraMemoryEstimateDefinition().memoryEstimation(configuration),
graph -> pathFindingAlgorithms.singlePairShortestPathDijkstra(graph, configuration),
Optional.of(new ShortestPathMutateStep(configuration)),
resultBuilder
);
}

public <RESULT> RESULT singlePairShortestPathDijkstraStream(
GraphName graphName,
ShortestPathDijkstraStreamConfig configuration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,17 +36,16 @@
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)
public Stream<PathFindingMutateResult> mutate(
@Name(value = "graphName") String graphName,
@Name(value = "configuration", defaultValue = "{}") Map<String, Object> 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)
Expand All @@ -60,6 +60,4 @@ public Stream<MemoryEstimateResult> estimate(
transactionContext()
).computeEstimate(graphNameOrConfiguration, algoConfiguration);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -70,37 +71,51 @@ public PathFindingProcedureFacade(
}

public Stream<PathFindingStreamResult> singlePairShortestPathAStarStream(
String graphNameAsString,
Map<String, Object> rawConfiguration
String graphName,
Map<String, Object> configuration
) {
return runStreamAlgorithm(
graphNameAsString,
rawConfiguration,
graphName,
configuration,
ShortestPathAStarStreamConfig::of,
facade::singlePairShortestPathAStarStream
);
}

public Stream<PathFindingMutateResult> singlePairShortestPathDijkstraMutate(
String graphName,
Map<String, Object> configuration
) {
return Stream.of(
runMutateAlgorithm(
graphName,
configuration,
ShortestPathDijkstraMutateConfig::of,
facade::singlePairShortestPathDijkstraMutate
)
);
}

public Stream<PathFindingStreamResult> singlePairShortestPathDijkstraStream(
String graphNameAsString,
Map<String, Object> rawConfiguration
String graphName,
Map<String, Object> configuration
) {
return runStreamAlgorithm(
graphNameAsString,
rawConfiguration,
graphName,
configuration,
ShortestPathDijkstraStreamConfig::of,
facade::singlePairShortestPathDijkstraStream
);
}

public Stream<PathFindingMutateResult> singleSourceShortestPathDijkstraMutate(
String graphNameAsString,
Map<String, Object> rawConfiguration
String graphName,
Map<String, Object> configuration
) {
return Stream.of(
runMutateAlgorithm(
graphNameAsString,
rawConfiguration,
graphName,
configuration,
AllShortestPathsDijkstraMutateConfig::of,
facade::singleSourceShortestPathDijkstraMutate
)
Expand Down

0 comments on commit 5e87ae8

Please sign in to comment.