Search in sources :

Example 6 with Edge

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

the class ComputeManagerTest method addSingleFreqEdgeBuffer.

private static void addSingleFreqEdgeBuffer(Consumer<NetworkBuffer> 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 7 with Edge

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

the class MockComputation method checkEdgesSize.

private static void checkEdgesSize(Edges edges) {
    int edgeSize = edges.size();
    int edgeIterSize = 0;
    for (@SuppressWarnings("unused") Edge edge : edges) {
        edgeIterSize++;
    }
    Assert.assertEquals(edgeSize, edgeIterSize);
}
Also used : Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge)

Example 8 with Edge

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

the class EdgesInputTest method checkEdgesInput.

private void checkEdgesInput(EdgesInput edgesInput, EdgeFrequency freq) throws IOException {
    for (long i = 0L; i < 200L; i += 2) {
        Id id = BytesId.of(i);
        ReusablePointer idPointer = idToReusablePointer(id);
        Edges edges = edgesInput.edges(idPointer);
        Iterator<Edge> edgesIt = edges.iterator();
        Assert.assertEquals(i, edges.size());
        for (int j = 0; j < edges.size(); j++) {
            Assert.assertTrue(edgesIt.hasNext());
            Edge edge = edgesIt.next();
            switch(freq) {
                case SINGLE:
                    Assert.assertEquals(BytesId.of(j), edge.targetId());
                    break;
                case SINGLE_PER_LABEL:
                    Assert.assertEquals(BytesId.of(j), edge.targetId());
                    Assert.assertEquals(String.valueOf(j), edge.label());
                    break;
                case MULTIPLE:
                    Assert.assertEquals(BytesId.of(j), edge.targetId());
                    Assert.assertEquals(String.valueOf(j), edge.label());
                    Assert.assertEquals(String.valueOf(j), edge.name());
                    break;
                default:
                    throw new ComputerException("Illegal edge frequency %s", freq);
            }
        }
        Assert.assertFalse(edgesIt.hasNext());
    }
}
Also used : Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) ConnectionId(com.baidu.hugegraph.computer.core.network.ConnectionId) Edges(com.baidu.hugegraph.computer.core.graph.edge.Edges) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 9 with Edge

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

the class EdgesInputTest method addEdgeBuffer.

private static void addEdgeBuffer(Consumer<NetworkBuffer> consumer, EdgeFrequency freq) throws IOException {
    for (long i = 0L; i < 200L; i++) {
        Vertex vertex = graphFactory().createVertex();
        vertex.id(BytesId.of(i));
        int count = (int) i;
        if (count == 0) {
            continue;
        }
        Edges edges = graphFactory().createEdges(count);
        for (long j = 0; j < count; j++) {
            Edge edge = graphFactory().createEdge();
            switch(freq) {
                case SINGLE:
                    edge.targetId(BytesId.of(j));
                    break;
                case SINGLE_PER_LABEL:
                    edge.label(String.valueOf(j));
                    edge.targetId(BytesId.of(j));
                    break;
                case MULTIPLE:
                    edge.name(String.valueOf(j));
                    edge.label(String.valueOf(j));
                    edge.targetId(BytesId.of(j));
                    break;
                default:
                    throw new ComputerException("Illegal edge frequency %s", freq);
            }
            Properties properties = graphFactory().createProperties();
            properties.put("p1", new LongValue(i));
            edge.properties(properties);
            edges.add(edge);
        }
        vertex.edges(edges);
        ReceiverUtil.consumeBuffer(writeEdges(vertex, freq), 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) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 10 with Edge

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

the class RingsDetection method compute.

@Override
public void compute(ComputationContext context, Vertex vertex, Iterator<IdList> messages) {
    Id id = vertex.id();
    boolean halt = true;
    while (messages.hasNext()) {
        halt = false;
        IdList sequence = messages.next();
        if (id.equals(sequence.get(0))) {
            // Use the smallest vertex record ring
            boolean isMin = true;
            for (int i = 1; i < sequence.size(); i++) {
                Id pathVertexValue = sequence.get(i);
                if (id.compareTo(pathVertexValue) > 0) {
                    isMin = false;
                    break;
                }
            }
            if (isMin) {
                sequence.add(id);
                IdListList sequences = vertex.value();
                sequences.add(sequence);
            }
        } else {
            boolean contains = false;
            // Drop sequence if path contains this vertex
            for (int i = 0; i < sequence.size(); i++) {
                Id pathVertexValue = sequence.get(i);
                if (pathVertexValue.equals(vertex.id())) {
                    contains = true;
                    break;
                }
            }
            // Field ringId is smallest vertex id in path
            Id ringId = sequence.get(0);
            if (!contains) {
                sequence.add(vertex.id());
                for (Edge edge : vertex.edges()) {
                    if (ringId.compareTo(edge.targetId()) <= 0) {
                        context.sendMessage(edge.targetId(), sequence);
                    }
                }
            }
        }
    }
    if (halt) {
        vertex.inactivate();
    }
}
Also used : Id(com.baidu.hugegraph.computer.core.graph.id.Id) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge) IdList(com.baidu.hugegraph.computer.core.graph.value.IdList) IdListList(com.baidu.hugegraph.computer.core.graph.value.IdListList)

Aggregations

Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)28 Id (com.baidu.hugegraph.computer.core.graph.id.Id)12 Edges (com.baidu.hugegraph.computer.core.graph.edge.Edges)11 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)11 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)10 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)8 ComputerException (com.baidu.hugegraph.computer.core.common.exception.ComputerException)5 IdListList (com.baidu.hugegraph.computer.core.graph.value.IdListList)4 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)3 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)3 IdList (com.baidu.hugegraph.computer.core.graph.value.IdList)3 IOException (java.io.IOException)3 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)2 ComputerOptions (com.baidu.hugegraph.computer.core.config.ComputerOptions)2 EdgeFrequency (com.baidu.hugegraph.computer.core.config.EdgeFrequency)2 Value (com.baidu.hugegraph.computer.core.graph.value.Value)2 EntryOutput (com.baidu.hugegraph.computer.core.store.entry.EntryOutput)2 KvEntryWriter (com.baidu.hugegraph.computer.core.store.entry.KvEntryWriter)2 Config (com.baidu.hugegraph.computer.core.config.Config)1 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)1