use of com.baidu.hugegraph.computer.core.graph.vertex.Vertex in project hugegraph-computer by hugegraph.
the class FileGraphPartition method output.
protected PartitionStat output() {
ComputerOutput output = this.context.config().createObject(ComputerOptions.OUTPUT_CLASS);
output.init(this.context.config(), this.partition);
try {
this.beforeOutput();
} catch (IOException e) {
throw new ComputerException("Error occurred when beforeOutput", e);
}
Value result = this.context.config().createObject(ComputerOptions.ALGORITHM_RESULT_CLASS);
while (this.vertexInput.hasNext()) {
Vertex vertex = this.vertexInput.next();
this.readVertexStatusAndValue(vertex, result);
Edges edges = this.edgesInput.edges(this.vertexInput.idPointer());
vertex.edges(edges);
output.write(vertex);
}
try {
this.afterOutput();
} catch (IOException e) {
throw new ComputerException("Error occurred when afterOutput", e);
}
output.close();
return new PartitionStat(this.partition, this.vertexCount, this.edgeCount, 0L);
}
use of com.baidu.hugegraph.computer.core.graph.vertex.Vertex 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.vertex.Vertex in project hugegraph-computer by hugegraph.
the class WorkerInputManager method loadGraph.
/**
* TODO: Load vertices and edges parallel.
* When this method finish, it means that all vertices and edges are sent,
* but there is no guarantee that all of them has been received.
*/
public void loadGraph() {
this.sendManager.startSend(MessageType.VERTEX);
Iterator<Vertex> iterator = this.loadService.createIteratorFromVertex();
while (iterator.hasNext()) {
Vertex vertex = iterator.next();
this.sendManager.sendVertex(vertex);
}
this.sendManager.finishSend(MessageType.VERTEX);
this.sendManager.startSend(MessageType.EDGE);
iterator = this.loadService.createIteratorFromEdge();
while (iterator.hasNext()) {
Vertex vertex = iterator.next();
this.sendManager.sendEdge(vertex);
}
this.sendManager.finishSend(MessageType.EDGE);
this.sendManager.clearBuffer();
}
use of com.baidu.hugegraph.computer.core.graph.vertex.Vertex in project hugegraph-computer by hugegraph.
the class WriteBufferTest method testReachThreshold.
@Test
public void testReachThreshold() throws IOException {
WriteBuffer buffer = new WriteBuffer(context, 20, 50);
Assert.assertFalse(buffer.reachThreshold());
Vertex vertex = context.graphFactory().createVertex(BytesId.of(1L), new DoubleValue(0.5d));
// After write, the position is 11
buffer.writeVertex(vertex);
Assert.assertFalse(buffer.reachThreshold());
// After write, the position is 22
buffer.writeVertex(vertex);
Assert.assertTrue(buffer.reachThreshold());
// After write, the position is 33
buffer.writeVertex(vertex);
Assert.assertTrue(buffer.reachThreshold());
}
use of com.baidu.hugegraph.computer.core.graph.vertex.Vertex in project hugegraph-computer by hugegraph.
the class WriteBuffersTest method testReachThreshold.
@Test
public void testReachThreshold() throws IOException {
WriteBuffers buffers = new WriteBuffers(context(), 20, 50);
Assert.assertFalse(buffers.reachThreshold());
Vertex vertex = context().graphFactory().createVertex(BytesId.of(1L), new DoubleValue(0.5d));
// After write, the position is 11
buffers.writeVertex(vertex);
Assert.assertFalse(buffers.reachThreshold());
// After write, the position is 22
buffers.writeVertex(vertex);
Assert.assertTrue(buffers.reachThreshold());
// After write, the position is 33
buffers.writeVertex(vertex);
Assert.assertTrue(buffers.reachThreshold());
}
Aggregations