Gelly: Flink Graph API
Gelly is a Graph API for Flink. It contains a set of methods and utilities which aim to simplify the development of graph analysis applications in Flink. In Gelly, graphs can be transformed and modified using highlevel functions similar to the ones provided by the batch processing API. Gelly provides methods to create, transform and modify graphs, as well as a library of graph algorithms.
 Using Gelly
 Graph Representation
 Graph Creation
 Graph Properties
 Graph Transformations
 Graph Mutations
 Neighborhood Methods
 Iterative Graph Processing
 Graph Validation
 Library Methods
Using Gelly
Gelly is currently part of the libraries Maven project. All relevant classes are located in the org.apache.flink.graph package.
Add the following dependency to your pom.xml
to use Gelly.
Note that Gelly is currently not part of the binary distribution. See linking with it for cluster execution here.
The remaining sections provide a description of available methods and present several examples of how to use Gelly and how to mix it with the Flink DataSet API. After reading this guide, you might also want to check the Gelly examples.
Graph Representation
In Gelly, a Graph
is represented by a DataSet
of vertices and a DataSet
of edges.
The Graph
nodes are represented by the Vertex
type. A Vertex
is defined by a unique ID and a value. Vertex
IDs should implement the Comparable
interface. Vertices without value can be represented by setting the value type to NullValue
.
The graph edges are represented by the Edge
type. An Edge
is defined by a source ID (the ID of the source Vertex
), a target ID (the ID of the target Vertex
) and an optional value. The source and target IDs should be of the same type as the Vertex
IDs. Edges with no value have a NullValue
value type.
Graph Creation
You can create a Graph
in the following ways:
 from a
DataSet
of edges and an optionalDataSet
of vertices:
 from a
DataSet
ofTuple2
representing the edges. Gelly will convert eachTuple2
to anEdge
, where the first field will be the source ID and the second field will be the target ID. Both vertex and edge values will be set toNullValue
.
 from a
DataSet
ofTuple3
and an optionalDataSet
ofTuple2
. In this case, Gelly will convert eachTuple3
to anEdge
, where the first field will be the source ID, the second field will be the target ID and the third field will be the edge value. Equivalently, eachTuple2
will be converted to aVertex
, where the first field will be the vertex ID and the second field will be the vertex value:

from a CSV file of Edge data and an optional CSV file of Vertex data. In this case, Gelly will convert each row from the Edge CSV file to an
Edge
, where the first field will be the source ID, the second field will be the target ID and the third field (if present) will be the edge value. Equivalently, each row from the optional Vertex CSV file will be converted to aVertex
, where the first field will be the vertex ID and the second field (if present) will be the vertex value. In order to get aGraph
from aGraphCsvReader
one has to specify the types, using one of the following methods: types(Class<K> vertexKey, Class<VV> vertexValue,Class<EV> edgeValue)
: both vertex and edge values are present.edgeTypes(Class<K> vertexKey, Class<EV> edgeValue)
: the Graph has edge values, but no vertex values.vertexTypes(Class<K> vertexKey, Class<VV> vertexValue)
: the Graph has vertex values, but no edge values.keyType(Class<K> vertexKey)
: the Graph has no vertex values and no edge values.
 from a CSV file of Edge data and an optional CSV file of Vertex data.
In this case, Gelly will convert each row from the Edge CSV file to an
Edge
. The first field of the each row will be the source ID, the second field will be the target ID and the third field (if present) will be the edge value. If the edges have no associated value, set the edge value type parameter (3rd type argument) toNullValue
. You can also specify that the vertices are initialized with a vertex value. If you provide a path to a CSV file viapathVertices
, each row of this file will be converted to aVertex
. The first field of each row will be the vertex ID and the second field will be the vertex value. If you provide a vertex value initializerMapFunction
via thevertexValueInitializer
parameter, then this function is used to generate the vertex values. The set of vertices will be created automatically from the edges input. If the vertices have no associated value, set the vertex value type parameter (2nd type argument) toNullValue
. The vertices will then be automatically created from the edges input with vertex value of typeNullValue
.
 from a
