Skip to content

Commit 6015dda

Browse files
committed
Move path finding mutate steps to subproject
1 parent 3f50405 commit 6015dda

File tree

11 files changed

+147
-73
lines changed

11 files changed

+147
-73
lines changed

applications/algorithms/path-finding/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ dependencies {
2525
implementation project(':memory-usage')
2626
implementation project(':metrics-api')
2727
implementation project(':path-finding-configs')
28+
implementation project(':path-finding-mutate-steps')
2829
implementation project(':progress-tracking')
2930
implementation project(':string-formatting')
3031
implementation project(':termination')

applications/algorithms/path-finding/src/main/java/org/neo4j/gds/applications/algorithms/pathfinding/PathFindingAlgorithmsMutateModeBusinessFacade.java

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
import org.neo4j.gds.applications.algorithms.metadata.RelationshipsWritten;
3434
import org.neo4j.gds.collections.ha.HugeLongArray;
3535
import org.neo4j.gds.collections.haa.HugeAtomicLongArray;
36+
import org.neo4j.gds.pathfinding.BellmanFordMutateStep;
37+
import org.neo4j.gds.pathfinding.PrizeCollectingSteinerTreeMutateStep;
38+
import org.neo4j.gds.pathfinding.RandomWalkCountingNodeVisitsMutateStep;
39+
import org.neo4j.gds.pathfinding.SearchMutateStep;
40+
import org.neo4j.gds.pathfinding.ShortestPathMutateStep;
41+
import org.neo4j.gds.pathfinding.SpanningTreeMutateStep;
42+
import org.neo4j.gds.pathfinding.SteinerTreeMutateStep;
3643
import org.neo4j.gds.paths.astar.config.ShortestPathAStarMutateConfig;
3744
import org.neo4j.gds.paths.bellmanford.AllShortestPathsBellmanFordMutateConfig;
3845
import org.neo4j.gds.paths.bellmanford.BellmanFordResult;
@@ -121,7 +128,10 @@ public <RESULT> RESULT breadthFirstSearch(
121128
BfsMutateConfig configuration,
122129
ResultBuilder<BfsMutateConfig, HugeLongArray, RESULT, RelationshipsWritten> resultBuilder
123130
) {
124-
var mutateStep = new SearchMutateStep(mutateRelationshipService, RelationshipType.of(configuration.mutateRelationshipType()));
131+
var mutateStep = new SearchMutateStep(
132+
mutateRelationshipService,
133+
RelationshipType.of(configuration.mutateRelationshipType())
134+
);
125135

126136
return algorithmProcessingTemplateConvenience.processRegularAlgorithmInMutateMode(
127137
graphName,
@@ -139,7 +149,7 @@ public <RESULT> RESULT deltaStepping(
139149
AllShortestPathsDeltaMutateConfig configuration,
140150
ResultBuilder<AllShortestPathsDeltaMutateConfig, PathFindingResult, RESULT, RelationshipsWritten> resultBuilder
141151
) {
142-
var mutateStep = new ShortestPathMutateStep(mutateRelationshipService,configuration);
152+
var mutateStep = new ShortestPathMutateStep(configuration.mutateRelationshipType(), mutateRelationshipService);
143153

144154
return algorithmProcessingTemplateConvenience.processRegularAlgorithmInMutateMode(
145155
graphName,
@@ -157,7 +167,10 @@ public <RESULT> RESULT depthFirstSearch(
157167
DfsMutateConfig configuration,
158168
ResultBuilder<DfsMutateConfig, HugeLongArray, RESULT, RelationshipsWritten> resultBuilder
159169
) {
160-
var mutateStep = new SearchMutateStep(mutateRelationshipService,RelationshipType.of(configuration.mutateRelationshipType()));
170+
var mutateStep = new SearchMutateStep(
171+
mutateRelationshipService,
172+
RelationshipType.of(configuration.mutateRelationshipType())
173+
);
161174

162175
return algorithmProcessingTemplateConvenience.processRegularAlgorithmInMutateMode(
163176
graphName,
@@ -175,7 +188,11 @@ public <RESULT> RESULT pcst(
175188
PCSTMutateConfig configuration,
176189
ResultBuilder<PCSTMutateConfig, PrizeSteinerTreeResult, RESULT, RelationshipsWritten> resultBuilder
177190
) {
178-
var mutateStep = new PrizeCollectingSteinerTreeMutateStep(mutateRelationshipService,configuration);
191+
var mutateStep = new PrizeCollectingSteinerTreeMutateStep(
192+
configuration.mutateRelationshipType(),
193+
configuration.mutateProperty(),
194+
mutateRelationshipService
195+
);
179196

180197
return algorithmProcessingTemplateConvenience.processRegularAlgorithmInMutateMode(
181198
graphName,
@@ -193,7 +210,11 @@ public <RESULT> RESULT randomWalk(
193210
RandomWalkMutateConfig configuration,
194211
ResultBuilder<RandomWalkMutateConfig, HugeAtomicLongArray, RESULT, NodePropertiesWritten> resultBuilder
195212
) {
196-
var mutateStep = new RandomWalkCountingNodeVisitsMutateStep(mutateNodeProperty, configuration);
213+
var mutateStep = new RandomWalkCountingNodeVisitsMutateStep(
214+
configuration.nodeLabels(),
215+
configuration.mutateProperty(),
216+
mutateNodeProperty
217+
);
197218

198219
return algorithmProcessingTemplateConvenience.processRegularAlgorithmInMutateMode(
199220
graphName,
@@ -212,7 +233,7 @@ public <RESULT> RESULT singlePairShortestPathAStar(
212233
ShortestPathAStarMutateConfig configuration,
213234
ResultBuilder<ShortestPathAStarMutateConfig, PathFindingResult, RESULT, RelationshipsWritten> resultBuilder
214235
) {
215-
var mutateStep = new ShortestPathMutateStep(mutateRelationshipService,configuration);
236+
var mutateStep = new ShortestPathMutateStep(configuration.mutateRelationshipType(), mutateRelationshipService);
216237

217238
return algorithmProcessingTemplateConvenience.processRegularAlgorithmInMutateMode(
218239
graphName,
@@ -230,7 +251,7 @@ public <RESULT> RESULT singlePairShortestPathDijkstra(
230251
ShortestPathDijkstraMutateConfig configuration,
231252
ResultBuilder<ShortestPathDijkstraMutateConfig, PathFindingResult, RESULT, RelationshipsWritten> resultBuilder
232253
) {
233-
var mutateStep = new ShortestPathMutateStep(mutateRelationshipService,configuration);
254+
var mutateStep = new ShortestPathMutateStep(configuration.mutateRelationshipType(), mutateRelationshipService);
234255

235256
return algorithmProcessingTemplateConvenience.processRegularAlgorithmInMutateMode(
236257
graphName,
@@ -271,7 +292,7 @@ public <RESULT> RESULT singlePairShortestPathYens(
271292
ShortestPathYensMutateConfig configuration,
272293
ResultBuilder<ShortestPathYensMutateConfig, PathFindingResult, RESULT, RelationshipsWritten> resultBuilder
273294
) {
274-
var mutateStep = new ShortestPathMutateStep(mutateRelationshipService,configuration);
295+
var mutateStep = new ShortestPathMutateStep(configuration.mutateRelationshipType(), mutateRelationshipService);
275296

276297
return algorithmProcessingTemplateConvenience.processRegularAlgorithmInMutateMode(
277298
graphName,
@@ -289,7 +310,7 @@ public <RESULT> RESULT singleSourceShortestPathDijkstra(
289310
AllShortestPathsDijkstraMutateConfig configuration,
290311
ResultBuilder<AllShortestPathsDijkstraMutateConfig, PathFindingResult, RESULT, RelationshipsWritten> resultBuilder
291312
) {
292-
var mutateStep = new ShortestPathMutateStep(mutateRelationshipService,configuration);
313+
var mutateStep = new ShortestPathMutateStep(configuration.mutateRelationshipType(), mutateRelationshipService);
293314

294315
return algorithmProcessingTemplateConvenience.processRegularAlgorithmInMutateMode(
295316
graphName,
@@ -355,7 +376,11 @@ public <RESULT> RESULT spanningTree(
355376
SpanningTreeMutateConfig configuration,
356377
ResultBuilder<SpanningTreeMutateConfig, SpanningTree, RESULT, RelationshipsWritten> resultBuilder
357378
) {
358-
var mutateStep = new SpanningTreeMutateStep(mutateRelationshipService,configuration);
379+
var mutateStep = new SpanningTreeMutateStep(
380+
configuration.mutateRelationshipType(),
381+
configuration.mutateProperty(),
382+
mutateRelationshipService
383+
);
359384

360385
return algorithmProcessingTemplateConvenience.processRegularAlgorithmInMutateMode(
361386
graphName,
@@ -373,7 +398,12 @@ public <RESULT> RESULT steinerTree(
373398
SteinerTreeMutateConfig configuration,
374399
ResultBuilder<SteinerTreeMutateConfig, SteinerTreeResult, RESULT, RelationshipsWritten> resultBuilder
375400
) {
376-
var mutateStep = new SteinerTreeMutateStep(mutateRelationshipService,configuration);
401+
var mutateStep = new SteinerTreeMutateStep(
402+
configuration.mutateRelationshipType(),
403+
configuration.mutateProperty(),
404+
configuration.sourceNode(),
405+
mutateRelationshipService
406+
);
377407

378408
return algorithmProcessingTemplateConvenience.processRegularAlgorithmInMutateMode(
379409
graphName,
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apply plugin: 'java-library'
2+
3+
description = 'Neo4j Graph Data Science :: Path Finding Mutate Steps'
4+
5+
group = 'org.neo4j.gds'
6+
7+
dependencies {
8+
9+
// FIXME: we need `:algo` because the algorithm results are there,
10+
// extract them in a separate project and bring it instead
11+
implementation project(':algo')
12+
13+
implementation project(':algorithms-machinery')
14+
15+
// FIXME: Massively annoying we need to bring this in because services use configs;
16+
// Also `ElementTypeValidator` is there even though it's not depending on any config 🤷
17+
implementation project(':config-api')
18+
19+
implementation project(':core')
20+
implementation project(':core-api')
21+
implementation project(':logging')
22+
implementation project(':string-formatting')
23+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* You should have received a copy of the GNU General Public License
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
20-
package org.neo4j.gds.applications.algorithms.pathfinding;
20+
package org.neo4j.gds.pathfinding;
2121

2222
import org.neo4j.gds.api.Graph;
2323
import org.neo4j.gds.api.GraphStore;
@@ -26,12 +26,12 @@
2626
import org.neo4j.gds.applications.algorithms.metadata.RelationshipsWritten;
2727
import org.neo4j.gds.paths.bellmanford.BellmanFordResult;
2828

29-
class BellmanFordMutateStep implements MutateStep<BellmanFordResult, RelationshipsWritten> {
29+
public class BellmanFordMutateStep implements MutateStep<BellmanFordResult, RelationshipsWritten> {
3030
private final String mutateRelationshipType;
3131
private final boolean mutateNegativeCycles;
3232
private final MutateRelationshipService mutateRelationshipService;
3333

34-
BellmanFordMutateStep(
34+
public BellmanFordMutateStep(
3535
String mutateRelationshipType,
3636
boolean mutateNegativeCycles,
3737
MutateRelationshipService mutateRelationshipService
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* You should have received a copy of the GNU General Public License
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
20-
package org.neo4j.gds.applications.algorithms.pathfinding;
20+
package org.neo4j.gds.pathfinding;
2121

2222
import org.neo4j.gds.Orientation;
2323
import org.neo4j.gds.RelationshipType;
@@ -27,9 +27,8 @@
2727
import org.neo4j.gds.paths.bellmanford.BellmanFordResult;
2828
import org.neo4j.gds.paths.dijkstra.PathFindingResult;
2929

30-
import static org.neo4j.gds.paths.dijkstra.config.ShortestPathDijkstraWriteConfig.TOTAL_COST_KEY;
31-
3230
final class PathFindingSingleTypeRelationshipsFactory {
31+
private static final String TOTAL_COST_KEY = "totalCost";
3332

3433
private PathFindingSingleTypeRelationshipsFactory() {}
3534

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* You should have received a copy of the GNU General Public License
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
20-
package org.neo4j.gds.applications.algorithms.pathfinding;
20+
package org.neo4j.gds.pathfinding;
2121

2222
import org.neo4j.gds.Orientation;
2323
import org.neo4j.gds.RelationshipType;
@@ -27,17 +27,22 @@
2727
import org.neo4j.gds.applications.algorithms.machinery.MutateStep;
2828
import org.neo4j.gds.applications.algorithms.metadata.RelationshipsWritten;
2929
import org.neo4j.gds.core.loading.construction.GraphFactory;
30-
import org.neo4j.gds.pcst.PCSTMutateConfig;
3130
import org.neo4j.gds.pricesteiner.PrizeSteinerTreeResult;
3231

3332
import java.util.stream.LongStream;
3433

35-
class PrizeCollectingSteinerTreeMutateStep implements MutateStep<PrizeSteinerTreeResult, RelationshipsWritten> {
36-
private final PCSTMutateConfig configuration;
34+
public class PrizeCollectingSteinerTreeMutateStep implements MutateStep<PrizeSteinerTreeResult, RelationshipsWritten> {
35+
private final String mutateRelationshipType;
36+
private final String mutateProperty;
3737
private final MutateRelationshipService mutateRelationshipService;
3838

39-
PrizeCollectingSteinerTreeMutateStep(MutateRelationshipService mutateRelationshipService, PCSTMutateConfig configuration) {
40-
this.configuration = configuration;
39+
public PrizeCollectingSteinerTreeMutateStep(
40+
String mutateRelationshipType,
41+
String mutateProperty,
42+
MutateRelationshipService mutateRelationshipService
43+
) {
44+
this.mutateRelationshipType = mutateRelationshipType;
45+
this.mutateProperty = mutateProperty;
4146
this.mutateRelationshipService = mutateRelationshipService;
4247
}
4348

@@ -47,29 +52,28 @@ public RelationshipsWritten execute(
4752
GraphStore graphStore,
4853
PrizeSteinerTreeResult treeResult
4954
) {
50-
var mutateRelationshipType = RelationshipType.of(configuration.mutateRelationshipType());
5155

5256
var relationshipsBuilder = GraphFactory.initRelationshipsBuilder()
5357
.nodes(graph)
54-
.relationshipType(mutateRelationshipType)
55-
.addPropertyConfig(GraphFactory.PropertyConfig.of(configuration.mutateProperty()))
58+
.relationshipType(RelationshipType.of(mutateRelationshipType))
59+
.addPropertyConfig(GraphFactory.PropertyConfig.of(mutateProperty))
5660
.orientation(Orientation.NATURAL)
5761
.build();
5862

5963
var parentArray = treeResult.parentArray();
6064
var costArray = treeResult.relationshipToParentCost();
6165
LongStream.range(0, graph.nodeCount())
62-
.filter(nodeId -> parentArray.get(nodeId) != PrizeSteinerTreeResult.PRUNED )
63-
.filter(nodeId -> parentArray.get(nodeId) != PrizeSteinerTreeResult.ROOT )
66+
.filter(nodeId -> parentArray.get(nodeId) != PrizeSteinerTreeResult.PRUNED)
67+
.filter(nodeId -> parentArray.get(nodeId) != PrizeSteinerTreeResult.ROOT)
6468
.forEach(nodeId -> {
6569
var parentId = parentArray.get(nodeId);
66-
relationshipsBuilder.addFromInternal(parentId, nodeId, costArray.get(nodeId));
70+
relationshipsBuilder.addFromInternal(parentId, nodeId, costArray.get(nodeId));
6771

6872
});
6973

7074
var relationships = relationshipsBuilder.build();
7175

72-
return mutateRelationshipService.mutate(graphStore, relationships);
76+
return mutateRelationshipService.mutate(graphStore, relationships);
7377

7478
}
7579
}
Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,34 @@
1717
* You should have received a copy of the GNU General Public License
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
20-
package org.neo4j.gds.applications.algorithms.pathfinding;
20+
package org.neo4j.gds.pathfinding;
2121

2222
import org.neo4j.gds.api.Graph;
2323
import org.neo4j.gds.api.GraphStore;
24+
import org.neo4j.gds.api.properties.nodes.NodePropertyRecord;
2425
import org.neo4j.gds.api.properties.nodes.NodePropertyValuesAdapter;
2526
import org.neo4j.gds.applications.algorithms.machinery.MutateNodePropertyService;
2627
import org.neo4j.gds.applications.algorithms.machinery.MutateStep;
2728
import org.neo4j.gds.applications.algorithms.metadata.NodePropertiesWritten;
2829
import org.neo4j.gds.collections.haa.HugeAtomicLongArray;
29-
import org.neo4j.gds.traversal.RandomWalkMutateConfig;
30+
import org.neo4j.gds.config.ElementTypeValidator;
3031

31-
class RandomWalkCountingNodeVisitsMutateStep implements MutateStep<HugeAtomicLongArray, NodePropertiesWritten> {
32+
import java.util.Collection;
33+
import java.util.List;
34+
35+
public class RandomWalkCountingNodeVisitsMutateStep implements MutateStep<HugeAtomicLongArray, NodePropertiesWritten> {
36+
private final Collection<String> labelsToUpdate;
37+
private final String mutateProperty;
3238
private final MutateNodePropertyService mutateNodePropertyService;
33-
private final RandomWalkMutateConfig configuration;
3439

35-
RandomWalkCountingNodeVisitsMutateStep(
36-
MutateNodePropertyService mutateNodePropertyService,
37-
RandomWalkMutateConfig configuration
40+
public RandomWalkCountingNodeVisitsMutateStep(
41+
Collection<String> labelsToUpdate,
42+
String mutateProperty,
43+
MutateNodePropertyService mutateNodePropertyService
3844
) {
45+
this.labelsToUpdate = labelsToUpdate;
46+
this.mutateProperty = mutateProperty;
3947
this.mutateNodePropertyService = mutateNodePropertyService;
40-
this.configuration = configuration;
4148
}
4249

4350
@Override
@@ -51,8 +58,8 @@ public NodePropertiesWritten execute(
5158
return mutateNodePropertyService.mutateNodeProperties(
5259
graph,
5360
graphStore,
54-
configuration,
55-
nodePropertyValues
61+
ElementTypeValidator.resolve(graphStore, labelsToUpdate),
62+
List.of(NodePropertyRecord.of(mutateProperty, nodePropertyValues))
5663
);
5764
}
5865
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* You should have received a copy of the GNU General Public License
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
20-
package org.neo4j.gds.applications.algorithms.pathfinding;
20+
package org.neo4j.gds.pathfinding;
2121

2222
import org.neo4j.gds.Orientation;
2323
import org.neo4j.gds.RelationshipType;
@@ -29,11 +29,11 @@
2929
import org.neo4j.gds.collections.ha.HugeLongArray;
3030
import org.neo4j.gds.core.loading.construction.GraphFactory;
3131

32-
class SearchMutateStep implements MutateStep<HugeLongArray, RelationshipsWritten> {
32+
public class SearchMutateStep implements MutateStep<HugeLongArray, RelationshipsWritten> {
3333
private final RelationshipType mutateRelationshipType;
3434
private final MutateRelationshipService mutateRelationshipService;
3535

36-
SearchMutateStep(MutateRelationshipService mutateRelationshipService, RelationshipType mutateRelationshipType) {
36+
public SearchMutateStep(MutateRelationshipService mutateRelationshipService, RelationshipType mutateRelationshipType) {
3737
this.mutateRelationshipType = mutateRelationshipType;
3838
this.mutateRelationshipService = mutateRelationshipService;
3939
}
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,21 @@
1717
* You should have received a copy of the GNU General Public License
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
20-
package org.neo4j.gds.applications.algorithms.pathfinding;
20+
package org.neo4j.gds.pathfinding;
2121

2222
import org.neo4j.gds.api.Graph;
2323
import org.neo4j.gds.api.GraphStore;
2424
import org.neo4j.gds.applications.algorithms.machinery.MutateRelationshipService;
2525
import org.neo4j.gds.applications.algorithms.machinery.MutateStep;
2626
import org.neo4j.gds.applications.algorithms.metadata.RelationshipsWritten;
27-
import org.neo4j.gds.config.MutateRelationshipConfig;
2827
import org.neo4j.gds.paths.dijkstra.PathFindingResult;
2928

30-
class ShortestPathMutateStep implements MutateStep<PathFindingResult, RelationshipsWritten> {
31-
private final MutateRelationshipConfig configuration;
29+
public class ShortestPathMutateStep implements MutateStep<PathFindingResult, RelationshipsWritten> {
30+
private final String mutateRelationshipType;
3231
private final MutateRelationshipService mutateRelationshipService;
3332

34-
ShortestPathMutateStep(MutateRelationshipService mutateRelationshipService, MutateRelationshipConfig configuration) {
35-
this.configuration = configuration;
33+
public ShortestPathMutateStep(String mutateRelationshipType, MutateRelationshipService mutateRelationshipService) {
34+
this.mutateRelationshipType = mutateRelationshipType;
3635
this.mutateRelationshipService = mutateRelationshipService;
3736
}
3837

@@ -50,7 +49,7 @@ public RelationshipsWritten execute(
5049

5150
return mutateRelationshipService.mutate(
5251
graphStore,
53-
configuration.mutateRelationshipType(),
52+
mutateRelationshipType,
5453
singleTypeRelationshipsProducer
5554
);
5655
}

0 commit comments

Comments
 (0)