Package org.neo4j.gds.beta.pregel
Interface PregelComputation<C extends PregelConfig>
-
public interface PregelComputation<C extends PregelConfig>
Main interface to express user-defined logic using the Pregel framework. An algorithm is expressed using a node-centric view. A node can receive messages from other nodes, change its state and send messages to other nodes in each iteration (superstep).
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default double
applyRelationshipWeight(double nodeValue, double relationshipWeight)
If the input graph is weighted, i.e.void
compute(ComputeContext<C> context, Messages messages)
The compute method is called individually for each node in every superstep as long as the node receives messages or has not voted to halt yet.default void
init(InitContext<C> context)
The init method is called in the beginning of the first superstep (iteration) of the Pregel computation and allows initializing node values.default boolean
masterCompute(MasterComputeContext<C> context)
The masterCompute method is called exactly once after every superstep.default java.util.Optional<Reducer>
reducer()
A reducer is used to combine messages sent to a single node.PregelSchema
schema(C config)
The schema describes the node property layout.
-
-
-
Method Detail
-
schema
PregelSchema schema(C config)
The schema describes the node property layout. A node property can be composed of multiple primitive values, such as double or long, as well as arrays of those. Each part of that composite schema is named by a unique key.
Example:public PregelSchema schema(PregelConfig config) { return new PregelSchema.Builder() .add("key", ValueType.LONG) .add("privateKey", ValueType.LONG, Visibility.PRIVATE) .build(); }
- See Also:
PregelSchema
-
init
default void init(InitContext<C> context)
The init method is called in the beginning of the first superstep (iteration) of the Pregel computation and allows initializing node values.
The context parameter provides access to node properties of the in-memory graph and the algorithm configuration.
-
compute
void compute(ComputeContext<C> context, Messages messages)
The compute method is called individually for each node in every superstep as long as the node receives messages or has not voted to halt yet.
Since a Pregel computation is state-less, a node can only communicate with other nodes via messages. In each super- step, a node receives messages via the input parameter and can send new messages via the context parameter. Messages can be sent to neighbor nodes or any node if the identifier is known.
-
masterCompute
default boolean masterCompute(MasterComputeContext<C> context)
The masterCompute method is called exactly once after every superstep. It is called by a single thread.- Returns:
- true, iff the computation converged and should stop
-
reducer
default java.util.Optional<Reducer> reducer()
A reducer is used to combine messages sent to a single node. Based on the reduce function, multiple messages are condensed into a single one. Use cases are computing the sum, count, minimum or maximum of messages. Specifying a reducer can significantly reduce memory consumption and runtime of the computation.
-
applyRelationshipWeight
default double applyRelationshipWeight(double nodeValue, double relationshipWeight)
If the input graph is weighted, i.e. relationships have a property, this method can be overridden to apply that weight on a message before it is read by the receiving node.
If the input graph has no relationship properties, i.e. is unweighted, the method is skipped.
-
-