-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleReducer.java
executable file
·44 lines (40 loc) · 1.63 KB
/
SimpleReducer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
public class SimpleReducer extends Reducer<IntWritable, Text, NullWritable, Text> {
public static double alpha = Utility.alpha;
public void reduce(IntWritable key, Iterable<Text> values, Context context)
throws IOException, InterruptedException {
//simply add pagerank to this node
Node node = null;
double s = 0;
double oldPageRank = 0;
for (Text v : values){
if (Node.isNode(Utility.getType(v))) {
node =new Node(Utility.getValue(v));
oldPageRank = node.pageRank;
}
else s += Double.parseDouble(Utility.getValue(v));
}
//deal with sink pagerank
long G = Utility.NUM_OF_NODES;
long m0000 = Long.parseLong(context.getConfiguration().get("sinkPageRank"));
double m = m0000/Utility.POWER;
double PR = m/G;
if (!Utility.SINK_MODE){
PR=0;
}
node.setPageRank((1-alpha)/G + alpha*(PR + s));
//add sink pagerank to counter
if(node.outgoingSize()==0){
long PR0000 = (long) (node.pageRank*Utility.POWER);
context.getCounter(HadoopCounter.COUNTER.SINKPAGERANK).increment(PR0000);
}
//add residual to counter
long PR00000 = (long) (Utility.computeResidual(oldPageRank, node.pageRank)*Utility.POWER);
context.getCounter(HadoopCounter.COUNTER.RESIDUALS).increment(PR00000);
context.write(null, node.toMPText());
}
}