Search in sources :

Example 1 with IdSet

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

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

the class BetweennessCentrality method compute.

@Override
public void compute(ComputationContext context, Vertex vertex, Iterator<BetweennessMessage> messages) {
    BetweennessValue value = vertex.value();
    // The betweenness value to be updated
    DoubleValue betweenness = value.betweenness();
    // Collect the vertices sent here this time
    IdSet arrivingVertices = new IdSet();
    while (messages.hasNext()) {
        BetweennessMessage message = messages.next();
        // The value contributed to the intermediate node on the path
        DoubleValue vote = message.vote();
        betweenness.value(betweenness.value() + vote.value());
        this.forward(context, vertex, message.sequence(), arrivingVertices);
    }
    value.arrivedVertices().addAll(arrivingVertices);
    boolean active = !this.seqTable.isEmpty();
    if (active) {
        this.sendMessage(context);
        this.seqTable.clear();
    } else {
        vertex.inactivate();
    }
}
Also used : IdSet(com.baidu.hugegraph.computer.core.graph.value.IdSet) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue)

Aggregations

IdSet (com.baidu.hugegraph.computer.core.graph.value.IdSet)2 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)1 Id (com.baidu.hugegraph.computer.core.graph.id.Id)1 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)1