Search in sources :

Example 6 with Vertex

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);
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) PartitionStat(com.baidu.hugegraph.computer.core.graph.partition.PartitionStat) Value(com.baidu.hugegraph.computer.core.graph.value.Value) IOException(java.io.IOException) Edges(com.baidu.hugegraph.computer.core.graph.edge.Edges) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException) ComputerOutput(com.baidu.hugegraph.computer.core.output.ComputerOutput)

Example 7 with Vertex

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;
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) Value(com.baidu.hugegraph.computer.core.graph.value.Value) IOException(java.io.IOException) Edges(com.baidu.hugegraph.computer.core.graph.edge.Edges) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 8 with Vertex

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();
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex)

Example 9 with Vertex

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());
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) Test(org.junit.Test)

Example 10 with Vertex

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());
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) Test(org.junit.Test)

Aggregations

Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)46 Test (org.junit.Test)21 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)18 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)16 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)15 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)15 Edges (com.baidu.hugegraph.computer.core.graph.edge.Edges)13 Id (com.baidu.hugegraph.computer.core.graph.id.Id)12 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)11 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)11 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)10 ComputerException (com.baidu.hugegraph.computer.core.common.exception.ComputerException)7 Value (com.baidu.hugegraph.computer.core.graph.value.Value)7 IOException (java.io.IOException)7 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)6 File (java.io.File)6 BooleanValue (com.baidu.hugegraph.computer.core.graph.value.BooleanValue)4 FloatValue (com.baidu.hugegraph.computer.core.graph.value.FloatValue)4 IdList (com.baidu.hugegraph.computer.core.graph.value.IdList)4 ComputerOptions (com.baidu.hugegraph.computer.core.config.ComputerOptions)2