本文整理汇总了Java中org.apache.flink.graph.spargel.MessageIterator类的典型用法代码示例。如果您正苦于以下问题:Java MessageIterator类的具体用法?Java MessageIterator怎么用?Java MessageIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessageIterator类属于org.apache.flink.graph.spargel包,在下文中一共展示了MessageIterator类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateVertex
import org.apache.flink.graph.spargel.MessageIterator; //导入依赖的package包/类
@Override
public void updateVertex(Vertex<K, Double> vertex,
MessageIterator<Double> inMessages) {
Double minDistance = Double.MAX_VALUE;
for (double msg : inMessages) {
if (msg < minDistance) {
minDistance = msg;
}
}
if (vertex.getValue() > minDistance) {
setNewVertexValue(minDistance);
}
}
示例2: updateVertex
import org.apache.flink.graph.spargel.MessageIterator; //导入依赖的package包/类
@Override
public void updateVertex(Vertex<GradoopId, GradoopId> vertex,
MessageIterator<GradoopId> messageIterator) throws Exception {
GradoopId lastComponent = vertex.getValue();
GradoopId newComponent = lastComponent;
for (GradoopId messageComponent : messageIterator) {
if (messageComponent.compareTo(newComponent) < 0) {
newComponent = messageComponent;
}
}
if (!lastComponent.equals(newComponent)) {
setNewVertexValue(newComponent);
}
}
示例3: updateVertex
import org.apache.flink.graph.spargel.MessageIterator; //导入依赖的package包/类
@Override
public void updateVertex(Vertex<Long, Double> vertex, MessageIterator<Double> inMessages) throws Exception {
if (inMessages.hasNext()) {
Long outDegree = getOutDegree() - 1;
// check if the vertex has another SP-Edge
if (outDegree <= 0) {
// set own value to infinity
setNewVertexValue(Double.MAX_VALUE);
}
}
}
示例4: updateVertex
import org.apache.flink.graph.spargel.MessageIterator; //导入依赖的package包/类
@Override
public void updateVertex(Vertex<Long, Double> vertex, MessageIterator<Double> inMessages) {
Double minDistance = Double.MAX_VALUE;
for (double msg : inMessages) {
if (msg < minDistance) {
minDistance = msg;
}
}
if (vertex.getValue() > minDistance) {
setNewVertexValue(minDistance);
}
}
示例5: updateVertex
import org.apache.flink.graph.spargel.MessageIterator; //导入依赖的package包/类
@Override
public void updateVertex(Vertex<K, Double> vertex, MessageIterator<Double> inMessages) {
double rankSum = 0.0;
for (double msg : inMessages) {
rankSum += msg;
}
// apply the dampening factor / random jump
double newRank = (beta * rankSum) + (1 - beta) / this.getNumberOfVertices();
setNewVertexValue(newRank);
}
示例6: updateVertex
import org.apache.flink.graph.spargel.MessageIterator; //导入依赖的package包/类
@Override
public void updateVertex(Vertex<K, VV> vertex, MessageIterator<VV> messages) throws Exception {
VV current = vertex.getValue();
VV min = current;
for (VV msg : messages) {
if (msg.compareTo(min) < 0) {
min = msg;
}
}
if (!min.equals(current)) {
setNewVertexValue(min);
}
}
示例7: updateVertex
import org.apache.flink.graph.spargel.MessageIterator; //导入依赖的package包/类
public void updateVertex(Vertex<K, VV> vertex, MessageIterator<VV> inMessages) {
Map<VV, Long> labelsWithFrequencies = new HashMap<>();
long maxFrequency = 1;
VV mostFrequentLabel = vertex.getValue();
// store the labels with their frequencies
for (VV msg : inMessages) {
if (labelsWithFrequencies.containsKey(msg)) {
long currentFreq = labelsWithFrequencies.get(msg);
labelsWithFrequencies.put(msg, currentFreq + 1);
} else {
labelsWithFrequencies.put(msg, 1L);
}
}
// select the most frequent label: if two or more labels have the
// same frequency, the node adopts the label with the highest value
for (Entry<VV, Long> entry : labelsWithFrequencies.entrySet()) {
if (entry.getValue() == maxFrequency) {
// check the label value to break ties
if (entry.getKey().compareTo(mostFrequentLabel) > 0) {
mostFrequentLabel = entry.getKey();
}
} else if (entry.getValue() > maxFrequency) {
maxFrequency = entry.getValue();
mostFrequentLabel = entry.getKey();
}
}
setNewVertexValue(mostFrequentLabel);
}
示例8: updateVertex
import org.apache.flink.graph.spargel.MessageIterator; //导入依赖的package包/类
@Override
public void updateVertex(Vertex<Long, Long> vertex, MessageIterator<Long> inMessages) {
long superstep = getSuperstepNumber();
aggregator.aggregate(superstep);
setNewVertexValue(vertex.getValue() + 1);
}
示例9: updateVertex
import org.apache.flink.graph.spargel.MessageIterator; //导入依赖的package包/类
/**
* Updates the vertex value if it has changed.
*
* @param vertex vertex to be updated
* @param msg message
* @throws Exception
*/
@Override
public void updateVertex(Vertex<GradoopId, PropertyValue> vertex,
MessageIterator<PropertyValue> msg) throws Exception {
PropertyValue value = getNewValue(vertex,
Lists.newArrayList(msg.iterator()));
if (!vertex.getValue().equals(value)) {
setNewVertexValue(value);
}
}
示例10: updateVertex
import org.apache.flink.graph.spargel.MessageIterator; //导入依赖的package包/类
@Override
public void updateVertex(Vertex<K, Tuple2<Long, Double>> vertex,
MessageIterator<Tuple2<Long, Double>> inMessages) throws Exception {
// we would like these two maps to be ordered
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;
// if the label was received before
if (receivedLabelsWithScores.containsKey(receivedLabel)) {
double newScore = receivedScore + receivedLabelsWithScores.get(receivedLabel);
receivedLabelsWithScores.put(receivedLabel, newScore);
} else {
// first time we see the label
receivedLabelsWithScores.put(receivedLabel, receivedScore);
}
// store the labels with the highest scores
if (labelsWithHighestScore.containsKey(receivedLabel)) {
double currentScore = labelsWithHighestScore.get(receivedLabel);
if (currentScore < receivedScore) {
// record the highest score
labelsWithHighestScore.put(receivedLabel, receivedScore);
}
} else {
// first time we see this label
labelsWithHighestScore.put(receivedLabel, receivedScore);
}
}
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()) {
if (receivedLabelsWithScores.get(curLabel) > maxScore) {
maxScore = receivedLabelsWithScores.get(curLabel);
maxScoreLabel = curLabel;
}
}
// find the highest score of 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<>(maxScoreLabel, highestScore));
}
}
示例11: updateVertex
import org.apache.flink.graph.spargel.MessageIterator; //导入依赖的package包/类
@Override
public void updateVertex(Vertex<Long, Long> vertex, MessageIterator<Long> inMessages) {
long superstep = getSuperstepNumber();
Assert.assertEquals(true, vertex.getValue() == superstep);
setNewVertexValue(vertex.getValue() + 1);
}