Search in sources :

Example 21 with Edge

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

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

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

the class ComputationContext method sendMessagesToAllEdgesIf.

/**
 * Send all values to filtered adjacent vertices of specified vertex. The
 * filtered adjacent vertices of specified vertex will receive the values
 * at next superstep.
 */
default <M extends Value> void sendMessagesToAllEdgesIf(Vertex vertex, Iterator<M> values, BiFunction<M, Id, Boolean> filter) {
    while (values.hasNext()) {
        M value = values.next();
        Iterator<Edge> edges = vertex.edges().iterator();
        while (edges.hasNext()) {
            Edge edge = edges.next();
            if (filter.apply(value, edge.targetId())) {
                this.sendMessage(edge.targetId(), value);
            }
        }
    }
}
Also used : Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge)

Example 24 with Edge

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

the class ComputationContext method sendMessageToAllEdges.

/**
 * Send value to all adjacent vertices of specified vertex. The adjacent
 * vertices of specified vertex will receive the value at next superstep.
 */
default void sendMessageToAllEdges(Vertex vertex, Value value) {
    Iterator<Edge> edges = vertex.edges().iterator();
    while (edges.hasNext()) {
        Edge edge = edges.next();
        this.sendMessage(edge.targetId(), value);
    }
}
Also used : Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge)

Example 25 with Edge

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

the class StreamGraphInput method readEdges.

@Override
public Vertex readEdges() throws IOException {
    Vertex vertex = this.graphFactory.createVertex();
    KvEntryReader reader = this.in.readEntry(in -> {
        // Read id
        vertex.id(readId(in));
    });
    if (this.frequency == EdgeFrequency.SINGLE) {
        while (reader.hasRemaining()) {
            Edge edge = this.graphFactory.createEdge();
            // Only use targetId as subKey, use properties as subValue
            reader.readSubKv(in -> {
                edge.targetId(readId(in));
            }, in -> {
                edge.properties(readProperties(in));
            });
            vertex.addEdge(edge);
        }
    } else if (this.frequency == EdgeFrequency.SINGLE_PER_LABEL) {
        while (reader.hasRemaining()) {
            Edge edge = this.graphFactory.createEdge();
            // Use label + targetId as subKey, use properties as subValue
            reader.readSubKv(in -> {
                edge.label(readLabel(in));
                edge.targetId(readId(in));
            }, in -> {
                edge.properties(readProperties(in));
            });
            vertex.addEdge(edge);
        }
    } else {
        assert this.frequency == EdgeFrequency.MULTIPLE;
        while (reader.hasRemaining()) {
            Edge edge = this.graphFactory.createEdge();
            /*
                 * Use label + sortValues + targetId as subKey,
                 * use properties as subValue
                 */
            reader.readSubKv(in -> {
                edge.label(readLabel(in));
                edge.name(readLabel(in));
                edge.targetId(readId(in));
            }, in -> {
                edge.properties(this.readProperties(in));
            });
            vertex.addEdge(edge);
        }
    }
    return vertex;
}
Also used : ComputerOptions(com.baidu.hugegraph.computer.core.config.ComputerOptions) Id(com.baidu.hugegraph.computer.core.graph.id.Id) EntryInput(com.baidu.hugegraph.computer.core.store.entry.EntryInput) EdgeFrequency(com.baidu.hugegraph.computer.core.config.EdgeFrequency) Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) IOException(java.io.IOException) BytesId(com.baidu.hugegraph.computer.core.graph.id.BytesId) GraphFactory(com.baidu.hugegraph.computer.core.graph.GraphFactory) Config(com.baidu.hugegraph.computer.core.config.Config) Value(com.baidu.hugegraph.computer.core.graph.value.Value) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Pair(org.apache.commons.lang3.tuple.Pair) KvEntryReader(com.baidu.hugegraph.computer.core.store.entry.KvEntryReader) ComputerContext(com.baidu.hugegraph.computer.core.common.ComputerContext) Vertex(com.baidu.hugegraph.computer.core.graph.vertex.Vertex) KvEntryReader(com.baidu.hugegraph.computer.core.store.entry.KvEntryReader) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge)

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