use of com.baidu.hugegraph.computer.core.graph.value.IdListList in project hugegraph-computer by hugegraph.
the class MockComputation method compute.
@Override
public void compute(ComputationContext context, Vertex vertex, Iterator<IdList> messages) {
IdListList value = vertex.value();
while (messages.hasNext()) {
Assert.assertTrue(messages.hasNext());
value.add(messages.next().copy());
}
Assert.assertFalse(messages.hasNext());
if (RANDOM.nextInt() % 10 == 0) {
vertex.inactivate();
}
}
use of com.baidu.hugegraph.computer.core.graph.value.IdListList 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.value.IdListList in project hugegraph-computer by hugegraph.
the class RingsDetectionWithFilter method compute0.
@Override
public void compute0(ComputationContext context, Vertex vertex) {
vertex.value(new IdListList());
if (vertex.edges().size() == 0 || !this.filter.filter(vertex)) {
return;
}
RingsDetectionMessage message = new RingsDetectionMessage();
message.addPath(vertex);
for (Edge edge : vertex.edges()) {
if (this.filter.filter(edge)) {
message.walkEdgeProp(edge.properties());
context.sendMessage(edge.targetId(), message);
}
}
}
use of com.baidu.hugegraph.computer.core.graph.value.IdListList in project hugegraph-computer by hugegraph.
the class RingsDetectionWithFilter method compute.
@Override
public void compute(ComputationContext context, Vertex vertex, Iterator<RingsDetectionMessage> messages) {
boolean halt = true;
if (this.filter.filter(vertex)) {
Id vertexId = vertex.id();
while (messages.hasNext()) {
halt = false;
RingsDetectionMessage message = messages.next();
IdList path = message.path();
if (vertexId.equals(path.get(0))) {
// Use the smallest vertex record ring
boolean isMin = true;
for (int i = 0; i < path.size(); i++) {
Id pathVertexValue = path.get(i);
if (vertexId.compareTo(pathVertexValue) > 0) {
isMin = false;
break;
}
}
if (isMin) {
path.add(vertexId);
IdListList value = vertex.value();
value.add(path.copy());
}
} else {
boolean contains = false;
// Drop sequence if path contains this vertex
for (int i = 0; i < path.size(); i++) {
Id pathVertexValue = path.get(i);
if (pathVertexValue.equals(vertex.id())) {
contains = true;
break;
}
}
if (!contains) {
path.add(vertex.id());
for (Edge edge : vertex.edges()) {
if (this.filter.filter(edge, message)) {
message.walkEdgeProp(edge.properties());
context.sendMessage(edge.targetId(), message);
}
}
}
}
}
}
if (halt) {
vertex.inactivate();
}
}
Aggregations