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);
}
}
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();
}
}
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();
}
}
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);
}
}
}
Aggregations