This code is borrowed from the book "Practical Graph Analytics with Apache Giraph".
My code's goal is to transform a graph from using only one-direction edge into using two-direction edges.
My data is a tab-delimited text file to TextDoubleDoubleAdjacencyListVertexInputFormat:
A 0 B 0
B 0
C 0 A 0 D 0
D 0 B 0 G 0
E 0 A 0 B 0 D 0
F 0 C 0 D 0
G 0 C 0 E 0
My minimal non-working example is:
import org.apache.giraph.GiraphRunner;
import org.apache.giraph.graph.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.util.ToolRunner;
import org.apache.giraph.edge.EdgeFactory;
public class DigraphToGraph extends BasicComputation<Text,DoubleWritable,DoubleWritable,Text>
{
static final DoubleWritable ORIG_E = new DoubleWritable (1),
NEW_E = new DoubleWritable (2);
@Override
public void compute(Vertex <Text,DoubleWritable, DoubleWritable> vertex, Iterable<Text> messages) {
if (getSuperstep () == 0)
sendMessageToAllEdges (vertex, vertex.getId ());
else {
for (Text m:messages) {
DoubleWritable edgeValue = vertex.getEdgeValue (m);
if (edgeValue == null)
vertex.addEdge (EdgeFactory.create (m, NEW_E));
else
// problem HERE: try to relabel edge
vertex.setEdgeValue (m, ORIG_E);
}
}
vertex.voteToHalt ();
}
}
After executing this code I was expecting to edges to have only 1 or 2 values. However, what I get is:
G 0.0 C 0.0 E 0.0 D 2.0
E 0.0 A 0.0 B 0.0 D 0.0 G 2.0
F 0.0 C 0.0 D 0.0
D 0.0 B 0.0 G 0.0 E 2.0 B 2.0 C 2.0
B 0.0 E 2.0 D 2.0 A 2.0
C 0.0 A 0.0 D 0.0 G 2.0 B 2.0
A 0.0 B 0.0 E 2.0 C 2.0
Why my code is not modyfing pre-existing edges?