-
Notifications
You must be signed in to change notification settings - Fork 2
Supported Graph Formats
Five formats are supported. .sg is the binary form GraphBrew converts
everything to on first load; subsequent runs use the cached .sg.
| Format | Extension | Description | Weighted |
|---|---|---|---|
| Edge List | .el |
Simple text format | No |
| Weighted Edge List | .wel |
Text with weights | Yes |
| Matrix Market | .mtx |
Standard sparse matrix | Optional |
| DIMACS | .gr |
Challenge format | Yes |
| Serialized |
.sg, .graph
|
Binary format | Optional |
The simplest format: one edge per line with source and destination vertices.
<source> <destination>
<source> <destination>
...
0 1
0 2
1 2
2 3
3 4
- Vertices are 0-indexed
- Whitespace separated (space or tab)
- Directed by default (add
-sto symmetrize) - No header required
./bench/bin/pr -f graph.el -s -n 3# From CSV
cat graph.csv | tr ',' ' ' > graph.el
# Remove headers
tail -n +2 graph_with_header.el > graph.elEdge list with weights for SSSP and weighted algorithms.
<source> <destination> <weight>
<source> <destination> <weight>
...
0 1 1.5
0 2 2.0
1 2 0.5
2 3 1.0
- Weights are floating-point numbers
- Used for SSSP benchmark
- Weights can be integers or decimals
./bench/bin/sssp -f graph.wel -s -r 0 -n 3# Add random weights to edge list
awk '{print $1, $2, rand()}' graph.el > graph.wel
# Add unit weights
awk '{print $1, $2, 1.0}' graph.el > graph.welStandard format from the Matrix Market collection. Widely used in scientific computing.
%%MatrixMarket matrix coordinate pattern general
<rows> <cols> <nnz>
<row> <col>
<row> <col>
...
Or with values:
%%MatrixMarket matrix coordinate real general
<rows> <cols> <nnz>
<row> <col> <value>
...
%%MatrixMarket matrix coordinate pattern general
5 5 6
1 2
1 3
2 3
3 4
4 5
5 1
- 1-indexed (vertices start at 1, not 0)
- Header line describes matrix type
- Dimensions line: rows, columns, non-zeros
-
pattern= unweighted,real= weighted -
symmetric= edges only stored once
./bench/bin/pr -f graph.mtx -s -n 3| Type | Meaning |
|---|---|
pattern |
Binary (0/1), unweighted |
real |
Floating-point weights |
integer |
Integer weights |
general |
Full matrix (not symmetric) |
symmetric |
Only lower triangle stored |
Format from DIMACS implementation challenges. Common for road networks.
c Comment line
p sp <nodes> <edges>
a <source> <destination> <weight>
a <source> <destination> <weight>
...
c Example graph
c This is a comment
p sp 5 6
a 1 2 10
a 1 3 20
a 2 3 5
a 3 4 15
a 4 5 10
a 5 1 25
- 1-indexed vertices
-
clines are comments -
p spdefines problem (shortest path) -
alines are arcs (edges) - Always weighted
./bench/bin/sssp -f graph.gr -s -r 0 -n 3- DIMACS Challenge
- Road networks (USA, Europe)
Binary format for fast loading. Pre-computed CSR representation.
# Convert edge list to serialized format
./bench/bin/converter -f graph.el -s -b graph.sg./bench/bin/pr -f graph.sg -n 3- Much faster loading for large graphs
- Larger file size than text
- Architecture-specific (endianness)
- Includes symmetrization if applied
| Graph Size | Recommendation |
|---|---|
| < 1M edges | Use text format |
| 1M - 100M edges | Consider serialized |
| > 100M edges | Use serialized |
GraphBrew automatically detects format by extension:
| Extension | Detected Format |
|---|---|
.el |
Edge list |
.wel |
Weighted edge list |
.mtx |
Matrix Market |
.gr |
DIMACS |
.sg, .graph
|
Serialized |
- Format detection is based solely on file extension
- There are no flags to force a specific input format
- Rename files or convert them if extension doesn't match format
# Edge list to serialized
./bench/bin/converter -f graph.el -s -b graph.sg
# Edge list to MTX format
./bench/bin/converter -f graph.el -s -p graph.mtx
# Edge list to Ligra format
./bench/bin/converter -f graph.el -s -y graph.ligra
# MTX to edge list (manual)
tail -n +3 graph.mtx | awk '{print $1-1, $2-1}' > graph.elimport networkx as nx
# Read various formats
G = nx.read_edgelist('graph.el', nodetype=int)
G = nx.read_weighted_edgelist('graph.wel', nodetype=int)
# Write to edge list
nx.write_edgelist(G, 'output.el', data=False)# MTX to EL (1-indexed to 0-indexed)
grep -v "^%" graph.mtx | tail -n +2 | awk '{print $1-1, $2-1}' > graph.el
# GR to WEL
grep "^a" graph.gr | awk '{print $2-1, $3-1, $4}' > graph.wel
# CSV to EL
cat graph.csv | tr ',' ' ' | grep -v "source" > graph.elUse the unified pipeline to download graphs automatically:
python3 scripts/graphbrew_experiment.py --download-only --size smallManual sources: SNAP, SuiteSparse, Network Repository. See Benchmark-Suite for size categories.
| Property | Requirement |
|---|---|
| Vertices | Non-negative integers |
| Self-loops | Allowed (removed by default, use -S to keep) |
| Multi-edges | Allowed (may affect results) |
| Directed | Yes (use -s for undirected) |
| Property | Recommendation |
|---|---|
| Connected | Ideally connected or mostly connected |
| No isolates | Remove isolated vertices for cleaner results |
| Reasonable size | 100+ edges for meaningful benchmarks |
# Check basic properties
head -5 graph.el
wc -l graph.el # Edge count
# Check for issues
sort graph.el | uniq -c | sort -rn | head # Duplicate edges
awk '$1==$2' graph.el # Self-loopsCommon issues: Windows line endings (dos2unix), 1-indexed vertices (awk '{print $1-1, $2-1}'), empty files. See Troubleshooting for details.
GraphBrew includes a test graph in scripts/test/graphs/:
| File | Description |
|---|---|
tiny/tiny.el |
Tiny edge list for quick testing |
Use for quick testing:
./bench/bin/pr -f scripts/test/graphs/tiny/tiny.el -s -n 3- Running-Benchmarks - How to run benchmarks
- Getting-Started - Getting started guide
- Graph-Benchmarks - Available algorithms