Skip to content

Commit

Permalink
update Betweenness with Stressness (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
houzhizhen authored and imbajin committed Nov 9, 2022
1 parent 9926fc6 commit 71f6e81
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -158,8 +158,8 @@ public Object subgraphStat(UserJob<Object> job) {
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ protected <V> GraphTraversal<V, V> filterNonShortestPath(
// ignore non shortest path
return false;
}
// TODO: len may be smaller than shortest
if (shortest == null) {
triples.put(key, len);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -48,16 +48,16 @@ public void checkParameters(Map<String, Object> parameters) {
@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));
}
}

Expand All @@ -74,16 +74,16 @@ public Traverser(UserJob<Object> 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;
Expand Down

0 comments on commit 71f6e81

Please sign in to comment.