本文整理汇总了Java中org.apache.giraph.edge.EdgeFactory类的典型用法代码示例。如果您正苦于以下问题:Java EdgeFactory类的具体用法?Java EdgeFactory怎么用?Java EdgeFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EdgeFactory类属于org.apache.giraph.edge包,在下文中一共展示了EdgeFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: replaceNodeEdgesWithCommunityEdges
import org.apache.giraph.edge.EdgeFactory; //导入依赖的package包/类
/**
* Replace each edge to a neighbor with an edge to that neigbors community
* instead. Done just before exiting computation. In the next state of the
* piple line this edges are aggregated and all communities are represented
* as single nodes. Edges from the community to itself are tracked be the
* ndoes interal weight.
*
* @param messages
*/
private void replaceNodeEdgesWithCommunityEdges(Vertex<Text, LouvainNodeState, LongWritable> vertex, Iterable<LouvainMessage> messages) {
// group messages by communities.
HashMap<String, LouvainMessage> communityMap = new HashMap<String, LouvainMessage>();
for (LouvainMessage message : messages) {
String communityId = message.getCommunityId();
if (communityMap.containsKey(communityId)) {
LouvainMessage m = communityMap.get(communityId);
m.setEdgeWeight(m.getEdgeWeight() + message.getEdgeWeight());
} else {
LouvainMessage newmess = new LouvainMessage(message);
communityMap.put(communityId, newmess);
}
}
List<Edge<Text, LongWritable>> edges = new ArrayList<Edge<Text, LongWritable>>(communityMap.size() + 1);
for (Map.Entry<String, LouvainMessage> entry : communityMap.entrySet()) {
edges.add(EdgeFactory.create(new Text(entry.getKey()), new LongWritable(entry.getValue().getEdgeWeight())));
}
vertex.setEdges(edges);
}
示例2: getCurrentVertex
import org.apache.giraph.edge.EdgeFactory; //导入依赖的package包/类
@Override
public Vertex<LongWritable, DoubleWritable, DoubleWritable, ?>
getCurrentVertex() throws IOException, InterruptedException {
Vertex<LongWritable, DoubleWritable, DoubleWritable, ?>
vertex = conf.createVertex();
String[] tokens =
separator.split(getRecordReader().getCurrentValue().toString());
List<Edge<LongWritable, DoubleWritable>> edges =
Lists.newArrayListWithCapacity(tokens.length - 1);
float weight = 1.0f / (tokens.length - 1);
for (int n = 1; n < tokens.length; n++) {
edges.add(EdgeFactory.create(
new LongWritable(Long.parseLong(tokens[n])),
new DoubleWritable(weight)));
}
LongWritable vertexId = new LongWritable(Long.parseLong(tokens[0]));
vertex.initialize(vertexId, new DoubleWritable(), edges);
return vertex;
}
示例3: getCurrentVertex
import org.apache.giraph.edge.EdgeFactory; //导入依赖的package包/类
/**
* For each row, create a vertex with the row ID as a text,
* and it's 'children' qualifier as a single edge.
*/
@Override
public Vertex<Text, Text, Text>
getCurrentVertex()
throws IOException, InterruptedException {
Result row = getRecordReader().getCurrentValue();
Vertex<Text, Text, Text> vertex =
getConf().createVertex();
Text vertexId = new Text(Bytes.toString(row.getRow()));
List<Edge<Text, Text>> edges = Lists.newLinkedList();
String edge = Bytes.toString(row.getValue(CF, CHILDREN));
Text vertexValue = new Text();
Text edgeId = new Text(edge);
edges.add(EdgeFactory.create(edgeId, uselessEdgeValue));
vertex.initialize(vertexId, vertexValue, edges);
return vertex;
}
示例4: getCurrentVertex
import org.apache.giraph.edge.EdgeFactory; //导入依赖的package包/类
@Override
public Vertex<LongWritable, DoubleWritable,
FloatWritable> getCurrentVertex() throws IOException {
Vertex<LongWritable, DoubleWritable, FloatWritable> vertex =
getConf().createVertex();
LongWritable vertexId = new LongWritable(
(inputSplit.getSplitIndex() * totalRecords) + recordsRead);
DoubleWritable vertexValue = new DoubleWritable(vertexId.get() * 10d);
long targetVertexId =
(vertexId.get() + 1) %
(inputSplit.getNumSplits() * totalRecords);
float edgeValue = vertexId.get() * 100f;
List<Edge<LongWritable, FloatWritable>> edges = Lists.newLinkedList();
edges.add(EdgeFactory.create(new LongWritable(targetVertexId),
new FloatWritable(edgeValue)));
vertex.initialize(vertexId, vertexValue, edges);
++recordsRead;
if (LOG.isInfoEnabled()) {
LOG.info("next vertex: Return vertexId=" + vertex.getId().get() +
", vertexValue=" + vertex.getValue() +
", targetVertexId=" + targetVertexId + ", edgeValue=" + edgeValue);
}
aggregate(INPUT_VERTEX_PERSISTENT_AGG,
new LongWritable((long) vertex.getValue().get()));
return vertex;
}
示例5: testHappyPath
import org.apache.giraph.edge.EdgeFactory; //导入依赖的package包/类
@Test
public void testHappyPath() throws Exception {
String input = "Hi\t0\tCiao\t1.123\tBomdia\t2.234\tOla\t3.345";
when(rr.getCurrentValue()).thenReturn(new Text(input));
TextVertexReader vr = createVertexReader(rr);
vr.setConf(conf);
vr.initialize(null, tac);
assertTrue("Should have been able to add a vertex", vr.nextVertex());
Vertex<Text, DoubleWritable, DoubleWritable, ?> vertex = vr.getCurrentVertex();
setGraphState(vertex, graphState);
assertValidVertex(conf, graphState, vertex,
new Text("Hi"), new DoubleWritable(0),
EdgeFactory.create(new Text("Ciao"), new DoubleWritable(1.123d)),
EdgeFactory.create(new Text("Bomdia"), new DoubleWritable(2.234d)),
EdgeFactory.create(new Text("Ola"), new DoubleWritable(3.345d)));
assertEquals(vertex.getNumEdges(), 3);
}
开发者ID:zfighter,项目名称:giraph-research,代码行数:19,代码来源:TestTextDoubleDoubleAdjacencyListVertexInputFormat.java
示例6: getCurrentVertex
import org.apache.giraph.edge.EdgeFactory; //导入依赖的package包/类
@Override
public Vertex<LongWritable, DoubleWritable, FloatWritable>
getCurrentVertex() throws IOException {
Vertex<LongWritable, DoubleWritable, FloatWritable> vertex =
getConf().createVertex();
LongWritable vertexId = new LongWritable(
(inputSplit.getSplitIndex() * totalRecords) + recordsRead);
DoubleWritable vertexValue = new DoubleWritable(vertexId.get() * 10d);
long targetVertexId =
(vertexId.get() + 1) %
(inputSplit.getNumSplits() * totalRecords);
float edgeValue = vertexId.get() * 100f;
List<Edge<LongWritable, FloatWritable>> edges = Lists.newLinkedList();
edges.add(EdgeFactory.create(new LongWritable(targetVertexId),
new FloatWritable(edgeValue)));
vertex.initialize(vertexId, vertexValue, edges);
++recordsRead;
if (LOG.isInfoEnabled()) {
LOG.info("next: Return vertexId=" + vertex.getId().get() +
", vertexValue=" + vertex.getValue() +
", targetVertexId=" + targetVertexId + ", edgeValue=" + edgeValue);
}
return vertex;
}
示例7: getCurrentVertex
import org.apache.giraph.edge.EdgeFactory; //导入依赖的package包/类
@Override
public Vertex<LongWritable, DoubleWritable, NullWritable>
getCurrentVertex() throws IOException, InterruptedException {
Vertex<LongWritable, DoubleWritable, NullWritable>
vertex = conf.createVertex();
String[] tokens =
separator.split(getRecordReader().getCurrentValue().toString());
List<Edge<LongWritable, NullWritable>> edges =
Lists.newArrayListWithCapacity(tokens.length - 1);
for (int n = 1; n < tokens.length; n++) {
edges.add(EdgeFactory.create(
new LongWritable(Long.parseLong(tokens[n])),
NullWritable.get()));
}
LongWritable vertexId = new LongWritable(Long.parseLong(tokens[0]));
vertex.initialize(vertexId, new DoubleWritable(), edges);
return vertex;
}
示例8: getCurrentVertex
import org.apache.giraph.edge.EdgeFactory; //导入依赖的package包/类
@Override
public Vertex<LongWritable, DoubleWritable,
FloatWritable, Writable> getCurrentVertex() throws IOException {
Vertex<LongWritable, DoubleWritable, FloatWritable, Writable>
vertex = getConf().createVertex();
LongWritable vertexId = new LongWritable(
(inputSplit.getSplitIndex() * totalRecords) + recordsRead);
DoubleWritable vertexValue = new DoubleWritable(vertexId.get() * 10d);
long targetVertexId =
(vertexId.get() + 1) %
(inputSplit.getNumSplits() * totalRecords);
float edgeValue = vertexId.get() * 100f;
List<Edge<LongWritable, FloatWritable>> edges = Lists.newLinkedList();
edges.add(EdgeFactory.create(new LongWritable(targetVertexId),
new FloatWritable(edgeValue)));
vertex.initialize(vertexId, vertexValue, edges);
++recordsRead;
if (LOG.isInfoEnabled()) {
LOG.info("next: Return vertexId=" + vertex.getId().get() +
", vertexValue=" + vertex.getValue() +
", targetVertexId=" + targetVertexId + ", edgeValue=" + edgeValue);
}
return vertex;
}
示例9: testSuperstepZero
import org.apache.giraph.edge.EdgeFactory; //导入依赖的package包/类
/**
* Test the behavior of the triangle closing algorithm:
* does it send all its out edge values to all neighbors?
*/
@Test
public void testSuperstepZero() throws Exception {
// this guy should end up with an array value of 4
Vertex<IntWritable, IntArrayListWritable, NullWritable> vertex =
new DefaultVertex<IntWritable, IntArrayListWritable, NullWritable>();
IntArrayListWritable alw = new IntArrayListWritable();
SimpleTriangleClosingComputation computation =
new SimpleTriangleClosingComputation();
MockUtils.MockedEnvironment env = MockUtils.prepareVertexAndComputation(
vertex, new IntWritable(1), alw, false, computation, 0L);
vertex.addEdge(EdgeFactory.create(new IntWritable(5)));
vertex.addEdge(EdgeFactory.create(new IntWritable(7)));
computation.compute(vertex, Lists.<IntWritable>newArrayList(
new IntWritable(83), new IntWritable(42)));
env.verifyMessageSentToAllEdges(vertex, new IntWritable(5));
env.verifyMessageSentToAllEdges(vertex, new IntWritable(7));
}
示例10: getCurrentEdge
import org.apache.giraph.edge.EdgeFactory; //导入依赖的package包/类
@Override
public Edge<LongWritable, DoubleWritable> getCurrentEdge()
throws IOException, InterruptedException {
LongWritable destVertexId = new LongWritable();
do {
destVertexId.set(localEdgesHelper.generateDestVertex(
currentVertexId.get(), random));
} while (currentVertexDestVertices.contains(destVertexId));
++currentOutEdgesRead;
currentVertexDestVertices.add(destVertexId);
if (LOG.isTraceEnabled()) {
LOG.trace("getCurrentEdge: Return edge (" + currentVertexId + ", " +
"" + destVertexId + ")");
}
return EdgeFactory.create(
destVertexId,
new DoubleWritable(random.nextDouble()));
}
示例11: parseIntDoubleEdges
import org.apache.giraph.edge.EdgeFactory; //导入依赖的package包/类
/**
* Parse edges as mappings of integer => double (id to weight)
* @param record Hive record to parse
* @param columnIndex offset of column in row
* @return edges
*/
@SuppressWarnings("unchecked")
public static Iterable<Edge<IntWritable, DoubleWritable>> parseIntDoubleEdges(
HiveReadableRecord record, int columnIndex) {
Object edgesObj = record.get(columnIndex);
if (edgesObj == null) {
return ImmutableList.of();
}
Map<Long, Double> readEdges = (Map<Long, Double>) edgesObj;
List<Edge<IntWritable, DoubleWritable>> edges =
Lists.newArrayListWithCapacity(readEdges.size());
for (Map.Entry<Long, Double> entry : readEdges.entrySet()) {
edges.add(EdgeFactory.create(new IntWritable(entry.getKey().intValue()),
new DoubleWritable(entry.getValue())));
}
return edges;
}
示例12: parseLongDoubleEdges
import org.apache.giraph.edge.EdgeFactory; //导入依赖的package包/类
/**
* Parse edges as mappings of long => double (id to weight)
* @param record Hive record to parse
* @param columnIndex offset of column in row
* @return edges
*/
@SuppressWarnings("unchecked")
public static Iterable<Edge<LongWritable, DoubleWritable>>
parseLongDoubleEdges(HiveReadableRecord record, int columnIndex) {
Object edgesObj = record.get(columnIndex);
if (edgesObj == null) {
return ImmutableList.of();
}
Map<Long, Double> readEdges = (Map<Long, Double>) edgesObj;
List<Edge<LongWritable, DoubleWritable>> edges =
Lists.newArrayListWithCapacity(readEdges.size());
for (Map.Entry<Long, Double> entry : readEdges.entrySet()) {
edges.add(EdgeFactory.create(new LongWritable(entry.getKey()),
new DoubleWritable(entry.getValue())));
}
return edges;
}
示例13: testHappyPath
import org.apache.giraph.edge.EdgeFactory; //导入依赖的package包/类
@Test
public void testHappyPath() throws Exception {
String input = "42\t0.1\t99\t0.2\t2000\t0.3\t4000\t0.4";
when(rr.getCurrentValue()).thenReturn(new Text(input));
TextVertexReader vr = createVertexReader(rr);
vr.setConf(conf);
vr.initialize(null, tac);
assertTrue("Should have been able to read vertex", vr.nextVertex());
Vertex<LongWritable, DoubleWritable, DoubleWritable, ?>
vertex = vr.getCurrentVertex();
setGraphState(vertex, graphState);
assertValidVertex(conf, graphState, vertex,
new LongWritable(42), new DoubleWritable(0.1),
EdgeFactory.create(new LongWritable(99), new DoubleWritable(0.2)),
EdgeFactory.create(new LongWritable(2000), new DoubleWritable(0.3)),
EdgeFactory.create(new LongWritable(4000), new DoubleWritable(0.4)));
assertEquals(vertex.getNumEdges(), 3);
}
开发者ID:zfighter,项目名称:giraph-research,代码行数:21,代码来源:TestLongDoubleDoubleAdjacencyListVertexInputFormat.java
示例14: testHappyPath
import org.apache.giraph.edge.EdgeFactory; //导入依赖的package包/类
@Test
public void testHappyPath() throws Exception {
String input = "42\t0.1\t99\t0.2\t2000\t0.3\t4000\t0.4";
when(rr.getCurrentValue()).thenReturn(new Text(input));
TextVertexReader vr = createVertexReader(rr);
vr.setConf(conf);
vr.initialize(null, tac);
assertTrue("Should have been able to read vertex", vr.nextVertex());
Vertex<LongWritable, DoubleWritable, DoubleWritable>
vertex = vr.getCurrentVertex();
assertValidVertex(conf, vertex,
new LongWritable(42), new DoubleWritable(0.1),
EdgeFactory.create(new LongWritable(99), new DoubleWritable(0.2)),
EdgeFactory.create(new LongWritable(2000), new DoubleWritable(0.3)),
EdgeFactory.create(new LongWritable(4000), new DoubleWritable(0.4)));
assertEquals(vertex.getNumEdges(), 3);
}
开发者ID:renato2099,项目名称:giraph-gora,代码行数:20,代码来源:TestLongDoubleDoubleAdjacencyListVertexInputFormat.java
示例15: testDifferentSeparators
import org.apache.giraph.edge.EdgeFactory; //导入依赖的package包/类
@Test
public void testDifferentSeparators() throws Exception {
String input = "12345:42.42:9999999:99.9";
when(rr.getCurrentValue()).thenReturn(new Text(input));
conf.set(AdjacencyListTextVertexInputFormat.LINE_TOKENIZE_VALUE, ":");
TextVertexReader vr = createVertexReader(rr);
vr.setConf(conf);
vr.initialize(null, tac);
assertTrue("Should have been able to read vertex", vr.nextVertex());
Vertex<LongWritable, DoubleWritable, DoubleWritable>
vertex = vr.getCurrentVertex();
assertValidVertex(conf, vertex,
new LongWritable(12345), new DoubleWritable(42.42),
EdgeFactory.create(new LongWritable(9999999), new DoubleWritable(99.9)));
assertEquals(vertex.getNumEdges(), 1);
}
开发者ID:renato2099,项目名称:giraph-gora,代码行数:18,代码来源:TestLongDoubleDoubleAdjacencyListVertexInputFormat.java