Search in sources :

Example 11 with Edges

use of com.baidu.hugegraph.computer.core.graph.edge.Edges in project hugegraph-computer by hugegraph.

the class EdgeMessageRecvPartitionTest method addTenDuplicateEdgeBuffer.

private static void addTenDuplicateEdgeBuffer(Consumer<NetworkBuffer> 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)

Example 12 with Edges

use of com.baidu.hugegraph.computer.core.graph.edge.Edges in project hugegraph-computer by hugegraph.

the class EdgeMessageRecvPartitionTest method addTenEdgeBuffer.

public static void addTenEdgeBuffer(Consumer<NetworkBuffer> 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 13 with Edges

use of com.baidu.hugegraph.computer.core.graph.edge.Edges in project hugegraph-computer by hugegraph.

the class TriangleCount method getOutNeighbors.

private static Set<Id> getOutNeighbors(Vertex vertex) {
    Set<Id> outNeighbors = new HashSet<>();
    Edges edges = vertex.edges();
    for (Edge edge : edges) {
        Id targetId = edge.targetId();
        if (!vertex.id().equals(targetId)) {
            outNeighbors.add(targetId);
        }
    }
    return outNeighbors;
}
Also used : Id(com.baidu.hugegraph.computer.core.graph.id.Id) Edges(com.baidu.hugegraph.computer.core.graph.edge.Edges) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge) HashSet(java.util.HashSet)

Example 14 with Edges

use of com.baidu.hugegraph.computer.core.graph.edge.Edges 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 15 with Edges

use of com.baidu.hugegraph.computer.core.graph.edge.Edges in project hugegraph-computer by hugegraph.

the class EdgesInput method edges.

public Edges edges(ReusablePointer vidPointer) {
    try {
        while (this.input.available() > 0) {
            long startPosition = this.input.position();
            this.idPointer.read(this.input);
            int status = vidPointer.compareTo(this.idPointer);
            if (status < 0) {
                // No edges
                /*
                     * The current batch belong to vertex that vertex id is
                     * bigger than specified id.
                     */
                this.input.seek(startPosition);
                return EmptyEdges.instance();
            } else if (status == 0) {
                // Has edges
                this.valuePointer.read(this.input);
                Edges edges = this.readEdges(this.valuePointer.input());
                if (edges.size() < this.flushThreshold) {
                    return edges;
                } else {
                    return new SuperEdges(vidPointer, edges, startPosition);
                }
            } else {
                /*
                     * The current batch belong to vertex that vertex id is
                     * smaller than specified id.
                     */
                int valueLength = this.input.readFixedInt();
                this.input.skip(valueLength);
            }
        }
        return EmptyEdges.instance();
    } catch (IOException e) {
        throw new ComputerException("Can't read from edges input '%s'", e, this.edgeFile.getAbsoluteFile());
    }
}
Also used : IOException(java.io.IOException) Edges(com.baidu.hugegraph.computer.core.graph.edge.Edges) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Aggregations

Edges (com.baidu.hugegraph.computer.core.graph.edge.Edges)18 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)13 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)11 ComputerException (com.baidu.hugegraph.computer.core.common.exception.ComputerException)10 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)9 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)8 IOException (java.io.IOException)7 Value (com.baidu.hugegraph.computer.core.graph.value.Value)3 Id (com.baidu.hugegraph.computer.core.graph.id.Id)2 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)1 PartitionStat (com.baidu.hugegraph.computer.core.graph.partition.PartitionStat)1 IdListList (com.baidu.hugegraph.computer.core.graph.value.IdListList)1 ConnectionId (com.baidu.hugegraph.computer.core.network.ConnectionId)1 ComputerOutput (com.baidu.hugegraph.computer.core.output.ComputerOutput)1 HashSet (java.util.HashSet)1