Collection
of edges and an optionalCollection
of vertices:
If no vertex input is provided during Graph creation, Gelly will automatically produce the Vertex
DataSet
from the edge input. In this case, the created vertices will have no values. Alternatively, you can provide a MapFunction
as an argument to the creation method, in order to initialize the Vertex
values:
If no vertex input is provided during Graph creation, Gelly will automatically produce the Vertex
DataSet
from the edge input. In this case, the created vertices will have no values. Alternatively, you can provide a MapFunction
as an argument to the creation method, in order to initialize the Vertex
values:
Graph Properties
Gelly includes the following methods for retrieving various Graph properties and metrics:
Graph Transformations
 Map: Gelly provides specialized methods for applying a map transformation on the vertex values or edge values.
mapVertices
andmapEdges
return a newGraph
, where the IDs of the vertices (or edges) remain unchanged, while the values are transformed according to the provided userdefined map function. The map functions also allow changing the type of the vertex or edge values.
 Filter: A filter transformation applies a userdefined filter function on the vertices or edges of the
Graph
.filterOnEdges
will create a subgraph of the original graph, keeping only the edges that satisfy the provided predicate. Note that the vertex dataset will not be modified. Respectively,filterOnVertices
applies a filter on the vertices of the graph. Edges whose source and/or target do not satisfy the vertex predicate are removed from the resulting edge dataset. Thesubgraph
method can be used to apply a filter function to the vertices and the edges at the same time.
 Join: Gelly provides specialized methods for joining the vertex and edge datasets with other input datasets.
joinWithVertices
joins the vertices with aTuple2
input data set. The join is performed using the vertex ID and the first field of theTuple2
input as the join keys. The method returns a newGraph
where the vertex values have been updated according to a provided userdefined transformation function. Similarly, an input dataset can be joined with the edges, using one of three methods.joinWithEdges
expects an inputDataSet
ofTuple3
and joins on the composite key of both source and target vertex IDs.joinWithEdgesOnSource
expects aDataSet
ofTuple2
and joins on the source key of the edges and the first attribute of the input dataset andjoinWithEdgesOnTarget
expects aDataSet
ofTuple2
and joins on the target key of the edges and the first attribute of the input dataset. All three methods apply a transformation function on the edge and the input data set values. Note that if the input dataset contains a key multiple times, all Gelly join methods will only consider the first value encountered.

Reverse: the
reverse()
method returns a newGraph
where the direction of all edges has been reversed. 
Undirected: In Gelly, a
Graph
is always directed. Undirected graphs can be represented by adding all oppositedirection edges to a graph. For this purpose, Gelly provides thegetUndirected()
method. 
Union: Gelly’s
union()
method performs a union operation on the vertex and edge sets of the specified graph and the current graph. Duplicate vertices are removed from the resultingGraph
, while if duplicate edges exist, these will be preserved.

