From 2bb9f8d76a7b6421dd7b88080117ef6aee69a998 Mon Sep 17 00:00:00 2001 From: Lasse Westh-Nielsen Date: Fri, 29 Nov 2024 11:09:08 +0100 Subject: [PATCH] migrate estimation cli k1 coloring to application layer --- .../K1ColoringAlgorithmFactory.java | 87 ------------------- .../K1ColoringProgressTrackerTaskCreator.java | 4 +- .../K1ColoringStub.java | 64 ++++++++++++++ .../ModularityOptimization.java | 22 +++-- .../ModularityOptimizationFactory.java | 6 +- .../org/neo4j/gds/k1coloring/Constants.java | 27 ------ .../K1ColoringMutateSpecification.java | 60 ------------- .../K1ColoringStatsSpecification.java | 60 ------------- .../K1ColoringStreamSpecification.java | 60 ------------- .../K1ColoringWriteSpecification.java | 60 ------------- .../community/CommunityAlgorithms.java | 42 ++++----- 11 files changed, 96 insertions(+), 396 deletions(-) delete mode 100644 algo/src/main/java/org/neo4j/gds/k1coloring/K1ColoringAlgorithmFactory.java create mode 100644 algo/src/main/java/org/neo4j/gds/modularityoptimization/K1ColoringStub.java delete mode 100644 algorithm-specifications/src/main/java/org/neo4j/gds/k1coloring/Constants.java delete mode 100644 algorithm-specifications/src/main/java/org/neo4j/gds/k1coloring/K1ColoringMutateSpecification.java delete mode 100644 algorithm-specifications/src/main/java/org/neo4j/gds/k1coloring/K1ColoringStatsSpecification.java delete mode 100644 algorithm-specifications/src/main/java/org/neo4j/gds/k1coloring/K1ColoringStreamSpecification.java delete mode 100644 algorithm-specifications/src/main/java/org/neo4j/gds/k1coloring/K1ColoringWriteSpecification.java diff --git a/algo/src/main/java/org/neo4j/gds/k1coloring/K1ColoringAlgorithmFactory.java b/algo/src/main/java/org/neo4j/gds/k1coloring/K1ColoringAlgorithmFactory.java deleted file mode 100644 index e27b445f45..0000000000 --- a/algo/src/main/java/org/neo4j/gds/k1coloring/K1ColoringAlgorithmFactory.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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 . - */ -package org.neo4j.gds.k1coloring; - -import org.neo4j.gds.GraphAlgorithmFactory; -import org.neo4j.gds.api.Graph; -import org.neo4j.gds.config.BaseConfig; -import org.neo4j.gds.config.IterationsConfig; -import org.neo4j.gds.core.concurrency.DefaultPool; -import org.neo4j.gds.mem.MemoryEstimation; -import org.neo4j.gds.core.utils.progress.tasks.ProgressTracker; -import org.neo4j.gds.core.utils.progress.tasks.Task; -import org.neo4j.gds.core.utils.progress.tasks.Tasks; -import org.neo4j.gds.termination.TerminationFlag; - -import java.util.List; - -public class K1ColoringAlgorithmFactory extends GraphAlgorithmFactory { - - private static final String K1_COLORING_TASK_NAME = "K1Coloring"; - - @Override - public String taskName() { - return K1_COLORING_TASK_NAME; - } - - public K1Coloring build(Graph graph, K1ColoringParameters parameters, ProgressTracker progressTracker) { - return new K1Coloring( - graph, - parameters.maxIterations(), - parameters.batchSize(), - parameters.concurrency(), - DefaultPool.INSTANCE, - progressTracker, - TerminationFlag.RUNNING_TRUE - ); - } - - @Override - public K1Coloring build( - Graph graph, - T configuration, - ProgressTracker progressTracker - ) { - return build(graph, configuration.toParameters(), progressTracker); - } - - @Override - public MemoryEstimation memoryEstimation(T config) { - return new K1ColoringMemoryEstimateDefinition().memoryEstimation(); - } - - @Override - public Task progressTask(Graph graph, T config) { - return k1ColoringProgressTask(graph, config); - } - - public static Task k1ColoringProgressTask(Graph graph, T config) { - return Tasks.iterativeDynamic( - K1_COLORING_TASK_NAME, - () -> List.of( - Tasks.leaf("color nodes", graph.nodeCount()), - Tasks.leaf("validate nodes", graph.nodeCount()) - ), - config.maxIterations() - ); - } - - -} diff --git a/algo/src/main/java/org/neo4j/gds/k1coloring/K1ColoringProgressTrackerTaskCreator.java b/algo/src/main/java/org/neo4j/gds/k1coloring/K1ColoringProgressTrackerTaskCreator.java index e80220bba2..7a5f8d054c 100644 --- a/algo/src/main/java/org/neo4j/gds/k1coloring/K1ColoringProgressTrackerTaskCreator.java +++ b/algo/src/main/java/org/neo4j/gds/k1coloring/K1ColoringProgressTrackerTaskCreator.java @@ -25,12 +25,10 @@ import java.util.List; -public class K1ColoringProgressTrackerTaskCreator { - +public final class K1ColoringProgressTrackerTaskCreator { private K1ColoringProgressTrackerTaskCreator() {} public static Task progressTask(long nodeCount, int maxIterations) { - return Tasks.iterativeDynamic( AlgorithmLabel.K1Coloring.asString(), () -> List.of( diff --git a/algo/src/main/java/org/neo4j/gds/modularityoptimization/K1ColoringStub.java b/algo/src/main/java/org/neo4j/gds/modularityoptimization/K1ColoringStub.java new file mode 100644 index 0000000000..edaecf8f8f --- /dev/null +++ b/algo/src/main/java/org/neo4j/gds/modularityoptimization/K1ColoringStub.java @@ -0,0 +1,64 @@ +/* + * 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 . + */ +package org.neo4j.gds.modularityoptimization; + +import org.neo4j.gds.api.Graph; +import org.neo4j.gds.applications.algorithms.machinery.AlgorithmMachinery; +import org.neo4j.gds.core.concurrency.Concurrency; +import org.neo4j.gds.core.concurrency.DefaultPool; +import org.neo4j.gds.core.utils.progress.tasks.ProgressTracker; +import org.neo4j.gds.k1coloring.K1Coloring; +import org.neo4j.gds.k1coloring.K1ColoringParameters; +import org.neo4j.gds.k1coloring.K1ColoringResult; +import org.neo4j.gds.termination.TerminationFlag; + +public class K1ColoringStub { + private final AlgorithmMachinery algorithmMachinery; + + public K1ColoringStub(AlgorithmMachinery algorithmMachinery) { + this.algorithmMachinery = algorithmMachinery; + } + + public K1ColoringResult k1Coloring( + Graph graph, + K1ColoringParameters parameters, + ProgressTracker progressTracker, + TerminationFlag terminationFlag, + Concurrency concurrency, + boolean shouldReleaseProgressTracker + ) { + var algorithm = new K1Coloring( + graph, + parameters.maxIterations(), + parameters.batchSize(), + parameters.concurrency(), + DefaultPool.INSTANCE, + progressTracker, + terminationFlag + ); + + return algorithmMachinery.runAlgorithmsAndManageProgressTracker( + algorithm, + progressTracker, + shouldReleaseProgressTracker, + concurrency + ); + } +} diff --git a/algo/src/main/java/org/neo4j/gds/modularityoptimization/ModularityOptimization.java b/algo/src/main/java/org/neo4j/gds/modularityoptimization/ModularityOptimization.java index 18f66a5cdc..972abd2cc8 100644 --- a/algo/src/main/java/org/neo4j/gds/modularityoptimization/ModularityOptimization.java +++ b/algo/src/main/java/org/neo4j/gds/modularityoptimization/ModularityOptimization.java @@ -27,6 +27,7 @@ import org.neo4j.gds.api.Graph; import org.neo4j.gds.api.properties.nodes.NodePropertyValues; import org.neo4j.gds.api.properties.relationships.RelationshipIterator; +import org.neo4j.gds.applications.algorithms.machinery.AlgorithmMachinery; import org.neo4j.gds.collections.ha.HugeDoubleArray; import org.neo4j.gds.collections.ha.HugeLongArray; import org.neo4j.gds.collections.haa.HugeAtomicDoubleArray; @@ -38,8 +39,6 @@ import org.neo4j.gds.core.utils.partition.Partition; import org.neo4j.gds.core.utils.partition.PartitionUtils; import org.neo4j.gds.core.utils.progress.tasks.ProgressTracker; -import org.neo4j.gds.k1coloring.K1Coloring; -import org.neo4j.gds.k1coloring.K1ColoringAlgorithmFactory; import org.neo4j.gds.k1coloring.K1ColoringParameters; import org.neo4j.gds.termination.TerminationFlag; @@ -177,10 +176,16 @@ public ModularityOptimizationResult compute() { private void computeColoring() { var parameters = new K1ColoringParameters(concurrency, K1COLORING_MAX_ITERATIONS, minBatchSize); - K1Coloring coloring = new K1ColoringAlgorithmFactory<>().build(graph, parameters, progressTracker); - coloring.setTerminationFlag(terminationFlag); + var k1ColoringStub = new K1ColoringStub(new AlgorithmMachinery()); + var k1ColoringResult = k1ColoringStub.k1Coloring( + graph, + parameters, + progressTracker, + terminationFlag, + concurrency, + false + ); - var k1ColoringResult = coloring.compute(); modularityColorArray = ModularityColorArray.create( k1ColoringResult.colors(), k1ColoringResult.usedColors() @@ -394,11 +399,4 @@ private double calculateModularity() { modularityManager.registerCommunities(currentCommunities); return modularityManager.calculateModularity(); } - - private long getCommunityId(long nodeId) { - if (seedProperty == null || reverseSeedCommunityMapping == null) { - return currentCommunities.get(nodeId); - } - return reverseSeedCommunityMapping.get(currentCommunities.get(nodeId)); - } } diff --git a/algo/src/main/java/org/neo4j/gds/modularityoptimization/ModularityOptimizationFactory.java b/algo/src/main/java/org/neo4j/gds/modularityoptimization/ModularityOptimizationFactory.java index 975897badf..c450a88493 100644 --- a/algo/src/main/java/org/neo4j/gds/modularityoptimization/ModularityOptimizationFactory.java +++ b/algo/src/main/java/org/neo4j/gds/modularityoptimization/ModularityOptimizationFactory.java @@ -24,11 +24,11 @@ import org.neo4j.gds.api.Graph; import org.neo4j.gds.api.properties.nodes.NodePropertyValues; import org.neo4j.gds.core.concurrency.DefaultPool; +import org.neo4j.gds.k1coloring.K1ColoringProgressTrackerTaskCreator; import org.neo4j.gds.mem.MemoryEstimation; import org.neo4j.gds.core.utils.progress.tasks.ProgressTracker; import org.neo4j.gds.core.utils.progress.tasks.Task; import org.neo4j.gds.core.utils.progress.tasks.Tasks; -import org.neo4j.gds.k1coloring.K1ColoringAlgorithmFactory; import org.neo4j.gds.k1coloring.K1ColoringBaseConfig; import org.neo4j.gds.k1coloring.K1ColoringStreamConfigImpl; import org.neo4j.gds.termination.TerminationFlag; @@ -94,11 +94,13 @@ public Task progressTask(Graph graph, CONFIG config) { } public static Task progressTask(Graph graph, int maxIterations) { + var config = createModularityConfig(); + return Tasks.task( MODULARITY_OPTIMIZATION_TASK_NAME, Tasks.task( "initialization", - K1ColoringAlgorithmFactory.k1ColoringProgressTask(graph, createModularityConfig()) + K1ColoringProgressTrackerTaskCreator.progressTask(graph.nodeCount(), config.maxIterations()) ), Tasks.iterativeDynamic( "compute modularity", diff --git a/algorithm-specifications/src/main/java/org/neo4j/gds/k1coloring/Constants.java b/algorithm-specifications/src/main/java/org/neo4j/gds/k1coloring/Constants.java deleted file mode 100644 index 8301d90cda..0000000000 --- a/algorithm-specifications/src/main/java/org/neo4j/gds/k1coloring/Constants.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 . - */ -package org.neo4j.gds.k1coloring; - -final class Constants { - static final String K1_COLORING_DESCRIPTION = "The K-1 Coloring algorithm assigns a color to every node in the graph."; - - private Constants() {} - -} diff --git a/algorithm-specifications/src/main/java/org/neo4j/gds/k1coloring/K1ColoringMutateSpecification.java b/algorithm-specifications/src/main/java/org/neo4j/gds/k1coloring/K1ColoringMutateSpecification.java deleted file mode 100644 index 7edd30b3d2..0000000000 --- a/algorithm-specifications/src/main/java/org/neo4j/gds/k1coloring/K1ColoringMutateSpecification.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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 . - */ -package org.neo4j.gds.k1coloring; - -import org.neo4j.gds.NullComputationResultConsumer; -import org.neo4j.gds.executor.AlgorithmSpec; -import org.neo4j.gds.executor.ComputationResultConsumer; -import org.neo4j.gds.executor.ExecutionContext; -import org.neo4j.gds.executor.GdsCallable; -import org.neo4j.gds.procedures.algorithms.community.K1ColoringMutateResult; -import org.neo4j.gds.procedures.algorithms.configuration.NewConfigFunction; - -import java.util.stream.Stream; - -import static org.neo4j.gds.executor.ExecutionMode.MUTATE_NODE_PROPERTY; -import static org.neo4j.gds.k1coloring.Constants.K1_COLORING_DESCRIPTION; - -@GdsCallable(name = "gds.k1coloring.mutate", - aliases = { "gds.beta.k1coloring.mutate"}, - description = K1_COLORING_DESCRIPTION, - executionMode = MUTATE_NODE_PROPERTY) -public class K1ColoringMutateSpecification implements AlgorithmSpec, K1ColoringAlgorithmFactory> { - - @Override - public String name() { - return "K1ColoringMutate"; - } - - @Override - public K1ColoringAlgorithmFactory algorithmFactory(ExecutionContext executionContext) { - return new K1ColoringAlgorithmFactory<>(); - } - - @Override - public NewConfigFunction newConfigFunction() { - return (__, userInput) -> K1ColoringMutateConfig.of(userInput); - } - - @Override - public ComputationResultConsumer> computationResultConsumer() { - return new NullComputationResultConsumer<>(); - } -} diff --git a/algorithm-specifications/src/main/java/org/neo4j/gds/k1coloring/K1ColoringStatsSpecification.java b/algorithm-specifications/src/main/java/org/neo4j/gds/k1coloring/K1ColoringStatsSpecification.java deleted file mode 100644 index ff216fb9d6..0000000000 --- a/algorithm-specifications/src/main/java/org/neo4j/gds/k1coloring/K1ColoringStatsSpecification.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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 . - */ -package org.neo4j.gds.k1coloring; - -import org.neo4j.gds.NullComputationResultConsumer; -import org.neo4j.gds.executor.AlgorithmSpec; -import org.neo4j.gds.executor.ComputationResultConsumer; -import org.neo4j.gds.executor.ExecutionContext; -import org.neo4j.gds.executor.GdsCallable; -import org.neo4j.gds.procedures.algorithms.community.K1ColoringStatsResult; -import org.neo4j.gds.procedures.algorithms.configuration.NewConfigFunction; - -import java.util.stream.Stream; - -import static org.neo4j.gds.executor.ExecutionMode.STATS; -import static org.neo4j.gds.k1coloring.Constants.K1_COLORING_DESCRIPTION; - -@GdsCallable(name = "gds.k1coloring.stats", - aliases = {"gds.beta.k1coloring.stats"}, - description = K1_COLORING_DESCRIPTION, - executionMode = STATS) -public class K1ColoringStatsSpecification implements AlgorithmSpec, K1ColoringAlgorithmFactory> { - - @Override - public String name() { - return "K1ColoringStats"; - } - - @Override - public K1ColoringAlgorithmFactory algorithmFactory(ExecutionContext executionContext) { - return new K1ColoringAlgorithmFactory<>(); - } - - @Override - public NewConfigFunction newConfigFunction() { - return (__, userInput) -> K1ColoringStatsConfig.of(userInput); - } - - @Override - public ComputationResultConsumer> computationResultConsumer() { - return new NullComputationResultConsumer<>(); - } -} diff --git a/algorithm-specifications/src/main/java/org/neo4j/gds/k1coloring/K1ColoringStreamSpecification.java b/algorithm-specifications/src/main/java/org/neo4j/gds/k1coloring/K1ColoringStreamSpecification.java deleted file mode 100644 index f8f26b79aa..0000000000 --- a/algorithm-specifications/src/main/java/org/neo4j/gds/k1coloring/K1ColoringStreamSpecification.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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 . - */ -package org.neo4j.gds.k1coloring; - -import org.neo4j.gds.NullComputationResultConsumer; -import org.neo4j.gds.executor.AlgorithmSpec; -import org.neo4j.gds.executor.ComputationResultConsumer; -import org.neo4j.gds.executor.ExecutionContext; -import org.neo4j.gds.executor.GdsCallable; -import org.neo4j.gds.procedures.algorithms.community.K1ColoringStreamResult; -import org.neo4j.gds.procedures.algorithms.configuration.NewConfigFunction; - -import java.util.stream.Stream; - -import static org.neo4j.gds.executor.ExecutionMode.STREAM; -import static org.neo4j.gds.k1coloring.Constants.K1_COLORING_DESCRIPTION; - -@GdsCallable(name = "gds.k1coloring.stream", - aliases = {"gds.beta.k1coloring.stream"}, - description = K1_COLORING_DESCRIPTION, - executionMode = STREAM) -public class K1ColoringStreamSpecification implements AlgorithmSpec, K1ColoringAlgorithmFactory> { - - @Override - public String name() { - return "K1ColoringStream"; - } - - @Override - public K1ColoringAlgorithmFactory algorithmFactory(ExecutionContext executionContext) { - return new K1ColoringAlgorithmFactory<>(); - } - - @Override - public NewConfigFunction newConfigFunction() { - return (__, userInput) -> K1ColoringStreamConfig.of(userInput); - } - - @Override - public ComputationResultConsumer> computationResultConsumer() { - return new NullComputationResultConsumer<>(); - } -} diff --git a/algorithm-specifications/src/main/java/org/neo4j/gds/k1coloring/K1ColoringWriteSpecification.java b/algorithm-specifications/src/main/java/org/neo4j/gds/k1coloring/K1ColoringWriteSpecification.java deleted file mode 100644 index f8069155d6..0000000000 --- a/algorithm-specifications/src/main/java/org/neo4j/gds/k1coloring/K1ColoringWriteSpecification.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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 . - */ -package org.neo4j.gds.k1coloring; - -import org.neo4j.gds.NullComputationResultConsumer; -import org.neo4j.gds.executor.AlgorithmSpec; -import org.neo4j.gds.executor.ComputationResultConsumer; -import org.neo4j.gds.executor.ExecutionContext; -import org.neo4j.gds.executor.GdsCallable; -import org.neo4j.gds.procedures.algorithms.community.K1ColoringWriteResult; -import org.neo4j.gds.procedures.algorithms.configuration.NewConfigFunction; - -import java.util.stream.Stream; - -import static org.neo4j.gds.executor.ExecutionMode.WRITE_NODE_PROPERTY; -import static org.neo4j.gds.k1coloring.Constants.K1_COLORING_DESCRIPTION; - -@GdsCallable(name = "gds.k1coloring.write", - aliases = {"gds.beta.k1coloring.write"}, - description = K1_COLORING_DESCRIPTION, - executionMode = WRITE_NODE_PROPERTY) -public class K1ColoringWriteSpecification implements AlgorithmSpec, K1ColoringAlgorithmFactory> { - - @Override - public String name() { - return "K1ColoringWrite"; - } - - @Override - public K1ColoringAlgorithmFactory algorithmFactory(ExecutionContext executionContext) { - return new K1ColoringAlgorithmFactory<>(); - } - - @Override - public NewConfigFunction newConfigFunction() { - return (__, userInput) -> K1ColoringWriteConfig.of(userInput); - } - - @Override - public ComputationResultConsumer> computationResultConsumer() { - return new NullComputationResultConsumer<>(); - } -} diff --git a/applications/algorithms/community/src/main/java/org/neo4j/gds/applications/algorithms/community/CommunityAlgorithms.java b/applications/algorithms/community/src/main/java/org/neo4j/gds/applications/algorithms/community/CommunityAlgorithms.java index 9753c4fc70..c50ff9370f 100644 --- a/applications/algorithms/community/src/main/java/org/neo4j/gds/applications/algorithms/community/CommunityAlgorithms.java +++ b/applications/algorithms/community/src/main/java/org/neo4j/gds/applications/algorithms/community/CommunityAlgorithms.java @@ -21,6 +21,7 @@ import org.neo4j.gds.algorithms.community.CommunityCompanion; import org.neo4j.gds.api.Graph; +import org.neo4j.gds.api.IdMap; import org.neo4j.gds.applications.algorithms.machinery.AlgorithmLabel; import org.neo4j.gds.applications.algorithms.machinery.AlgorithmMachinery; import org.neo4j.gds.applications.algorithms.machinery.ProgressTrackerCreator; @@ -39,7 +40,6 @@ import org.neo4j.gds.core.utils.paged.dss.DisjointSetStruct; import org.neo4j.gds.core.utils.progress.tasks.Task; import org.neo4j.gds.core.utils.progress.tasks.Tasks; -import org.neo4j.gds.k1coloring.K1Coloring; import org.neo4j.gds.k1coloring.K1ColoringBaseConfig; import org.neo4j.gds.k1coloring.K1ColoringProgressTrackerTaskCreator; import org.neo4j.gds.k1coloring.K1ColoringResult; @@ -62,12 +62,12 @@ import org.neo4j.gds.modularity.ModularityBaseConfig; import org.neo4j.gds.modularity.ModularityCalculator; import org.neo4j.gds.modularity.ModularityResult; +import org.neo4j.gds.modularityoptimization.K1ColoringStub; import org.neo4j.gds.modularityoptimization.ModularityOptimization; import org.neo4j.gds.modularityoptimization.ModularityOptimizationBaseConfig; import org.neo4j.gds.modularityoptimization.ModularityOptimizationProgressTrackerTaskCreator; import org.neo4j.gds.modularityoptimization.ModularityOptimizationResult; import org.neo4j.gds.scc.Scc; -import org.neo4j.gds.scc.SccCommonBaseConfig; import org.neo4j.gds.sllpa.SpeakerListenerLPA; import org.neo4j.gds.sllpa.SpeakerListenerLPAConfig; import org.neo4j.gds.sllpa.SpeakerListenerLPAProgressTrackerCreator; @@ -156,28 +156,20 @@ ConductanceResult conductance(Graph graph, ConductanceBaseConfig configuration) ); } - K1ColoringResult k1Coloring(Graph graph, K1ColoringBaseConfig configuration) { - - + public K1ColoringResult k1Coloring(Graph graph, K1ColoringBaseConfig configuration) { var parameters = configuration.toParameters(); - var task = K1ColoringProgressTrackerTaskCreator.progressTask(graph.nodeCount(),parameters.maxIterations()); + var task = K1ColoringProgressTrackerTaskCreator.progressTask(graph.nodeCount(), parameters.maxIterations()); var progressTracker = progressTrackerCreator.createProgressTracker(configuration, task); - var algorithm = new K1Coloring( - graph, - parameters.maxIterations(), - parameters.batchSize(), - parameters.concurrency(), - DefaultPool.INSTANCE, - progressTracker, - terminationFlag - ); + var k1ColoringStub = new K1ColoringStub(algorithmMachinery); - return algorithmMachinery.runAlgorithmsAndManageProgressTracker( - algorithm, + return k1ColoringStub.k1Coloring( + graph, + parameters, progressTracker, - true, - configuration.concurrency() + terminationFlag, + configuration.concurrency(), + true ); } @@ -402,7 +394,7 @@ ModularityOptimizationResult modularityOptimization(Graph graph, ModularityOptim ); } - HugeLongArray scc(Graph graph, SccCommonBaseConfig configuration) { + HugeLongArray scc(Graph graph, AlgoBaseConfig configuration) { var progressTracker = progressTrackerCreator.createProgressTracker( configuration, Tasks.leaf(AlgorithmLabel.SCC.asString(), graph.nodeCount()) @@ -466,27 +458,27 @@ public DisjointSetStruct wcc(Graph graph, WccBaseConfig configuration) { return wccStub.wcc(graph, configuration.toParameters(), progressTracker, true); } - private Task constructKMeansProgressTask(Graph graph, KmeansBaseConfig configuration) { + private Task constructKMeansProgressTask(IdMap idMap, KmeansBaseConfig configuration) { var label = AlgorithmLabel.KMeans.asString(); var iterations = configuration.numberOfRestarts(); if (iterations == 1) { - return kMeansTask(graph, label, configuration); + return kMeansTask(idMap, label, configuration); } return Tasks.iterativeFixed( label, - () -> List.of(kMeansTask(graph, "KMeans Iteration", configuration)), + () -> List.of(kMeansTask(idMap, "KMeans Iteration", configuration)), iterations ); } - private Task kMeansTask(Graph graph, String description, KmeansBaseConfig configuration) { + private Task kMeansTask(IdMap idMap, String description, KmeansBaseConfig configuration) { if (configuration.computeSilhouette()) { return Tasks.task(description, List.of( Tasks.leaf("Initialization", configuration.k()), Tasks.iterativeDynamic("Main", () -> List.of(Tasks.leaf("Iteration")), configuration.maxIterations()), - Tasks.leaf("Silhouette", graph.nodeCount()) + Tasks.leaf("Silhouette", idMap.nodeCount()) )); } else {