update Betweenness with Stressness (#60)

This commit is contained in:
houzhizhen 2020-09-21 14:03:22 +08:00 committed by imbajin
parent 9926fc6e05
commit 71f6e81796
4 changed files with 28 additions and 27 deletions

View File

@ -22,7 +22,7 @@ package com.baidu.hugegraph.job.algorithm;
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());

View File

@ -33,7 +33,7 @@ import com.baidu.hugegraph.backend.id.Id;
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 class SubgraphStatAlgorithm extends AbstractAlgorithm {
Map<String, Object> 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));

View File

@ -157,6 +157,7 @@ public abstract class AbstractCentAlgorithm extends AbstractAlgorithm {
// ignore non shortest path
return false;
}
// TODO: len may be smaller than shortest
if (shortest == null) {
triples.put(key, len);
} else {

View File

@ -30,13 +30,13 @@ import com.baidu.hugegraph.job.UserJob;
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 class BetweenessCentralityAlgorithm extends AbstractCentAlgorithm {
@Override
public Object call(UserJob<Object> job, Map<String, Object> 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 class BetweenessCentralityAlgorithm extends AbstractCentAlgorithm {
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;