Difference: Gelly’s
difference()
method performs a difference on the vertex and edge sets of the current graph and the specified graph. 
Intersect: Gelly’s
intersect()
method performs an intersect on the edge sets of the current graph and the specified graph. The result is a newGraph
that contains all edges that exist in both input graphs. Two edges are considered equal, if they have the same source identifier, target identifier and edge value. Vertices in the resulting graph have no value. If vertex values are required, one can for example retrieve them from one of the input graphs using thejoinWithVertices()
method. Depending on the parameterdistinct
, equal edges are either contained once in the resultingGraph
or as often as there are pairs of equal edges in the input graphs.
Graph Mutations
Gelly includes the following methods for adding and removing vertices and edges from an input Graph
:
Neighborhood Methods
Neighborhood methods allow vertices to perform an aggregation on their firsthop neighborhood.
reduceOnEdges()
can be used to compute an aggregation on the values of the neighboring edges of a vertex and reduceOnNeighbors()
can be used to compute an aggregation on the values of the neighboring vertices. These methods assume associative and commutative aggregations and exploit combiners internally, significantly improving performance.
The neighborhood scope is defined by the EdgeDirection
parameter, which takes the values IN
, OUT
or ALL
. IN
will gather all incoming edges (neighbors) of a vertex, OUT
will gather all outgoing edges (neighbors), while ALL
will gather all edges (neighbors).
For example, assume that you want to select the minimum weight of all outedges for each vertex in the following graph:
The following code will collect the outedges for each vertex and apply the SelectMinWeight()
userdefined function on each of the resulting neighborhoods:
Similarly, assume that you would like to compute the sum of the values of all incoming neighbors, for every vertex. The following code will collect the incoming neighbors for each vertex and apply the SumValues()
userdefined function on each neighborhood:
When the aggregation function is not associative and commutative or when it is desirable to return more than one values per vertex, one can use the more general
groupReduceOnEdges()
and groupReduceOnNeighbors()
methods.
These methods return zero, one or more values per vertex and provide access to the whole neighborhood.
For example, the following code will output all the vertex pairs which are connected with an edge having a weight of 0.5 or more:
When the aggregation computation does not require access to the vertex value (for which the aggregation is performed), it is advised to use the more efficient EdgesFunction
and NeighborsFunction
for the userdefined functions. When access to the vertex value is required, one should use EdgesFunctionWithVertexValue
and NeighborsFunctionWithVertexValue
instead.
Iterative Graph Processing
Gelly exploits Flink’s efficient iteration operators to support largescale iterative graph processing. Currently, we provide implementations of the popular scattergather iterative model and a variation of GatherSumApply. In the following sections, we describe these models and show how you can use them in Gelly.
ScatterGather Iterations
The scattergather model, also known as “signal/collect” model, expresses computation from the perspective of a vertex in the graph. The computation proceeds in synchronized iteration steps, called supersteps. In each superstep, a vertex produces messages for other vertices and updates its value based on the messages it receives. To use scattergather iterations in Gelly, the user only needs to define how a vertex behaves in each superstep:
 Messaging: corresponds to the scatter phase and produces the messages that a vertex will send to other vertices.
 Value Update: corresponds to the gather phase and updates the vertex value using the received messages.
Gelly provides methods for scattergather iterations. The user only needs to implement two functions, corresponding to the scatter and gather phases. The first function is a MessagingFunction
, which allows a vertex to send out messages for other vertices. Messages are recieved during the same superstep as they are sent. The second function is VertexUpdateFunction
, which defines how a vertex will update its value based on the received messages.
These functions and the maximum number of iterations to run are given as parameters to Gelly’s runScatterGatherIteration
. This method will execute the scattergather iteration on the input Graph and return a new Graph, with updated vertex values.
A scattergather iteration can be extended with information such as the total number of vertices, the in degree and out degree. Additionally, the neighborhood type (in/out/all) over which to run the scattergather iteration can be specified. By default, the updates from the inneighbors are used to modify the current vertex’s state and messages are sent to outneighbors.
Let us consider computing SingleSourceShortestPaths with scattergather iterations on the following graph and let vertex 1 be the source. In each superstep, each vertex sends a candidate distance message to all its neighbors. The message value is the sum of the current value of the vertex and the edge weight connecting this vertex with its neighbor. Upon receiving candidate distance messages, each vertex calculates the minimum distance and, if a shorter path has been discovered, it updates its value. If a vertex does not change its value during a superstep, then it does not produce messages for its neighbors for the next superstep. The algorithm converges when there are no value updates.
Configuring a ScatterGather Iteration
A scattergather iteration can be configured using a ScatterGatherConfiguration
object.
Currently, the following parameters can be specified:

