A collection of example applications demonstrating graph processing algorithms using Apache Flink's Gelly Graph API
—
Flexible input system supporting both file-based graph data and algorithmic graph generation. All inputs implement the standardized Input interface for consistent parameter handling and graph creation.
Base interface that all graph input sources must implement.
/**
* Base interface for all graph input sources
* @param <K> Vertex key type
* @param <VV> Vertex value type
* @param <EV> Edge value type
*/
public interface Input<K, VV, EV> extends Parameterized {
/** Human-readable identifier for the input source */
String getIdentity();
/** Create the input graph using Flink execution environment */
Graph<K, VV, EV> create(ExecutionEnvironment env) throws Exception;
}Base implementation providing common functionality for input sources.
/**
* Base class for input implementations with common parameter handling
*/
public abstract class InputBase<K, VV, EV> extends ParameterizedBase implements Input<K, VV, EV> {
/** Input generation or reading parallelism */
LongParameter parallelism;
}Reads graph data from CSV files with configurable format and field mappings.
/**
* CSV file input for reading graph data from comma-separated files
*/
public class CSV extends InputBase<K, VV, EV> {
/** Path to input CSV file */
StringParameter inputFilename;
/** Field separator character (default: comma) */
StringParameter fieldDelimiter;
/** Skip header row in CSV file */
BooleanParameter skipHeader;
}Usage Examples:
# Basic CSV input
--input CSV --input_filename graph.csv
# CSV with custom delimiter and header
--input CSV --input_filename data.tsv --field_delimiter "\t" --skip_headerCSV Format Examples:
# Edge list format (source, target)
1,2
2,3
3,1
# Edge list with weights (source, target, weight)
1,2,0.5
2,3,1.0
3,1,0.8
# Vertex and edge data (source, target, source_value, target_value, edge_value)
1,2,Alice,Bob,friend
2,3,Bob,Charlie,colleagueBase classes for algorithmically generated graphs with common parameters.
/**
* Base class for algorithmically generated graphs
*/
public abstract class GeneratedGraph extends InputBase<K, VV, EV> {
/** Number of vertices in generated graph */
LongParameter vertexCount;
/** Random seed for reproducible generation */
LongParameter seed;
}
/**
* Base class for generated graphs that may have multiple edges between vertices
*/
public abstract class GeneratedMultiGraph extends GeneratedGraph {
/** Whether to allow multiple edges between same vertex pair */
BooleanParameter allowMultipleEdges;
}Generates complete graphs where every vertex is connected to every other vertex.
/**
* Complete graph generator - all vertices connected to all others
*/
public class CompleteGraph extends GeneratedGraph {
// Inherits vertexCount and seed from GeneratedGraph
// Generates (n * (n-1)) / 2 edges for n vertices
}Usage Examples:
# Generate complete graph with 1000 vertices
--input CompleteGraph --vertex_count 1000
# Complete graph with specific seed for reproducibility
--input CompleteGraph --vertex_count 500 --seed 12345Generates regular grid graphs with configurable dimensions.
/**
* Grid graph generator for regular lattice structures
*/
public class GridGraph extends GeneratedGraph {
/** Grid dimensions (e.g., "10x10" for 2D, "5x5x5" for 3D) */
StringParameter dimensions;
/** Include diagonal connections in grid */
BooleanParameter includeDiagonals;
}Usage Examples:
# 2D grid graph
--input GridGraph --dimensions "10x10"
# 3D grid with diagonals
--input GridGraph --dimensions "5x5x5" --include_diagonalsGenerates star graphs with one central vertex connected to all others.
/**
* Star graph generator - one central vertex connected to all others
*/
public class StarGraph extends GeneratedGraph {
// Generates 1 central vertex + (n-1) leaf vertices
// Total edges: n-1
}Usage Examples:
# Star graph with 1000 vertices (1 center + 999 leaves)
--input StarGraph --vertex_count 1000Generates cycle graphs where vertices form a ring structure.
/**
* Cycle graph generator - vertices connected in a ring
*/
public class CycleGraph extends GeneratedGraph {
// Each vertex connected to exactly 2 neighbors
// Total edges: n (for n vertices)
}Generates path graphs where vertices form a linear chain.
/**
* Path graph generator - vertices connected in a line
*/
public class PathGraph extends GeneratedGraph {
// Vertices connected in sequence: 1-2-3-...-n
// Total edges: n-1
}Generates R-MAT (Recursive Matrix) graphs using probabilistic edge placement for realistic network structures.
/**
* R-MAT graph generator for realistic network topologies
* Uses recursive matrix model with configurable probabilities
*/
public class RMatGraph extends GeneratedMultiGraph {
/** Graph scale - generates 2^scale vertices */
LongParameter scale;
/** Edge factor - multiplier for number of edges */
LongParameter edgeFactor;
/** R-MAT matrix probability parameters (must sum to 1.0) */
DoubleParameter a, b, c; // d = 1 - a - b - c
/** Enable noise in edge placement */
BooleanParameter noiseEnabled;
/** Noise level for edge placement randomization */
DoubleParameter noise;
}Usage Examples:
# Basic R-MAT graph (scale=10 gives 1024 vertices)
--input RMatGraph --scale 10 --edge_factor 4
# R-MAT with custom probabilities
--input RMatGraph --scale 12 --edge_factor 8 --a 0.45 --b 0.25 --c 0.15
# R-MAT with noise
--input RMatGraph --scale 8 --edge_factor 2 --noise_enabled --noise 0.1Generates hypercube graphs of specified dimensions.
/**
* Hypercube graph generator for n-dimensional hypercube structures
*/
public class HypercubeGraph extends GeneratedGraph {
/** Hypercube dimension */
LongParameter dimensions;
// Generates 2^dimensions vertices
}Generates circulant graphs with configurable connection patterns.
/**
* Circulant graph generator with configurable offset patterns
*/
public class CirculantGraph extends GeneratedGraph {
/** Connection offsets (e.g., "1,2" connects each vertex to +1 and +2 neighbors) */
StringParameter offsets;
}Usage Examples:
# Circulant graph with offset pattern
--input CirculantGraph --vertex_count 100 --offsets "1,2,5"Generates graphs with vertices but no edges.
/**
* Empty graph generator - vertices with no edges
*/
public class EmptyGraph extends GeneratedGraph {
// Generates n isolated vertices
}Generates graphs with single edges between vertex pairs.
/**
* Singleton edge graph generator - ensures single edges between pairs
*/
public class SingletonEdgeGraph extends GeneratedGraph {
/** Target edge count */
LongParameter edgeCount;
}Utility input for testing and debugging that echoes input parameters.
/**
* Echo graph for testing - outputs parameter information
*/
public class EchoGraph extends InputBase<K, VV, EV> {
// Used for debugging parameter passing and configuration
}Basic Graph Generation:
// Create complete graph generator
CompleteGraph generator = new CompleteGraph();
generator.configure(ParameterTool.fromArgs(new String[]{
"--vertex_count", "1000",
"--seed", "12345"
}));
// Generate graph
Graph<LongValue, NullValue, NullValue> graph = generator.create(env);File Input:
// Configure CSV input
CSV csvInput = new CSV();
csvInput.configure(ParameterTool.fromArgs(new String[]{
"--input_filename", "graph.csv",
"--field_delimiter", ",",
"--skip_header"
}));
// Read graph from file
Graph<LongValue, NullValue, DoubleValue> graph = csvInput.create(env);Input Selection by Name:
// Get input from factory
ParameterizedFactory<Input> factory = createInputFactory();
Input input = factory.get("CompleteGraph");
if (input != null) {
input.configure(parameters);
Graph graph = input.create(env);
}Install with Tessl CLI
npx tessl i tessl/maven-org-apache-flink--flink-gelly-examples-2-12