提交 7324b9c1 编写于 作者: G Greg Hogan

[FLINK-4132] [gelly] Fix boxed comparison in CommunityDetection algorithm

This closes #2185
上级 918e5d0c
......@@ -48,9 +48,9 @@ import java.util.TreeMap;
*/
public class CommunityDetection<K> implements GraphAlgorithm<K, Long, Double, Graph<K, Long, Double>> {
private Integer maxIterations;
private int maxIterations;
private Double delta;
private double delta;
/**
* Creates a new Community Detection algorithm instance.
......@@ -63,7 +63,7 @@ public class CommunityDetection<K> implements GraphAlgorithm<K, Long, Double, Gr
* @param maxIterations The maximum number of iterations to run.
* @param delta The hop attenuation parameter. Its default value is 0.5.
*/
public CommunityDetection(Integer maxIterations, Double delta) {
public CommunityDetection(int maxIterations, double delta) {
this.maxIterations = maxIterations;
this.delta = delta;
......@@ -91,7 +91,7 @@ public class CommunityDetection<K> implements GraphAlgorithm<K, Long, Double, Gr
public void sendMessages(Vertex<K, Tuple2<Long, Double>> vertex) throws Exception {
for(Edge<K, Double> edge : getEdges()) {
sendMessageTo(edge.getTarget(), new Tuple2<Long, Double>(vertex.getValue().f0,
sendMessageTo(edge.getTarget(), new Tuple2<>(vertex.getValue().f0,
vertex.getValue().f1 * edge.getValue()));
}
}
......@@ -101,9 +101,9 @@ public class CommunityDetection<K> implements GraphAlgorithm<K, Long, Double, Gr
public static final class VertexLabelUpdater<K> extends GatherFunction<
K, Tuple2<Long, Double>, Tuple2<Long, Double>> {
private Double delta;
private double delta;
public VertexLabelUpdater(Double delta) {
public VertexLabelUpdater(double delta) {
this.delta = delta;
}
......@@ -112,17 +112,17 @@ public class CommunityDetection<K> implements GraphAlgorithm<K, Long, Double, Gr
MessageIterator<Tuple2<Long, Double>> inMessages) throws Exception {
// we would like these two maps to be ordered
Map<Long, Double> receivedLabelsWithScores = new TreeMap<Long, Double>();
Map<Long, Double> labelsWithHighestScore = new TreeMap<Long, Double>();
Map<Long, Double> receivedLabelsWithScores = new TreeMap<>();
Map<Long, Double> labelsWithHighestScore = new TreeMap<>();
for (Tuple2<Long, Double> message : inMessages) {
// split the message into received label and score
Long receivedLabel = message.f0;
Double receivedScore = message.f1;
long receivedLabel = message.f0;
double receivedScore = message.f1;
// if the label was received before
if (receivedLabelsWithScores.containsKey(receivedLabel)) {
Double newScore = receivedScore + receivedLabelsWithScores.get(receivedLabel);
double newScore = receivedScore + receivedLabelsWithScores.get(receivedLabel);
receivedLabelsWithScores.put(receivedLabel, newScore);
} else {
// first time we see the label
......@@ -131,7 +131,7 @@ public class CommunityDetection<K> implements GraphAlgorithm<K, Long, Double, Gr
// store the labels with the highest scores
if (labelsWithHighestScore.containsKey(receivedLabel)) {
Double currentScore = labelsWithHighestScore.get(receivedLabel);
double currentScore = labelsWithHighestScore.get(receivedLabel);
if (currentScore < receivedScore) {
// record the highest score
labelsWithHighestScore.put(receivedLabel, receivedScore);
......@@ -144,9 +144,9 @@ public class CommunityDetection<K> implements GraphAlgorithm<K, Long, Double, Gr
if(receivedLabelsWithScores.size() > 0) {
// find the label with the highest score from the ones received
Double maxScore = -Double.MAX_VALUE;
Long maxScoreLabel = vertex.getValue().f0;
for (Long curLabel : receivedLabelsWithScores.keySet()) {
double maxScore = Double.MIN_VALUE;
long maxScoreLabel = vertex.getValue().f0;
for (long curLabel : receivedLabelsWithScores.keySet()) {
if (receivedLabelsWithScores.get(curLabel) > maxScore) {
maxScore = receivedLabelsWithScores.get(curLabel);
......@@ -155,14 +155,14 @@ public class CommunityDetection<K> implements GraphAlgorithm<K, Long, Double, Gr
}
// find the highest score of maxScoreLabel
Double highestScore = labelsWithHighestScore.get(maxScoreLabel);
double highestScore = labelsWithHighestScore.get(maxScoreLabel);
// re-score the new label
if (maxScoreLabel != vertex.getValue().f0) {
highestScore -= delta / getSuperstepNumber();
}
// else delta = 0
// update own label
setNewVertexValue(new Tuple2<Long, Double>(maxScoreLabel, highestScore));
setNewVertexValue(new Tuple2<>(maxScoreLabel, highestScore));
}
}
}
......@@ -173,8 +173,7 @@ public class CommunityDetection<K> implements GraphAlgorithm<K, Long, Double, Gr
Vertex<K, Long>, Vertex<K, Tuple2<Long, Double>>> {
public Vertex<K, Tuple2<Long, Double>> map(Vertex<K, Long> vertex) {
return new Vertex<K, Tuple2<Long, Double>>(
vertex.getId(), new Tuple2<Long, Double>(vertex.getValue(), 1.0));
return new Vertex<>(vertex.getId(), new Tuple2<>(vertex.getValue(), 1.0));
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册