Search in sources :

Example 16 with Edge

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

the class BetweennessCentrality method forward.

private void forward(ComputationContext context, Vertex vertex, IdList sequence, IdSet arrivingVertices) {
    if (sequence.size() == 0) {
        return;
    }
    BetweennessValue value = vertex.value();
    IdSet arrivedVertices = value.arrivedVertices();
    Id source = sequence.get(0);
    // The source vertex is arriving at first time
    if (!arrivedVertices.contains(source)) {
        arrivingVertices.add(source);
        SeqCount seqCount = this.seqTable.computeIfAbsent(source, k -> new SeqCount());
        seqCount.totalCount++;
        // Accumulate the number of shortest paths for intermediate vertices
        for (int i = 1; i < sequence.size(); i++) {
            Id id = sequence.get(i);
            Map<Id, Integer> idCounts = seqCount.idCount;
            idCounts.put(id, idCounts.getOrDefault(id, 0) + 1);
        }
        Id selfId = vertex.id();
        sequence.add(selfId);
        BetweennessMessage newMessage = new BetweennessMessage(sequence);
        for (Edge edge : vertex.edges()) {
            Id targetId = edge.targetId();
            if (this.sample(selfId, targetId, edge) && !sequence.contains(targetId)) {
                context.sendMessage(targetId, newMessage);
            }
        }
    }
}
Also used : IdSet(com.baidu.hugegraph.computer.core.graph.value.IdSet) Id(com.baidu.hugegraph.computer.core.graph.id.Id) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge)

Example 17 with Edge

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

the class ClosenessCentrality method sendMessage.

private void sendMessage(ComputationContext context, Vertex vertex, Id senderId, Id startId, DoubleValue newValue) {
    Id selfId = vertex.id();
    double baseNewValue = this.weightValue(newValue);
    for (Edge edge : vertex.edges()) {
        Id targetId = edge.targetId();
        if (senderId.equals(targetId) || startId.equals(targetId)) {
            continue;
        }
        if (!sample(selfId, targetId, edge)) {
            continue;
        }
        // Update distance information
        double updatedValue = baseNewValue + this.weightValue(edge.property(this.weightProp));
        DoubleValue newDistance = new DoubleValue(updatedValue);
        ClosenessMessage message = new ClosenessMessage(selfId, startId, newDistance);
        context.sendMessage(targetId, message);
    }
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) Id(com.baidu.hugegraph.computer.core.graph.id.Id) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge)

Example 18 with Edge

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

the class Wcc method compute0.

@Override
public void compute0(ComputationContext context, Vertex vertex) {
    Id min = vertex.id();
    for (Edge edge : vertex.edges()) {
        if (edge.targetId().compareTo(min) < 0) {
            min = edge.targetId();
        }
    }
    Id value = min;
    vertex.value(value);
    vertex.inactivate();
    context.sendMessageToAllEdgesIf(vertex, value, (result, target) -> {
        return result.compareTo(target) < 0;
    });
}
Also used : Id(com.baidu.hugegraph.computer.core.graph.id.Id) Edge(com.baidu.hugegraph.computer.core.graph.edge.Edge)

Example 19 with Edge

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

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

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