From ae7a9de3f8098a9c5c7afc9f8dc8b39bcab85d51 Mon Sep 17 00:00:00 2001 From: Jermy Li Date: Fri, 10 Apr 2020 17:35:22 +0800 Subject: [PATCH] set louvain max community members limit 10w (#9) Change-Id: I5cc3be846ff4536ebfba1f9bf54a0adda7409036 --- .../hugegraph/job/algorithm/comm/KCoreAlgorithm.java | 12 +++++++----- .../job/algorithm/comm/LouvainTraverser.java | 8 ++++---- .../job/algorithm/path/RingsDetectAlgorithm.java | 12 +++++++----- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/KCoreAlgorithm.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/KCoreAlgorithm.java index 80f10da77e..4cc6a88ba5 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/KCoreAlgorithm.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/KCoreAlgorithm.java @@ -72,9 +72,12 @@ public Object call(Job job, Map parameters) { Traverser traverser = new Traverser(job); return traverser.kcore(sourceLabel(parameters), sourceCLabel(parameters), - direction(parameters), edgeLabel(parameters), - k(parameters), alpha(parameters), - degree(parameters), merged(parameters)); + direction(parameters), + edgeLabel(parameters), + k(parameters), + alpha(parameters), + degree(parameters), + merged(parameters)); } protected static int k(Map parameters) { @@ -139,7 +142,6 @@ public Object kcore(String sourceLabel, String sourceCLabel, return kcoresJson.asJson(); } - @SuppressWarnings("unchecked") private static void mergeKcores(Set> kcores, Set kcore) { boolean merged = false; /* @@ -173,7 +175,7 @@ public KcoreTraverser(HugeGraph graph) { public Set kcore(Iterator vertices, Directions direction, EdgeLabel label, int k, double alpha, long degree) { - int minNeighbors = (int) Math.floor(1 / alpha * k); + int minNeighbors = (int) Math.floor(1.0 / alpha * k); SimilarsMap map = fusiformSimilarity(vertices, direction, label, minNeighbors, alpha, k - 1, 0, null, 1, degree, diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/LouvainTraverser.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/LouvainTraverser.java index 9c4f80f645..ecb500a7d6 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/LouvainTraverser.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/comm/LouvainTraverser.java @@ -65,7 +65,7 @@ public class LouvainTraverser extends AlgoTraverser { public static final String C_MEMBERS = "c_members"; private static final long LIMIT = AbstractAlgorithm.MAX_QUERY_LIMIT; - private static final int MAX_COMM_SIZE = 1000000; + private static final int MAX_COMM_SIZE = 100000; // 10w private static final Logger LOG = Log.logger(LouvainTraverser.class); @@ -372,9 +372,9 @@ private double moveCommunities(int pass) { for (Pair nbc : nbCommunities(pass, nbs)) { // △Q = (Ki_in - Ki * Etot / m) / 2m Community otherC = nbc.getLeft(); - if (otherC.size() > MAX_COMM_SIZE) { - LOG.info("Skip community {} due to its size > {}", - otherC, MAX_COMM_SIZE); + if (otherC.size() >= MAX_COMM_SIZE) { + LOG.info("Skip community {} for {} due to its size >= {}", + otherC.cid, v, MAX_COMM_SIZE); continue; } // weight between c and otherC diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/path/RingsDetectAlgorithm.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/path/RingsDetectAlgorithm.java index 6a1a0add7a..b3ce1ec992 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/path/RingsDetectAlgorithm.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/path/RingsDetectAlgorithm.java @@ -63,9 +63,12 @@ public Object call(Job job, Map parameters) { Traverser traverser = new Traverser(job); return traverser.rings(sourceLabel(parameters), sourceCLabel(parameters), - direction(parameters), edgeLabel(parameters), - depth(parameters), degree(parameters), - capacity(parameters), limit(parameters)); + direction(parameters), + edgeLabel(parameters), + depth(parameters), + degree(parameters), + capacity(parameters), + limit(parameters)); } public static class Traverser extends AlgoTraverser { @@ -89,8 +92,7 @@ public Object rings(String sourceLabel, String sourceCLabel, this.updateProgress(++this.progress); Id source = ((HugeVertex) vertices.next()).id(); PathSet rings = traverser.rings(source, dir, label, depth, - true, degree, - capacity, limit); + true, degree, capacity, limit); for (Path ring : rings) { Id min = null; for (Id id : ring.vertices()) {