Skip to content

Commit

Permalink
moar facade segregation
Browse files Browse the repository at this point in the history
  • Loading branch information
lassewesth committed Jan 11, 2024
1 parent de6e450 commit 4ef794b
Show file tree
Hide file tree
Showing 9 changed files with 421 additions and 291 deletions.
18 changes: 18 additions & 0 deletions applications/algorithms/path-finding/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Path Finding Applications

We are in the application layer, so we offer all the verticals for path finding, such as Dijkstra oin various forms, A*, Yens, you name it.

And we package them in a neat facade so that we are easily used from e.g. the Neo4j integration layer.

## Facade design

We offer facades segmented by mode, e.g. writes or estimates.
Because these facades are the top level thing in the path finding segment of this layer,
we should make it very useful and usable. That is their purpose.
A single dependency that grants access.

We should capture reuse here that different UIs need. Neo4j Procedures coming in, maybe Arrow, let's make life easy for them.

Concretely, we have UI layers inject result rendering as that is bespoke. We delegate downwards for the actual computations.

Importantly, each segment-facade decides which, if any, mutate or write hooks need to be injected. We pick those from a catalog since they are all the same - relationship-centric for path finding.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.gds.applications.algorithms.pathfinding;

/**
* We need human-readable labels for e.g. progress tracking
*/
interface AlgorithmLabels {
String A_STAR = "AStar";
String DIJKSTRA = "Dijkstra";
String YENS = "Yens";
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.gds.applications.algorithms.pathfinding;

import org.neo4j.gds.AlgorithmMemoryEstimateDefinition;
import org.neo4j.gds.config.AlgoBaseConfig;
import org.neo4j.gds.paths.SourceTargetShortestPathBaseConfig;
import org.neo4j.gds.paths.astar.AStarMemoryEstimateDefinition;
import org.neo4j.gds.paths.astar.config.ShortestPathAStarBaseConfig;
import org.neo4j.gds.paths.dijkstra.DijkstraMemoryEstimateDefinition;
import org.neo4j.gds.paths.yens.YensMemoryEstimateDefinition;
import org.neo4j.gds.paths.yens.config.ShortestPathYensBaseConfig;
import org.neo4j.gds.results.MemoryEstimateResult;

/**
* Here is the top level business facade for all your path finding memory estimation needs.
* It will have all pathfinding algorithms on it, in estimate mode.
*/
public class PathFindingAlgorithmsEstimationModeBusinessFacade {
private final AlgorithmEstimationTemplate algorithmEstimationTemplate;

public PathFindingAlgorithmsEstimationModeBusinessFacade(AlgorithmEstimationTemplate algorithmEstimationTemplate) {
this.algorithmEstimationTemplate = algorithmEstimationTemplate;
}

public MemoryEstimateResult singlePairShortestPathAStarEstimate(
ShortestPathAStarBaseConfig configuration,
Object graphNameOrConfiguration
) {
return runEstimation(new AStarMemoryEstimateDefinition(), configuration, graphNameOrConfiguration);
}

public MemoryEstimateResult singlePairShortestPathDijkstraEstimate(
SourceTargetShortestPathBaseConfig configuration,
Object graphNameOrConfiguration
) {
return runEstimation(new DijkstraMemoryEstimateDefinition(), configuration, graphNameOrConfiguration);
}

public MemoryEstimateResult singlePairShortestPathYensEstimate(
ShortestPathYensBaseConfig configuration,
Object graphNameOrConfiguration
) {
return runEstimation(new YensMemoryEstimateDefinition(), configuration, graphNameOrConfiguration);
}

private <CONFIGURATION extends AlgoBaseConfig> MemoryEstimateResult runEstimation(
AlgorithmMemoryEstimateDefinition<CONFIGURATION> memoryEstimateDefinition,
CONFIGURATION configuration,
Object graphNameOrConfiguration
) {
var memoryEstimation = memoryEstimateDefinition.memoryEstimation(configuration);

return algorithmEstimationTemplate.estimate(
configuration,
graphNameOrConfiguration,
memoryEstimation
);
}
}
Loading

0 comments on commit 4ef794b

Please sign in to comment.