Name: The name for the scattergather iteration. The name is displayed in logs and messages and can be specified using the
setName()
method. 
Parallelism: The parallelism for the iteration. It can be set using the
setParallelism()
method. 
Solution set in unmanaged memory: Defines whether the solution set is kept in managed memory (Flink’s internal way of keeping objects in serialized form) or as a simple object map. By default, the solution set runs in managed memory. This property can be set using the
setSolutionSetUnmanagedMemory()
method. 
Aggregators: Iteration aggregators can be registered using the
registerAggregator()
method. An iteration aggregator combines all aggregates globally once per superstep and makes them available in the next superstep. Registered aggregators can be accessed inside the userdefinedVertexUpdateFunction
andMessagingFunction
. 
Broadcast Variables: DataSets can be added as Broadcast Variables to the
VertexUpdateFunction
andMessagingFunction
, using theaddBroadcastSetForUpdateFunction()
andaddBroadcastSetForMessagingFunction()
methods, respectively. 
Number of Vertices: Accessing the total number of vertices within the iteration. This property can be set using the
setOptNumVertices()
method. The number of vertices can then be accessed in the vertex update function and in the messaging function using thegetNumberOfVertices()
method. If the option is not set in the configuration, this method will return 1. 
Degrees: Accessing the in/out degree for a vertex within an iteration. This property can be set using the
setOptDegrees()
method. The in/out degrees can then be accessed in the vertex update function and in the messaging function, per vertex using thegetInDegree()
andgetOutDegree()
methods. If the degrees option is not set in the configuration, these methods will return 1. 
Messaging Direction: By default, a vertex sends messages to its outneighbors and updates its value based on messages received from its inneighbors. This configuration option allows users to change the messaging direction to either
EdgeDirection.IN
,EdgeDirection.OUT
,EdgeDirection.ALL
. The messaging direction also dictates the update direction which would beEdgeDirection.OUT
,EdgeDirection.IN
andEdgeDirection.ALL
, respectively. This property can be set using thesetDirection()
method.
The following example illustrates the usage of the degree as well as the number of vertices options.
The following example illustrates the usage of the edge direction option. Vertices update their values to contain a list of all their inneighbors.
GatherSumApply Iterations
Like in the scattergather model, GatherSumApply also proceeds in synchronized iterative steps, called supersteps. Each superstep consists of the following three phases:
 Gather: a userdefined function is invoked in parallel on the edges and neighbors of each vertex, producing a partial value.
 Sum: the partial values produced in the Gather phase are aggregated to a single value, using a userdefined reducer.
 Apply: each vertex value is updated by applying a function on the current value and the aggregated value produced by the Sum phase.
Let us consider computing SingleSourceShortestPaths with GSA on the following graph and let vertex 1 be the source. During the Gather
phase, we calculate the new candidate distances, by adding each vertex value with the edge weight. In Sum
, the candidate distances are grouped by vertex ID and the minimum distance is chosen. In Apply
, the newly calculated distance is compared to the current vertex value and the minimum of the two is assigned as the new value of the vertex.
Notice that, if a vertex does not change its value during a superstep, it will not calculate candidate distance during the next superstep. The algorithm converges when no vertex changes value. The resulting graph after the algorithm converges is shown below.
To implement this example in Gelly GSA, the user only needs to call the runGatherSumApplyIteration
method on the input graph and provide the GatherFunction
, SumFunction
and ApplyFunction
UDFs. Iteration synchronization, grouping, value updates and convergence are handled by the system:
Note that gather
takes a Neighbor
type as an argument. This is a convenience type which simply wraps a vertex with its neighboring edge.
For more examples of how to implement algorithms with the GatherSumApply model, check the GSAPageRank and GSAConnectedComponents library methods of Gelly.
Configuring a GatherSumApply Iteration
A GSA iteration can be configured using a GSAConfiguration
object.
Currently, the following parameters can be specified:

