From e7088eba046965e3ea94bbd356d46d13e1244571 Mon Sep 17 00:00:00 2001 From: houzhizhen Date: Mon, 21 Sep 2020 14:03:22 +0800 Subject: [PATCH] update Betweenness with Stressness (#60) --- .../job/algorithm/AlgorithmPool.java | 4 +- .../job/algorithm/SubgraphStatAlgorithm.java | 6 +-- .../algorithm/cent/AbstractCentAlgorithm.java | 1 + ...hm.java => StressCentralityAlgorithm.java} | 44 +++++++++---------- 4 files changed, 28 insertions(+), 27 deletions(-) rename hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/{BetweenessCentralityAlgorithm.java => StressCentralityAlgorithm.java} (68%) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/AlgorithmPool.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/AlgorithmPool.java index 9a84120772..3252936699 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/AlgorithmPool.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/AlgorithmPool.java @@ -22,7 +22,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import com.baidu.hugegraph.job.algorithm.cent.BetweenessCentralityAlgorithm; +import com.baidu.hugegraph.job.algorithm.cent.StressCentralityAlgorithm; import com.baidu.hugegraph.job.algorithm.cent.ClosenessCentralityAlgorithm; import com.baidu.hugegraph.job.algorithm.cent.DegreeCentralityAlgorithm; import com.baidu.hugegraph.job.algorithm.cent.EigenvectorCentralityAlgorithm; @@ -45,7 +45,7 @@ public class AlgorithmPool { INSTANCE.register(new CountEdgeAlgorithm()); INSTANCE.register(new DegreeCentralityAlgorithm()); - INSTANCE.register(new BetweenessCentralityAlgorithm()); + INSTANCE.register(new StressCentralityAlgorithm()); INSTANCE.register(new ClosenessCentralityAlgorithm()); INSTANCE.register(new EigenvectorCentralityAlgorithm()); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/SubgraphStatAlgorithm.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/SubgraphStatAlgorithm.java index bf35097346..09f994d14e 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/SubgraphStatAlgorithm.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/SubgraphStatAlgorithm.java @@ -33,7 +33,7 @@ import com.baidu.hugegraph.config.CoreOptions; import com.baidu.hugegraph.config.HugeConfig; import com.baidu.hugegraph.job.UserJob; -import com.baidu.hugegraph.job.algorithm.cent.BetweenessCentralityAlgorithm; +import com.baidu.hugegraph.job.algorithm.cent.StressCentralityAlgorithm; import com.baidu.hugegraph.job.algorithm.cent.ClosenessCentralityAlgorithm; import com.baidu.hugegraph.job.algorithm.cent.DegreeCentralityAlgorithm; import com.baidu.hugegraph.job.algorithm.cent.EigenvectorCentralityAlgorithm; @@ -158,8 +158,8 @@ public Object subgraphStat(UserJob job) { Map parameters = ImmutableMap.copyOf(PARAMS); results.put("degrees", algo.call(job, parameters)); - algo = new BetweenessCentralityAlgorithm(); - results.put("betweeness", algo.call(job, parameters)); + algo = new StressCentralityAlgorithm(); + results.put("stress", algo.call(job, parameters)); algo = new EigenvectorCentralityAlgorithm(); results.put("eigenvectors", algo.call(job, parameters)); diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/AbstractCentAlgorithm.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/AbstractCentAlgorithm.java index fd8453fff3..752dc74ba5 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/AbstractCentAlgorithm.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/AbstractCentAlgorithm.java @@ -157,6 +157,7 @@ protected GraphTraversal filterNonShortestPath( // ignore non shortest path return false; } + // TODO: len may be smaller than shortest if (shortest == null) { triples.put(key, len); } else { diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/BetweenessCentralityAlgorithm.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/StressCentralityAlgorithm.java similarity index 68% rename from hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/BetweenessCentralityAlgorithm.java rename to hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/StressCentralityAlgorithm.java index 968f636bae..87f1471d4b 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/BetweenessCentralityAlgorithm.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/StressCentralityAlgorithm.java @@ -30,13 +30,13 @@ import com.baidu.hugegraph.type.define.Directions; import com.baidu.hugegraph.util.ParameterUtil; -public class BetweenessCentralityAlgorithm extends AbstractCentAlgorithm { +public class StressCentralityAlgorithm extends AbstractCentAlgorithm { public static final String KEY_WITH_BOUNDARY = "with_boundary"; @Override public String name() { - return "betweeness_centrality"; + return "stress_centrality"; } @Override @@ -48,16 +48,16 @@ public void checkParameters(Map parameters) { @Override public Object call(UserJob job, Map parameters) { try (Traverser traverser = new Traverser(job)) { - return traverser.betweenessCentrality(direction(parameters), - edgeLabel(parameters), - depth(parameters), - degree(parameters), - sample(parameters), - withBoundary(parameters), - sourceLabel(parameters), - sourceSample(parameters), - sourceCLabel(parameters), - top(parameters)); + return traverser.stressCentrality(direction(parameters), + edgeLabel(parameters), + depth(parameters), + degree(parameters), + sample(parameters), + withBoundary(parameters), + sourceLabel(parameters), + sourceSample(parameters), + sourceCLabel(parameters), + top(parameters)); } } @@ -74,16 +74,16 @@ public Traverser(UserJob job) { super(job); } - public Object betweenessCentrality(Directions direction, - String label, - int depth, - long degree, - long sample, - boolean withBoundary, - String sourceLabel, - long sourceSample, - String sourceCLabel, - long topN) { + public Object stressCentrality(Directions direction, + String label, + int depth, + long degree, + long sample, + boolean withBoundary, + String sourceLabel, + long sourceSample, + String sourceCLabel, + long topN) { assert depth > 0; assert degree > 0L || degree == NO_LIMIT; assert topN >= 0L || topN == NO_LIMIT;