use of com.baidu.hugegraph.computer.core.graph.edge.Edge 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.edge.Edge 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();
}
}
use of com.baidu.hugegraph.computer.core.graph.edge.Edge in project hugegraph-computer by hugegraph.
the class ComputationContext method sendMessagesToAllEdgesIf.
/**
* Send all values to filtered adjacent vertices of specified vertex. The
* filtered adjacent vertices of specified vertex will receive the values
* at next superstep.
*/
default <M extends Value> void sendMessagesToAllEdgesIf(Vertex vertex, Iterator<M> values, BiFunction<M, Id, Boolean> filter) {
while (values.hasNext()) {
M value = values.next();
Iterator<Edge> edges = vertex.edges().iterator();
while (edges.hasNext()) {
Edge edge = edges.next();
if (filter.apply(value, edge.targetId())) {
this.sendMessage(edge.targetId(), value);
}
}
}
}
use of com.baidu.hugegraph.computer.core.graph.edge.Edge in project hugegraph-computer by hugegraph.
the class ComputationContext method sendMessageToAllEdges.
/**
* Send value to all adjacent vertices of specified vertex. The adjacent
* vertices of specified vertex will receive the value at next superstep.
*/
default void sendMessageToAllEdges(Vertex vertex, Value value) {
Iterator<Edge> edges = vertex.edges().iterator();
while (edges.hasNext()) {
Edge edge = edges.next();
this.sendMessage(edge.targetId(), value);
}
}
use of com.baidu.hugegraph.computer.core.graph.edge.Edge in project hugegraph-computer by hugegraph.
the class StreamGraphInput method readEdges.
@Override
public Vertex readEdges() throws IOException {
Vertex vertex = this.graphFactory.createVertex();
KvEntryReader reader = this.in.readEntry(in -> {
// Read id
vertex.id(readId(in));
});
if (this.frequency == EdgeFrequency.SINGLE) {
while (reader.hasRemaining()) {
Edge edge = this.graphFactory.createEdge();
// Only use targetId as subKey, use properties as subValue
reader.readSubKv(in -> {
edge.targetId(readId(in));
}, in -> {
edge.properties(readProperties(in));
});
vertex.addEdge(edge);
}
} else if (this.frequency == EdgeFrequency.SINGLE_PER_LABEL) {
while (reader.hasRemaining()) {
Edge edge = this.graphFactory.createEdge();
// Use label + targetId as subKey, use properties as subValue
reader.readSubKv(in -> {
edge.label(readLabel(in));
edge.targetId(readId(in));
}, in -> {
edge.properties(readProperties(in));
});
vertex.addEdge(edge);
}
} else {
assert this.frequency == EdgeFrequency.MULTIPLE;
while (reader.hasRemaining()) {
Edge edge = this.graphFactory.createEdge();
/*
* Use label + sortValues + targetId as subKey,
* use properties as subValue
*/
reader.readSubKv(in -> {
edge.label(readLabel(in));
edge.name(readLabel(in));
edge.targetId(readId(in));
}, in -> {
edge.properties(this.readProperties(in));
});
vertex.addEdge(edge);
}
}
return vertex;
}
Aggregations