Name: The name for the GSA iteration. The name is displayed in logs and messages and can be specified using the
setName()
method. 
Parallelism: The parallelism for the iteration. It can be set using the
setParallelism()
method. 
Solution set in unmanaged memory: Defines whether the solution set is kept in managed memory (Flink’s internal way of keeping objects in serialized form) or as a simple object map. By default, the solution set runs in managed memory. This property can be set using the
setSolutionSetUnmanagedMemory()
method. 
Aggregators: Iteration aggregators can be registered using the
registerAggregator()
method. An iteration aggregator combines all aggregates globally once per superstep and makes them available in the next superstep. Registered aggregators can be accessed inside the userdefinedGatherFunction
,SumFunction
andApplyFunction
. 
Broadcast Variables: DataSets can be added as Broadcast Variables to the
GatherFunction
,SumFunction
andApplyFunction
, using the methodsaddBroadcastSetForGatherFunction()
,addBroadcastSetForSumFunction()
andaddBroadcastSetForApplyFunction
methods, respectively. 
Number of Vertices: Accessing the total number of vertices within the iteration. This property can be set using the
setOptNumVertices()
method. The number of vertices can then be accessed in the gather, sum and/or apply functions by using thegetNumberOfVertices()
method. If the option is not set in the configuration, this method will return 1. 
Neighbor Direction: By default values are gathered from the out neighbors of the Vertex. This can be modified using the
setDirection()
method.
The following example illustrates the usage of the number of vertices option.
The following example illustrates the usage of the edge direction option.
ScatterGather and GSA Comparison
As seen in the examples above, GatherSumApply iterations are quite similar to scattergather iterations. In fact, any algorithm which can be expressed as a GSA iteration can also be written in the scattergather model. The messaging phase of the scattergather model is equivalent to the Gather and Sum steps of GSA: Gather can be seen as the phase where the messages are produced and Sum as the phase where they are routed to the target vertex. Similarly, the value update phase corresponds to the Apply step.
The main difference between the two implementations is that the Gather phase of GSA parallelizes the computation over the edges, while the messaging phase distributes the computation over the vertices. Using the SSSP examples above, we see that in the first superstep of the scattergather case, vertices 1, 2 and 3 produce messages in parallel. Vertex 1 produces 3 messages, while vertices 2 and 3 produce one message each. In the GSA case on the other hand, the computation is parallelized over the edges: the three candidate distance values of vertex 1 are produced in parallel. Thus, if the Gather step contains “heavy” computation, it might be a better idea to use GSA and spread out the computation, instead of burdening a single vertex. Another case when parallelizing over the edges might prove to be more efficient is when the input graph is skewed (some vertices have a lot more neighbors than others).
Another difference between the two implementations is that the scattergather implementation uses a coGroup
operator internally, while GSA uses a reduce
. Therefore, if the function that combines neighbor values (messages) requires the whole group of values for the computation, scattergather should be used. If the update function is associative and commutative, then the GSA’s reducer is expected to give a more efficient implementation, as it can make use of a combiner.
Another thing to note is that GSA works strictly on neighborhoods, while in the scattergather model, a vertex can send a message to any vertex, given that it knows its vertex ID, regardless of whether it is a neighbor. Finally, in Gelly’s scattergather implementation, one can choose the messaging direction, i.e. the direction in which updates propagate. GSA does not support this yet, so each vertex will be updated based on the values of its inneighbors only.
Graph Validation
Gelly provides a simple utility for performing validation checks on input graphs. Depending on the application context, a graph may or may not be valid according to certain criteria. For example, a user might need to validate whether their graph contains duplicate edges or whether its structure is bipartite. In order to validate a graph, one can define a custom GraphValidator
and implement its validate()
method. InvalidVertexIdsValidator
is Gelly’s predefined validator. It checks that the edge set contains valid vertex IDs, i.e. that all edge IDs
also exist in the vertex IDs set.
Library Methods
Gelly has a growing collection of graph algorithms for easily analyzing largescale Graphs. So far, the following library methods are implemented:
 Community Detection
 Label Propagation
 Connected Components
 GSA Connected Components
 PageRank
 GSA PageRank
 Single Source Shortest Paths
 GSA Single Source Shortest Paths
 GSA Triangle Count
 Triangle Enumerator
 Summarization
