Fast Graph Algorithms Library implemented in C++
Project description
# fastgraphFPMS
**fastgraphFPMS** — compact, fast graph utilities in C++ using a CSR (Compressed Sparse Row) representation.
This repository provides a flexible graph file reader (auto-detects several common formats) and many classical graph algorithms (shortest paths, MST, connected components, Euler/Hamilton utilities, coloring heuristics, max-flow, BFS/DFS, …).
> Quick install (if the package is published to PyPI):
```bash
pip install fastgraphFPMS
If no pip package is available, please follow Build / Install from source below.
Table of contents
- What is this
- Highlights / Features
- Supported input formats (examples)
- Quick C++ example
- Build / Install from source
- API overview (selected)
- Testing & examples
- Contributing
- License
What is this
fastgraphFPMS provides a compact Graph class (CSR style) and implements a broad set of algorithms commonly used in graph processing. The library is focused on performance and simple integration into C++ projects. It includes a robust loader that attempts to auto-detect several input formats including a 3-line CSR format (HeadSucc, Succ, WeightsSucc) and adjacency matrices.
Highlights / Features
-
CSR internal representation:
HeadSucc,Succ,WeightsSucc. -
Automatic construction of predecessor arrays:
HeadPred,Pred,WeightsPred. -
Degree bookkeeping:
DemiDegreExt(out-degree) andDemiDegreInt(in-degree). -
Loader auto-detection for multiple file formats.
-
Algorithms implemented (non-exhaustive):
- Connected components (CC), Strongly connected components (SCC)
- Bipartiteness testing
- Minimum Spanning Tree: Prim & Kruskal
- Single-source shortest paths: Dijkstra (+bucket), Sedgewick–Vitter, Bellman–Ford
- All-pairs: Floyd–Warshall
- Eulerian path/circuit detection & construction
- Hamiltonian path/circuit utilities (backtracking)
- Graph coloring heuristics: Greedy, Welsh–Powell, DSATUR; chromatic helpers
- Max flow: Ford–Fulkerson & Edmonds–Karp
- BFS & DFS traversals
Supported input formats (examples)
The loader tries formats in a robust order and falls back when necessary.
1) CSR three-line format (HeadSucc / Succ / WeightsSucc)
Recommended if you want to provide a CSR representation directly. The first 3 non-empty lines are parsed as three integer lists.
0 2 5 6 8 9 9
1 3 2 3 4 5 2 4 5
2 4 1 2 2 2 2 1 2
-
Interpreted as:
HeadSucc = [0,2,5,6,8,9,9]→num_nodes = 6Succ = [1,3,2,3,4,5,2,4,5]WeightsSucc = [2,4,1,2,2,2,2,1,2]
Constraints:
HeadSuccmust havenum_nodes + 1entries.HeadSucc.back()must equalSucc.size().- Node indices are 0-based.
2) Adjacency matrix (first line N then N rows of N integers)
Zeros represent "no edge" in matrix format.
6
0 2 0 4 0 0
0 0 1 2 2 0
0 0 0 0 0 2
0 0 2 0 1 0
0 0 0 0 0 2
0 0 0 0 0 0
3) Explicit triples (first line N, then triples u v w)
Any whitespace grouping is allowed; parser expects triples after the first line.
6
0 1 2
0 3 4
1 2 1
2 5 2
3 4 1
4 5 2
4) Per-line adjacency lists (fallback)
Each non-empty line: u neighbor1 weight1 neighbor2 weight2 ...
0 1 2 3 4
1 2 1 3 2
2 5 2
3 2 2 4 1
4 5 2
Quick C++ example
#include "graph.h"
#include <iostream>
using namespace fastgraphfpms;
using namespace std;
int main() {
// Loads graph from file and auto-detects the format
Graph g("examples/csr_three_line.txt");
cout << "Nodes: " << g.get_num_nodes() << endl;
// Connected components example
auto cc = g.find_cc();
cout << "Connected components: " << cc.first << endl;
// Dijkstra from source 0 (example)
auto res = g.dijkstra(0);
if (holds_alternative<pair<vector<int>,vector<int>>>(res)) {
auto p = get<pair<vector<int>,vector<int>>>(res);
const vector<int>& dist = p.first;
for (size_t i = 0; i < dist.size(); ++i) {
cout << "dist[" << i << "] = " << dist[i] << endl;
}
}
return 0;
}
Build / Install from source
If the pip package is not published, build the library from source (CMake example):
git clone <repo-url>
cd fastgraphFPMS
mkdir build
cd build
cmake ..
make -j
sudo make install # optional: installs headers and library system-wide
Then compile your example program linking to the built library. Example:
g++ -std=c++17 example.cpp -I/usr/local/include -L/usr/local/lib -lfastgraphfpms -o example
Adjust include/library paths according to your install.
Note: The repository does not ship Python bindings by default. To make
pip install fastgraphFPMSavailable, add Python bindings (e.g., viapybind11) and publish to PyPI.
API overview (selected / high-level)
Constructors
Graph()— empty graphGraph(const vector<vector<int>>& matrix)— build from adjacency matrixGraph(const vector<int>& HeadSucc, const vector<int>& Succ, const vector<int>& Weights)— build from CSR arraysGraph(const string& filename)— load from file (auto-detection)
File I/O
void load_from_file(const string& filename);void save_to_file(const string& filename) const;void save_to_file_adjacency_list(const string& filename) const;
Selected algorithms & queries
int get_num_nodes() const;pair<int,vector<vector<int>>> find_cc() const;pair<int,vector<vector<int>>> find_scc() const;pair<int, vector<tuple<int,int,int>>> prim() const;pair<int, vector<tuple<int,int,int>>> kruskal() const;dijkstra(),dijkstra_bucket(),sedgewick_vitter(),bellman_ford()floyd_warshall()find_eulerian_path(),find_eulerian_circuit()find_hamiltonian_path(),find_hamiltonian_circuit()greedy_coloring(),welsh_powell_coloring(),dsatur_coloring(),chromatic_number()max_flow_ford_fulkerson(),max_flow_edmonds_karp()bfs(),dfs()
Check graph.h for exact signatures and return types.
Testing & examples
Suggested examples to include in examples/:
matrix_example.txt(adjacency matrix)csr_three_line.txt(three-line CSR)triples.txt(explicit triples)adjlist.txt(per-line adjacency)
Add unit tests that:
- load each format and assert
get_num_nodes()and degree counts - verify algorithm outputs on small graphs (connected components, MST weight, shortest path lengths)
Set up CI with CMake and ctest or GitHub Actions.
Contributing
Contributions are welcome. Ways to contribute:
- Add Python bindings (pybind11) and publish to PyPI
- Add tests and CI
- Improve input detection or add
format_hintoption toload_from_file - Add more sample programs and tutorials
Please open issues and pull requests against the repository.
Contact / support
Open an issue with:
- the input file you used
- the exact command or code that failed
- platform and compiler information
Attach a minimal reproducer file when possible.
License
Copyright (c) 2025 Drogo Flavio
Permission est hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastgraphfpms-1.0.4.tar.gz.
File metadata
- Download URL: fastgraphfpms-1.0.4.tar.gz
- Upload date:
- Size: 92.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be0fa817bd0979f998dab2913d135529654a4ef76ed64309ebc01f5e0bda7cff
|
|
| MD5 |
98bf295052ee0f1412b71914cf0f3c5e
|
|
| BLAKE2b-256 |
c253bd0eabed70680b00ae4e49501977d6d6d04c783ac78761dd41b91835cc0e
|
File details
Details for the file fastgraphfpms-1.0.4-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: fastgraphfpms-1.0.4-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 230.0 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9889b33e35dd09d356fe711b407eb2f7f37e3de08845bf361e01eb31f41125d9
|
|
| MD5 |
a95fc7cc016103a8b82cb48d89b2a2b9
|
|
| BLAKE2b-256 |
bdc818debf2d4597c67b4f63717fdf6c03e3ab92d3324bd931b41548316dd0b2
|