use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.
the class Wcc method compute.
@Override
public void compute(ComputationContext context, Vertex vertex, Iterator<Id> messages) {
Id message = Combiner.combineAll(context.combiner(), messages);
Id value = vertex.value();
if (value.compareTo(message) > 0) {
vertex.value(message);
context.sendMessageToAllEdges(vertex, message);
}
vertex.inactivate();
}
use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.
the class RingsDetection method compute.
@Override
public void compute(ComputationContext context, Vertex vertex, Iterator<IdList> messages) {
Id id = vertex.id();
boolean halt = true;
while (messages.hasNext()) {
halt = false;
IdList sequence = messages.next();
if (id.equals(sequence.get(0))) {
// Use the smallest vertex record ring
boolean isMin = true;
for (int i = 1; i < sequence.size(); i++) {
Id pathVertexValue = sequence.get(i);
if (id.compareTo(pathVertexValue) > 0) {
isMin = false;
break;
}
}
if (isMin) {
sequence.add(id);
IdListList sequences = vertex.value();
sequences.add(sequence);
}
} else {
boolean contains = false;
// Drop sequence if path contains this vertex
for (int i = 0; i < sequence.size(); i++) {
Id pathVertexValue = sequence.get(i);
if (pathVertexValue.equals(vertex.id())) {
contains = true;
break;
}
}
// Field ringId is smallest vertex id in path
Id ringId = sequence.get(0);
if (!contains) {
sequence.add(vertex.id());
for (Edge edge : vertex.edges()) {
if (ringId.compareTo(edge.targetId()) <= 0) {
context.sendMessage(edge.targetId(), sequence);
}
}
}
}
}
if (halt) {
vertex.inactivate();
}
}
use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.
the class BetweennessMessage method compareTo.
@Override
public int compareTo(Value value) {
E.checkArgument(value instanceof BetweennessMessage, "The BetweennessMessage can't compare with class '%s'", value.getClass());
BetweennessMessage other = (BetweennessMessage) value;
E.checkArgument(this.sequence.size() != 0, "Sequence can't be empty");
E.checkArgument(other.sequence.size() != 0, "Sequence can't be empty");
Id selfSourceId = this.sequence.get(0);
Id otherSourceId = other.sequence.get(0);
return selfSourceId.compareTo(otherSourceId);
}
use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.
the class ClosenessCentrality method compute0.
@Override
public void compute0(ComputationContext context, Vertex vertex) {
// Set empty map as initial value
vertex.value(new ClosenessValue());
// Send messages to adjacent edges
for (Edge edge : vertex.edges()) {
Id senderId = vertex.id();
// Get property value
double value = this.weightValue(edge.property(this.weightProp));
DoubleValue distance = new DoubleValue(value);
ClosenessMessage message = new ClosenessMessage(senderId, senderId, distance);
context.sendMessage(edge.targetId(), message);
}
}
use of com.baidu.hugegraph.computer.core.graph.id.Id in project hugegraph-computer by hugegraph.
the class BetweennessCentrality method sendMessage.
private void sendMessage(ComputationContext context) {
for (SeqCount seqCount : this.seqTable.values()) {
for (Map.Entry<Id, Integer> entry : seqCount.idCount.entrySet()) {
double vote = (double) entry.getValue() / seqCount.totalCount;
BetweennessMessage voteMessage = new BetweennessMessage(new DoubleValue(vote));
context.sendMessage(entry.getKey(), voteMessage);
}
}
}
Aggregations