You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/modules/ROOT/pages/algorithms/pregel-api.adoc
+39Lines changed: 39 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -404,6 +404,45 @@ public class CustomComputation implements PregelComputation<CustomConfig> {
404
404
}
405
405
----
406
406
407
+
[[algorithms-pregel-api-bidirectional]]
408
+
=== Traversing incoming relationships
409
+
410
+
Some algorithms implemented in Pregel might require or benefit from the ability to access and send messages to all incoming relationships of the current context node.
411
+
GDS supports the creation of inverse indexes for relationship types, which enables the traversal of incoming relationships for directed relationship types.
412
+
413
+
A Pregel algorithm can access this index by implementing the `org.neo4j.gds.beta.pregel.BidirectionalPregelComputation` interface instead of the `PregelComputation` interface.
414
+
Implementing this interface has the following consequences:
415
+
416
+
* The Pregel framework will make sure that all relationships passed into the algorithm are inverse indexed.
417
+
If no such index exists, an error will be thrown.
418
+
* The signature of the `init` and `compute` functions now accept a `org.neo4j.gds.beta.pregel.context.InitContext.BidirectionalInitContext` and `org.neo4j.gds.beta.pregel.context.ComputeContext.BidirectionalComputeContext` respectively.
419
+
* Algorithms annotated with the `@PregelProcedure` annotation will automatically create all required inverse indexes.
420
+
421
+
The `BidirectionalInitContext` and `BidirectionalComputeContexts` expose the following new methods in addition to the methods defined by `InitContext` and `ComputeContext`:
422
+
423
+
[source, java]
424
+
----
425
+
//Returns the incoming degree (number of relationships) of the currently processed node.
426
+
public int incomingDegree();
427
+
// Calls the consumer for each incoming neighbor of the currently processed node.
428
+
public void forEachIncomingNeighbor(LongConsumer targetConsumer);
429
+
// Calls the consumer for each incoming neighbor of the given node.
430
+
public void forEachIncomingNeighbor(long nodeId, LongConsumer targetConsumer);
431
+
// Calls the consumer once for each incoming neighbor of the currently processed node.
432
+
public void forEachDistinctIncomingNeighbor(LongConsumer targetConsumer);
433
+
// Calls the consumer once for each incoming neighbor of the given node.
434
+
public void forEachDistinctIncomingNeighbor(long nodeId, LongConsumer targetConsumer);
435
+
----
436
+
437
+
In addition, the `BidirectionalComputeContext` also exposes the following function:
438
+
439
+
[source, java]
440
+
----
441
+
// Sends the given message to all neighbors of the node.
442
+
public void sendToIncomingNeighbors(double message);
0 commit comments