Search in sources :

Example 16 with IdList

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

the class RingsDetection method compute0.

@Override
public void compute0(ComputationContext context, Vertex vertex) {
    vertex.value(new IdListList());
    if (vertex.edges().size() == 0) {
        return;
    }
    // Init path
    Id id = vertex.id();
    IdList path = new IdList();
    path.add(id);
    for (Edge edge : vertex.edges()) {
        /*
             * Only send path to vertex whose id is larger than
             * or equals current vertex id
             */
        if (id.compareTo(edge.targetId()) <= 0) {
            context.sendMessage(edge.targetId(), path);
        }
    }
}
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)

Example 17 with IdList

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

the class TriangleCount method compute0.

@Override
public void compute0(ComputationContext context, Vertex vertex) {
    IdList selfId = new IdList();
    selfId.add(vertex.id());
    context.sendMessageToAllEdgesIf(vertex, selfId, (ids, targetId) -> {
        return !ids.get(0).equals(targetId);
    });
    vertex.value(new TriangleCountValue());
}
Also used : IdList(com.baidu.hugegraph.computer.core.graph.value.IdList)

Example 18 with IdList

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

the class RingsDetectionWithFilter method compute.

@Override
public void compute(ComputationContext context, Vertex vertex, Iterator<RingsDetectionMessage> messages) {
    boolean halt = true;
    if (this.filter.filter(vertex)) {
        Id vertexId = vertex.id();
        while (messages.hasNext()) {
            halt = false;
            RingsDetectionMessage message = messages.next();
            IdList path = message.path();
            if (vertexId.equals(path.get(0))) {
                // Use the smallest vertex record ring
                boolean isMin = true;
                for (int i = 0; i < path.size(); i++) {
                    Id pathVertexValue = path.get(i);
                    if (vertexId.compareTo(pathVertexValue) > 0) {
                        isMin = false;
                        break;
                    }
                }
                if (isMin) {
                    path.add(vertexId);
                    IdListList value = vertex.value();
                    value.add(path.copy());
                }
            } else {
                boolean contains = false;
                // Drop sequence if path contains this vertex
                for (int i = 0; i < path.size(); i++) {
                    Id pathVertexValue = path.get(i);
                    if (pathVertexValue.equals(vertex.id())) {
                        contains = true;
                        break;
                    }
                }
                if (!contains) {
                    path.add(vertex.id());
                    for (Edge edge : vertex.edges()) {
                        if (this.filter.filter(edge, message)) {
                            message.walkEdgeProp(edge.properties());
                            context.sendMessage(edge.targetId(), message);
                        }
                    }
                }
            }
        }
    }
    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)

Example 19 with IdList

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

the class ComputeMessageRecvPartitionTest method addTwentyDuplicateIdValueListMessageBuffer.

private static void addTwentyDuplicateIdValueListMessageBuffer(Consumer<ManagedBuffer> consumer) throws IOException {
    for (long i = 0L; i < 10L; i++) {
        for (int j = 0; j < 2; j++) {
            Id id = BytesId.of(i);
            IdList message = new IdList();
            message.add(id);
            ReceiverUtil.consumeBuffer(ReceiverUtil.writeMessage(id, message), consumer);
        }
    }
}
Also used : Id(com.baidu.hugegraph.computer.core.graph.id.Id) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) IdList(com.baidu.hugegraph.computer.core.graph.value.IdList)

Example 20 with IdList

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

the class MessageInputTest method addMessages.

private static void addMessages(Consumer<ManagedBuffer> consumer) throws IOException {
    Random random = new Random(1);
    for (long i = 0L; i < 200L; i++) {
        int count = random.nextInt(5);
        for (int j = 0; j < count; j++) {
            Id id = BytesId.of(random.nextInt(200));
            IdList message = new IdList();
            message.add(id);
            ReceiverUtil.consumeBuffer(ReceiverUtil.writeMessage(id, message), consumer);
        }
    }
}
Also used : Random(java.util.Random) 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) IdList(com.baidu.hugegraph.computer.core.graph.value.IdList)

Aggregations

IdList (com.baidu.hugegraph.computer.core.graph.value.IdList)20 Id (com.baidu.hugegraph.computer.core.graph.id.Id)18 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)14 IdListList (com.baidu.hugegraph.computer.core.graph.value.IdListList)7 ConnectionId (com.baidu.hugegraph.computer.core.network.ConnectionId)7 Test (org.junit.Test)5 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)4 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)4 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)4 File (java.io.File)4 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)3 Random (java.util.Random)3 BooleanValue (com.baidu.hugegraph.computer.core.graph.value.BooleanValue)2 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)2 FloatValue (com.baidu.hugegraph.computer.core.graph.value.FloatValue)2 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)2 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)2 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2