Search in sources :

Example 46 with DoubleValue

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

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

the class ClosenessCentrality method compute.

@Override
public void compute(ComputationContext context, Vertex vertex, Iterator<ClosenessMessage> messages) {
    Id selfId = vertex.id();
    // Save the distance from other vertices to self
    ClosenessValue localValue = vertex.value();
    boolean active = false;
    while (messages.hasNext()) {
        active = true;
        ClosenessMessage message = messages.next();
        Id senderId = message.senderId();
        // In theory, it won't happen, defensive programming
        if (selfId.equals(senderId)) {
            continue;
        }
        Id startId = message.startId();
        if (selfId.equals(startId)) {
            continue;
        }
        DoubleValue oldValue = localValue.get(startId);
        DoubleValue newValue = message.distance();
        // If the id already exists and the new value >= old value, skip it
        if (oldValue != null && newValue.compareTo(oldValue) >= 0) {
            continue;
        }
        // Update local saved values (take smaller value)
        localValue.put(startId, newValue);
        // Send this smaller value to neighbors
        this.sendMessage(context, vertex, senderId, startId, newValue);
    }
    if (!active) {
        vertex.inactivate();
    }
}
Also used : DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) Id(com.baidu.hugegraph.computer.core.graph.id.Id)

Example 48 with DoubleValue

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

Example 49 with DoubleValue

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

the class ComputeMessageRecvPartitionTest method addTwentyCombineMessageBuffer.

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

Aggregations

DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)49 Test (org.junit.Test)28 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)21 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)14 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)13 FloatValue (com.baidu.hugegraph.computer.core.graph.value.FloatValue)12 Id (com.baidu.hugegraph.computer.core.graph.id.Id)10 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)8 DefaultProperties (com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties)7 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)6 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)5 BooleanValue (com.baidu.hugegraph.computer.core.graph.value.BooleanValue)4 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)3 Value (com.baidu.hugegraph.computer.core.graph.value.Value)3 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)2 DefaultEdge (com.baidu.hugegraph.computer.core.graph.edge.DefaultEdge)2 IdList (com.baidu.hugegraph.computer.core.graph.value.IdList)2 IdListList (com.baidu.hugegraph.computer.core.graph.value.IdListList)2 ListValue (com.baidu.hugegraph.computer.core.graph.value.ListValue)2 File (java.io.File)2