1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.giraph.io.formats;
20
21 import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
22 import org.apache.giraph.partition.PartitionUtils;
23 import org.apache.giraph.worker.WorkerInfo;
24
25 import java.util.Collections;
26 import java.util.List;
27 import java.util.Random;
28
29
30
31
32
33
34 public class PseudoRandomIntNullLocalEdgesHelper {
35
36 private float minLocalEdgesRatio;
37
38 private int numVertices;
39
40 private int numPartitions;
41
42 private int partitionSize;
43
44
45
46
47
48
49
50 public PseudoRandomIntNullLocalEdgesHelper(int numVertices,
51 ImmutableClassesGiraphConfiguration conf) {
52 this.minLocalEdgesRatio = conf.getFloat(
53 PseudoRandomInputFormatConstants.LOCAL_EDGES_MIN_RATIO,
54 PseudoRandomInputFormatConstants.LOCAL_EDGES_MIN_RATIO_DEFAULT);
55 this.numVertices = numVertices;
56 int numWorkers = conf.getMaxWorkers();
57 List<WorkerInfo> workerInfos = Collections.nCopies(numWorkers,
58 new WorkerInfo());
59 numPartitions = PartitionUtils.computePartitionCount(
60 workerInfos.size(), conf);
61 partitionSize = numVertices / numPartitions;
62 }
63
64
65
66
67
68
69
70
71
72
73 public int generateDestVertex(int sourceVertexId, Random rand) {
74 if (rand.nextFloat() < minLocalEdgesRatio) {
75 int partitionId = sourceVertexId % numPartitions;
76 return partitionId + numPartitions * rand.nextInt(partitionSize);
77 } else {
78 return rand.nextInt(numVertices);
79 }
80 }
81 }