Search in sources :

Example 1 with Value

use of com.baidu.hugegraph.computer.core.graph.value.Value in project hugegraph-computer by hugegraph.

the class FileGraphPartition method compute1.

private long compute1(ComputationContext context, Computation<M> computation, int superstep) {
    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<M> 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);
            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 2 with Value

use of com.baidu.hugegraph.computer.core.graph.value.Value 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 3 with Value

use of com.baidu.hugegraph.computer.core.graph.value.Value in project hugegraph-computer by hugegraph.

the class FileGraphPartition method saveVertexStatusAndValue.

private void saveVertexStatusAndValue(Vertex vertex) throws IOException {
    this.curStatusOutput.writeBoolean(vertex.active());
    Value value = vertex.value();
    E.checkNotNull(value, "Vertex's value can't be null");
    value.write(this.curValueOutput);
}
Also used : Value(com.baidu.hugegraph.computer.core.graph.value.Value)

Example 4 with Value

use of com.baidu.hugegraph.computer.core.graph.value.Value 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 5 with Value

use of com.baidu.hugegraph.computer.core.graph.value.Value in project hugegraph-computer by hugegraph.

the class DefaultProperties method read.

@Override
public void read(RandomAccessInput in) throws IOException {
    this.keyValues.clear();
    int size = in.readInt();
    for (int i = 0; i < size; i++) {
        String key = in.readUTF();
        ValueType valueType = SerialEnum.fromCode(ValueType.class, in.readByte());
        Value value = this.graphFactory.createValue(valueType);
        value.read(in);
        this.keyValues.put(key, value);
    }
}
Also used : ValueType(com.baidu.hugegraph.computer.core.graph.value.ValueType) Value(com.baidu.hugegraph.computer.core.graph.value.Value)

Aggregations

Value (com.baidu.hugegraph.computer.core.graph.value.Value)19 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)7 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)7 Test (org.junit.Test)6 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)5 ComputerException (com.baidu.hugegraph.computer.core.common.exception.ComputerException)3 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)3 Edges (com.baidu.hugegraph.computer.core.graph.edge.Edges)3 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)3 Id (com.baidu.hugegraph.computer.core.graph.id.Id)3 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)3 BooleanValue (com.baidu.hugegraph.computer.core.graph.value.BooleanValue)3 FloatValue (com.baidu.hugegraph.computer.core.graph.value.FloatValue)3 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)3 IOException (java.io.IOException)3 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)2 Config (com.baidu.hugegraph.computer.core.config.Config)2 DefaultProperties (com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties)2 ListValue (com.baidu.hugegraph.computer.core.graph.value.ListValue)2 BytesInput (com.baidu.hugegraph.computer.core.io.BytesInput)2