use of com.baidu.hugegraph.computer.core.graph.edge.Edges in project hugegraph-computer by hugegraph.
the class FileGraphPartition method compute1.
private long compute1(ComputationContext context) {
Value result = this.context.config().createObject(ComputerOptions.ALGORITHM_RESULT_CLASS);
long activeVertexCount = 0L;
while (this.vertexInput.hasNext()) {
Vertex vertex = this.vertexInput.next();
this.readVertexStatusAndValue(vertex, result);
Iterator<Value> messageIter = this.messageInput.iterator(this.vertexInput.idPointer());
if (messageIter.hasNext()) {
vertex.reactivate();
}
/*
* If the vertex is inactive, it's edges will be skipped
* automatically at the next vertex.
*/
if (vertex.active()) {
Edges edges = this.edgesInput.edges(this.vertexInput.idPointer());
vertex.edges(edges);
this.computation.compute(context, vertex, messageIter);
}
// The vertex status may be changed after computation
if (vertex.active()) {
activeVertexCount++;
}
try {
this.saveVertexStatusAndValue(vertex);
} catch (IOException e) {
throw new ComputerException("Error occurred when saveVertex", e);
}
}
return activeVertexCount;
}
use of com.baidu.hugegraph.computer.core.graph.edge.Edges in project hugegraph-computer by hugegraph.
the class ComputeManagerTest method addSingleFreqEdgeBuffer.
private static void addSingleFreqEdgeBuffer(Consumer<NetworkBuffer> consumer) throws IOException {
for (long i = 0L; i < 200L; i++) {
Vertex vertex = graphFactory().createVertex();
vertex.id(BytesId.of(i));
int count = RANDOM.nextInt(20);
if (count == 0) {
continue;
}
Edges edges = graphFactory().createEdges(count);
for (long j = 0; j < count; j++) {
Edge edge = graphFactory().createEdge();
edge.targetId(BytesId.of(RANDOM.nextInt(200)));
Properties properties = graphFactory().createProperties();
properties.put("p1", new LongValue(i));
edge.properties(properties);
edges.add(edge);
}
vertex.edges(edges);
ReceiverUtil.consumeBuffer(writeEdges(vertex, EdgeFrequency.SINGLE), consumer);
}
}
use of com.baidu.hugegraph.computer.core.graph.edge.Edges in project hugegraph-computer by hugegraph.
the class MockComputation method compute0.
@Override
public void compute0(ComputationContext context, Vertex vertex) {
IdListList value = new IdListList();
vertex.value(value);
Edges edges = vertex.edges();
checkEdgesSize(edges);
checkEdgesSize(edges);
if (RANDOM.nextInt() % 10 == 0) {
vertex.inactivate();
}
}
use of com.baidu.hugegraph.computer.core.graph.edge.Edges in project hugegraph-computer by hugegraph.
the class EdgesInputTest method checkEdgesInput.
private void checkEdgesInput(EdgesInput edgesInput, EdgeFrequency freq) throws IOException {
for (long i = 0L; i < 200L; i += 2) {
Id id = BytesId.of(i);
ReusablePointer idPointer = idToReusablePointer(id);
Edges edges = edgesInput.edges(idPointer);
Iterator<Edge> edgesIt = edges.iterator();
Assert.assertEquals(i, edges.size());
for (int j = 0; j < edges.size(); j++) {
Assert.assertTrue(edgesIt.hasNext());
Edge edge = edgesIt.next();
switch(freq) {
case SINGLE:
Assert.assertEquals(BytesId.of(j), edge.targetId());
break;
case SINGLE_PER_LABEL:
Assert.assertEquals(BytesId.of(j), edge.targetId());
Assert.assertEquals(String.valueOf(j), edge.label());
break;
case MULTIPLE:
Assert.assertEquals(BytesId.of(j), edge.targetId());
Assert.assertEquals(String.valueOf(j), edge.label());
Assert.assertEquals(String.valueOf(j), edge.name());
break;
default:
throw new ComputerException("Illegal edge frequency %s", freq);
}
}
Assert.assertFalse(edgesIt.hasNext());
}
}
use of com.baidu.hugegraph.computer.core.graph.edge.Edges in project hugegraph-computer by hugegraph.
the class EdgesInputTest method addEdgeBuffer.
private static void addEdgeBuffer(Consumer<NetworkBuffer> consumer, EdgeFrequency freq) throws IOException {
for (long i = 0L; i < 200L; i++) {
Vertex vertex = graphFactory().createVertex();
vertex.id(BytesId.of(i));
int count = (int) i;
if (count == 0) {
continue;
}
Edges edges = graphFactory().createEdges(count);
for (long j = 0; j < count; j++) {
Edge edge = graphFactory().createEdge();
switch(freq) {
case SINGLE:
edge.targetId(BytesId.of(j));
break;
case SINGLE_PER_LABEL:
edge.label(String.valueOf(j));
edge.targetId(BytesId.of(j));
break;
case MULTIPLE:
edge.name(String.valueOf(j));
edge.label(String.valueOf(j));
edge.targetId(BytesId.of(j));
break;
default:
throw new ComputerException("Illegal edge frequency %s", freq);
}
Properties properties = graphFactory().createProperties();
properties.put("p1", new LongValue(i));
edge.properties(properties);
edges.add(edge);
}
vertex.edges(edges);
ReceiverUtil.consumeBuffer(writeEdges(vertex, freq), consumer);
}
}
Aggregations