Search in sources :

Example 41 with Vertex

use of com.baidu.hugegraph.computer.core.graph.vertex.Vertex in project hugegraph-computer by hugegraph.

the class FileGraphPartition method compute0.

private long compute0(ComputationContext context) {
    long activeVertexCount = 0L;
    while (this.vertexInput.hasNext()) {
        Vertex vertex = this.vertexInput.next();
        vertex.reactivate();
        Edges edges = this.edgesInput.edges(this.vertexInput.idPointer());
        vertex.edges(edges);
        this.computation.compute0(context, vertex);
        if (vertex.active()) {
            activeVertexCount++;
        }
        try {
            this.saveVertexStatusAndValue(vertex);
        } catch (IOException e) {
            throw new ComputerException("Error occurred when saveVertex: %s", e, vertex);
        }
    }
    return activeVertexCount;
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) IOException(java.io.IOException) Edges(com.baidu.hugegraph.computer.core.graph.edge.Edges) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 42 with Vertex

use of com.baidu.hugegraph.computer.core.graph.vertex.Vertex in project hugegraph-computer by hugegraph.

the class EdgesInputTest method add200VertexBuffer.

private static void add200VertexBuffer(Consumer<ManagedBuffer> consumer) throws IOException {
    for (long i = 0L; i < 200L; i += 2) {
        Vertex vertex = graphFactory().createVertex();
        vertex.id(BytesId.of(i));
        vertex.properties(graphFactory().createProperties());
        ReceiverUtil.consumeBuffer(writeVertex(vertex), consumer);
    }
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex)

Example 43 with Vertex

use of com.baidu.hugegraph.computer.core.graph.vertex.Vertex in project hugegraph-computer by hugegraph.

the class ComputeManagerTest method addSingleFreqEdgeBuffer.

private static void addSingleFreqEdgeBuffer(Consumer<ManagedBuffer> 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);
    }
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) Edges(com.baidu.hugegraph.computer.core.graph.edge.Edges) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge)

Example 44 with Vertex

use of com.baidu.hugegraph.computer.core.graph.vertex.Vertex in project hugegraph-computer by hugegraph.

the class EdgeMessageRecvPartitionTest method addTenEdgeBuffer.

public static void addTenEdgeBuffer(Consumer<ManagedBuffer> consumer) throws IOException {
    for (long i = 0L; i < 10L; i++) {
        Vertex vertex = graphFactory().createVertex();
        vertex.id(BytesId.of(i));
        Edges edges = graphFactory().createEdges(2);
        for (long j = i + 1; j < i + 3; j++) {
            Edge edge = graphFactory().createEdge();
            edge.targetId(BytesId.of(j));
            Properties properties = graphFactory().createProperties();
            properties.put("p1", new LongValue(i));
            edge.properties(properties);
            edges.add(edge);
        }
        vertex.edges(edges);
        ReceiverUtil.consumeBuffer(writeEdges(vertex), consumer);
    }
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) Edges(com.baidu.hugegraph.computer.core.graph.edge.Edges) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge)

Example 45 with Vertex

use of com.baidu.hugegraph.computer.core.graph.vertex.Vertex in project hugegraph-computer by hugegraph.

the class EdgeMessageRecvPartitionTest method addTenDuplicateEdgeBuffer.

private static void addTenDuplicateEdgeBuffer(Consumer<ManagedBuffer> consumer) throws IOException {
    for (long i = 0L; i < 10L; i++) {
        Vertex vertex = graphFactory().createVertex();
        vertex.id(BytesId.of(i));
        Edges edges = graphFactory().createEdges(2);
        for (long j = i + 1; j < i + 3; j++) {
            Edge edge = graphFactory().createEdge();
            edge.targetId(BytesId.of(j));
            Properties properties = graphFactory().createProperties();
            properties.put("p1", new LongValue(i));
            edge.properties(properties);
            edges.add(edge);
        }
        vertex.edges(edges);
        ReceiverUtil.consumeBuffer(writeEdges(vertex), consumer);
    }
    for (long i = 0L; i < 10L; i++) {
        Vertex vertex = graphFactory().createVertex();
        vertex.id(BytesId.of(i));
        Edges edges = graphFactory().createEdges(2);
        for (long j = i + 1; j < i + 3; j++) {
            Edge edge = graphFactory().createEdge();
            edge.targetId(BytesId.of(j));
            Properties properties = graphFactory().createProperties();
            properties.put("p2", new LongValue(2L * i));
            edge.properties(properties);
            edges.add(edge);
        }
        vertex.edges(edges);
        ReceiverUtil.consumeBuffer(writeEdges(vertex), consumer);
    }
}
Also used : Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) Edges(com.baidu.hugegraph.computer.core.graph.edge.Edges) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge)

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