Search in sources :

Example 6 with IdListList

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

the class MockComputation method compute.

@Override
public void compute(ComputationContext context, Vertex vertex, Iterator<IdList> messages) {
    IdListList value = vertex.value();
    while (messages.hasNext()) {
        Assert.assertTrue(messages.hasNext());
        value.add(messages.next().copy());
    }
    Assert.assertFalse(messages.hasNext());
    if (RANDOM.nextInt() % 10 == 0) {
        vertex.inactivate();
    }
}
Also used : IdListList(com.baidu.hugegraph.computer.core.graph.value.IdListList)

Example 7 with IdListList

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

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

the class RingsDetectionWithFilter method compute0.

@Override
public void compute0(ComputationContext context, Vertex vertex) {
    vertex.value(new IdListList());
    if (vertex.edges().size() == 0 || !this.filter.filter(vertex)) {
        return;
    }
    RingsDetectionMessage message = new RingsDetectionMessage();
    message.addPath(vertex);
    for (Edge edge : vertex.edges()) {
        if (this.filter.filter(edge)) {
            message.walkEdgeProp(edge.properties());
            context.sendMessage(edge.targetId(), message);
        }
    }
}
Also used : Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge) IdListList(com.baidu.hugegraph.computer.core.graph.value.IdListList)

Example 9 with IdListList

use of com.baidu.hugegraph.computer.core.graph.value.IdListList 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)

Aggregations

IdListList (com.baidu.hugegraph.computer.core.graph.value.IdListList)9 Id (com.baidu.hugegraph.computer.core.graph.id.Id)5 IdList (com.baidu.hugegraph.computer.core.graph.value.IdList)5 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)4 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)2 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)2 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)2 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 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)2 File (java.io.File)2 Test (org.junit.Test)2 Edges (com.baidu.hugegraph.computer.core.graph.edge.Edges)1 ArrayList (java.util.ArrayList)1