Gelly’s library methods can be used by simply calling the run()
method on the input graph:
Community Detection
Overview
In graph theory, communities refer to groups of nodes that are well connected internally, but sparsely connected to other groups. This library method is an implementation of the community detection algorithm described in the paper Towards realtime community detection in large networks.
Details
The algorithm is implemented using scattergather iterations.
Initially, each vertex is assigned a Tuple2
containing its initial value along with a score equal to 1.0.
In each iteration, vertices send their labels and scores to their neighbors. Upon receiving messages from its neighbors,
a vertex chooses the label with the highest score and subsequently rescores it using the edge values,
a userdefined hop attenuation parameter, delta
, and the superstep number.
The algorithm converges when vertices no longer update their value or when the maximum number of iterations
is reached.
Usage
The algorithm takes as input a Graph
with any vertex type, Long
vertex values, and Double
edge values. It returns a Graph
of the same type as the input,
where the vertex values correspond to the community labels, i.e. two vertices belong to the same community if they have the same vertex value.
The constructor takes two parameters:
maxIterations
: the maximum number of iterations to run.delta
: the hop attenuation parameter, with default value 0.5.
Label Propagation
Overview
This is an implementation of the wellknown Label Propagation algorithm described in this paper. The algorithm discovers communities in a graph, by iteratively propagating labels between neighbors. Unlike the Community Detection library method, this implementation does not use scores associated with the labels.
Details
The algorithm is implemented using scattergather iterations.
Labels are expected to be of type Comparable
and are initialized using the vertex values of the input Graph
.
The algorithm iteratively refines discovered communities by propagating labels. In each iteration, a vertex adopts
the label that is most frequent among its neighbors’ labels. In case of a tie (i.e. two or more labels appear with the
same frequency), the algorithm picks the greater label. The algorithm converges when no vertex changes its value or
the maximum number of iterations has been reached. Note that different initializations might lead to different results.
Usage
The algorithm takes as input a Graph
with a Comparable
vertex type, a Comparable
vertex value type and an arbitrary edge value type.
It returns a DataSet
of vertices, where the vertex value corresponds to the community in which this vertex belongs after convergence.
The constructor takes one parameter:
maxIterations
: the maximum number of iterations to run.
Connected Components
Overview
This is an implementation of the Weakly Connected Components algorithm. Upon convergence, two vertices belong to the same component, if there is a path from one to the other, without taking edge direction into account.
Details
The algorithm is implemented using scattergather iterations. This implementation uses a comparable vertex value as initial component identifier (ID). Vertices propagate their current value in each iteration. Upon receiving component IDs from its neighbors, a vertex adopts a new component ID if its value is lower than its current component ID. The algorithm converges when vertices no longer update their component ID value or when the maximum number of iterations has been reached.
Usage
The result is a DataSet
of vertices, where the vertex value corresponds to the assigned component.
The constructor takes one parameter:
maxIterations
: the maximum number of iterations to run.
GSA Connected Components
Overview
This is an implementation of the Weakly Connected Components algorithm. Upon convergence, two vertices belong to the same component, if there is a path from one to the other, without taking edge direction into account.
Details
The algorithm is implemented using gathersumapply iterations. This implementation uses a comparable vertex value as initial component identifier (ID). In the gather phase, each vertex collects the vertex value of their adjacent vertices. In the sum phase, the minimum among those values is selected. In the apply phase, the algorithm sets the minimum value as the new vertex value if it is smaller than the current value. The algorithm converges when vertices no longer update their component ID value or when the maximum number of iterations has been reached.
Usage
The result is a DataSet
of vertices, where the vertex value corresponds to the assigned component.
The constructor takes one parameter:
maxIterations
: the maximum number of iterations to run.
PageRank
Overview
An implementation of a simple PageRank algorithm, using scattergather iterations. PageRank is an algorithm that was first used to rank web search engine results. Today, the algorithm and many variations, are used in various graph application domains. The idea of PageRank is that important or relevant pages tend to link to other important pages.
Details
The algorithm operates in iterations, where pages distribute their scores to their neighbors (pages they have links to) and subsequently update their scores based on the partial values they receive. The implementation assumes that each page has at least one incoming and one outgoing link. In order to consider the importance of a link from one page to another, scores are divided by the total number of outlinks of the source page. Thus, a page with 10 links will distribute 1/10 of its score to each neighbor, while a page with 100 links, will distribute 1/100 of its score to each neighboring page. This process computes what is often called the transition probablities, i.e. the probability that some page will lead to other page while surfing the web. To correctly compute the transition probabilities, this implementation expectes the edge values to be initialiez to 1.0.
Usage
The algorithm takes as input a Graph
with any vertex type, Double
vertex values, and Double
edge values. Edges values should be initialized to 1.0, in order to correctly compute the transition probabilities. Otherwise, the transition probability for an Edge (u, v)
will be set to the edge value divided by u
’s outdegree. The algorithm returns a DataSet
of vertices, where the vertex value corresponds to assigned rank after convergence (or maximum iterations).
The constructors take the following parameters:
beta
: the damping factor.maxIterations
: the maximum number of iterations to run.numVertices
: the number of vertices in the input. If known beforehand, is it advised to provide this argument to speed up execution.
GSA PageRank
The algorithm is implemented using gathersumapply iterations.
See the PageRank library method for implementation details and usage information.
Single Source Shortest Paths
Overview
An implementation of the SingleSourceShortestPaths algorithm for weighted graphs. Given a source vertex, the algorithm computes the shortest paths from this source to all other nodes in the graph.
Details
The algorithm is implemented using scattergather iterations. In each iteration, a vertex sends to its neighbors a message containing the sum its current distance and the edge weight connecting this vertex with the neighbor. Upon receiving candidate distance messages, a vertex calculates the minimum distance and, if a shorter path has been discovered, it updates its value. If a vertex does not change its value during a superstep, then it does not produce messages for its neighbors for the next superstep. The computation terminates after the specified maximum number of supersteps or when there are no value updates.
Usage
The algorithm takes as input a Graph
with any vertex type, Double
vertex values, and Double
edge values. The output is a DataSet
of vertices where the vertex values
correspond to the minimum distances from the given source vertex.
The constructor takes two parameters:
srcVertexId
The vertex ID of the source vertex.maxIterations
: the maximum number of iterations to run.
GSA Single Source Shortest Paths
The algorithm is implemented using gathersumapply iterations.
See the Single Source Shortest Paths library method for implementation details and usage information.
GSA Triangle Count
Overview
An implementation of the Triangle Count algorithm. Given an input graph, it returns the number of unique triangles in it.
Details
This algorithm operates in three phases. First, vertices select neighbors with IDs greater than theirs and send messages to them. Each received message is then propagated to neighbors with higher IDs. Finally, if a node encounters the target ID in the list of received messages, it increments the number of discovered triangles.
Usage
The algorithm takes an undirected, unweighted graph as input and outputs a DataSet
which contains a single integer corresponding to the number of triangles
in the graph. The algorithm constructor takes no arguments.
Triangle Enumerator
Overview
This library method enumerates unique triangles present in the input graph. A triangle consists of three edges that connect three vertices with each other. This implementation ignores edge directions.
Details
The basic triangle enumeration algorithm groups all edges that share a common vertex and builds triads, i.e., triples of vertices that are connected by two edges. Then, all triads are filtered for which no third edge exists that closes the triangle. For a group of n edges that share a common vertex, the number of built triads is quadratic ((n*(n1))/2). Therefore, an optimization of the algorithm is to group edges on the vertex with the smaller output degree to reduce the number of triads. This implementation extends the basic algorithm by computing output degrees of edge vertices and grouping on edges on the vertex with the smaller degree.
Usage
The algorithm takes a directed graph as input and outputs a DataSet
of Tuple3
. The Vertex ID type has to be Comparable
.
Each Tuple3
corresponds to a triangle, with the fields containing the IDs of the vertices forming the triangle.
Summarization
Overview
The summarization algorithm computes a condensed version of the input graph by grouping vertices and edges based on their values. In doing so, the algorithm helps to uncover insights about patterns and distributions in the graph. One possible use case is the visualization of communities where the whole graph is too large and needs to be summarized based on the community identifier stored at a vertex.
Details
In the resulting graph, each vertex represents a group of vertices that share the same value. An edge, that connects a vertex with itself, represents all edges with the same edge value that connect vertices from the same vertex group. An edge between different vertices in the output graph represents all edges with the same edge value between members of different vertex groups in the input graph.
The algorithm is implemented using Flink data operators. First, vertices are grouped by their value and a representative is chosen from each group. For any edge, the source and target vertex identifiers are replaced with the corresponding representative and grouped by source, target and edge value. Output vertices and edges are created from their corresponding groupings.
Usage
The algorithm takes a directed, vertex (and possibly edge) attributed graph as input and outputs a new graph where each vertex represents a group of vertices and each edge represents a group of edges from the input graph. Furthermore, each vertex and edge in the output graph stores the common group value and the number of represented elements.