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