我正在使用Apache Giraph编写一个分布式聚类算法。在计算()方法中,我需要访问每个邻居发送的值,加上当前顶点和发送该消息的邻居之间的边的权重。然而,我在Giraph示例中看到的唯一消息类型是单类型消息(DoubleWritable、IntWritable等),它只能传递值,而不能传递发送者信息。
我们如何访问发送者信息或边缘信息?
例如,在上面的代码中,我们可以获得每条消息的值,但我们不知道是哪个节点将该值发送到当前节点。
public void compute(Iterator<DoubleWritable> msgIterator) {
...
double minDist = isSource() ? 0d : Double.MAX_VALUE;
while (msgIterator.hasNext()) {
// Get who sent this message, how?
minDist = Math.min(minDist, msgIterator.next().get());
}
...
}谢谢,
发布于 2013-07-14 06:48:27
我同意Thomas Jungblut的观点;编写自己的Writable可能是最好(也是最简单)的解决方案。
我最近编写了一个名为IntPairWritable的自定义Writable,它只包含两个整数。这是我的代码。
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.apache.giraph.utils.IntPair;
import org.apache.hadoop.conf.Configurable;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.Writable;
public class IntPairWritable extends IntPair implements Writable, Configurable {
private Configuration conf;
public IntPairWritable() {
super(0, 0);
}
public IntPairWritable(int fst, int snd) {
super(fst, snd);
}
@Override
public void readFields(DataInput input) throws IOException {
super.setFirst(input.readInt());
super.setSecond(input.readInt());
}
@Override
public void write(DataOutput output) throws IOException {
output.writeInt(super.getFirst());
output.writeInt(super.getSecond());
}
@Override
public Configuration getConf() {
return this.conf;
}
@Override
public void setConf(Configuration conf) {
this.conf = conf;
}
@Override
public String toString() {
return super.getFirst() + "," + super.getSecond();
}
}您的Writable类可能看起来很相似。也许就像
public class RetraceableWritable<I extends Writable, D extends Writable> implements Writable, Configurable {
private I senderId;
private D data;
......and等等。
可以创建类的实例。Hadoop
configurable的情况,因此实现此接口是一个好主意。问候
发布于 2014-07-03 15:16:33
正如darefilz提到的,编写自己的Writable类将是最好的选择。在使用自定义消息类的图形示例中提供了一个示例"verifyMessages.java“。
https://stackoverflow.com/questions/17371861
复制相似问题