https://github.com/ZigRazor/CXXGraph
Header-Only C++ Library for Graph Representation and Algorithms
https://github.com/ZigRazor/CXXGraph
algorithm algorithms bfs-algorithm cpp cpp-library cpp17 cycle-detection dfs-algorithm dijkstra-algorithm graph graph-algorithms graph-analysis graph-theory-algorithms hacktoberfest hacktoberfest-accepted header-only machine-learning partitioning partitioning-algorithms search-algorithm
Last synced: 24 days ago
JSON representation
Header-Only C++ Library for Graph Representation and Algorithms
- Host: GitHub
- URL: https://github.com/ZigRazor/CXXGraph
- Owner: ZigRazor
- License: mpl-2.0
- Created: 2020-06-19T17:11:45.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-10-31T08:06:54.000Z (about 1 month ago)
- Last Synced: 2025-10-31T10:10:16.869Z (about 1 month ago)
- Topics: algorithm, algorithms, bfs-algorithm, cpp, cpp-library, cpp17, cycle-detection, dfs-algorithm, dijkstra-algorithm, graph, graph-algorithms, graph-analysis, graph-theory-algorithms, hacktoberfest, hacktoberfest-accepted, header-only, machine-learning, partitioning, partitioning-algorithms, search-algorithm
- Language: C++
- Homepage: https://zigrazor.github.io/CXXGraph/
- Size: 71.8 MB
- Stars: 650
- Watchers: 17
- Forks: 138
- Open Issues: 49
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Citation: CITATION
- Security: SECURITY.md
Awesome Lists containing this project
- fucking-awesome-cpp - CXXGraph - free C++(17) graph header-only library for representation and algorithms execution. [AGPL-3.0] (Graph)
- awesome-hpp - CXXGraph - AGPL%203.0-blue.svg)](https://opensource.org/licenses/AGPL-3.0) | (Graph)
- awesome-cpp - CXXGraph - free C++(17) graph header-only library for representation and algorithms execution. [AGPL-3.0] (Graph)
README

# CXXGraph

[](https://doi.org/10.5281/zenodo.5878831)
[](https://doi.org/10.6084/m9.figshare.18705572.v1)
[](https://codecov.io/gh/ZigRazor/CXXGraph)
[](https://www.codefactor.io/repository/github/zigrazor/cxxgraph)
[](https://github.com/ZigRazor/CXXGraph/blob/master/LICENSE) [](https://GitHub.com/ZigRazor/CXXGraph/releases/) [](https://conan.io/center/recipes/cxxgraph)
[](https://shields.io/) [](https://shields.io/) [](https://shields.io/)
[](https://shields.io/) [](https://shields.io/)
## Introduction
**CXXGraph** is a comprehensive C++ library that manages graph algorithms. This header-only library serves as an alternative to the [Boost Graph Library (BGL)](https://www.boost.org/doc/libs/1_77_0/libs/graph/doc/index.html).
[CXXGraph Website](https://zigrazor.github.io/CXXGraph/)
## We are Looking for
**We are looking for:**
- **A Web Developer** for the development of the CXXGraph website. All documentation is currently hosted on this GitHub page.
- **Developers and Contributors** to provide input. If you are new to the open-source world, we will guide you step by step!
If you are interested, please contact us at or contribute to this project. We are waiting for you!
## Table of Contents
- [CXXGraph](#cxxgraph)
- [Introduction](#introduction)
- [We are Looking for...](#we-are-looking-for)
- [Table of Contents](#table-of-contents)
- [Install and Uninstall](#install-and-uninstall)
- [Install Linux Tarballs](#install-linux-tarballs)
- [Install RPM](#install-rpm)
- [Install DEB](#install-deb)
- [Install From Source](#install-from-source)
- [Requirements](#requirements)
- [How to use](#how-to-use)
- [Examples](#examples)
- [Unit-Test Execution](#unit-test-execution)
- [Google Test Installation](#google-test-installation)
- [How to Compile Test](#how-to-compile-test)
- [How to Run Test](#how-to-run-test)
- [Benchmark Execution](#benchmark-execution)
- [Google Benchmark Installation](#google-benchmark-installation)
- [How to Compile Benchmark](#how-to-compile-benchmark)
- [How to Run Benchmark](#how-to-run-benchmark)
- [Benchmark Results](#benchmark-results)
- [Packaging](#packaging)
- [Tarballs](#tarballs)
- [RPM](#rpm)
- [(Fedora/CentOS/RedHat)](#fedoracentosredhat)
- [DEB](#deb)
- [(Debian/Ubuntu)](#debianubuntu)
- [Algorithms, Classes and Network Dynamics](#algorithms-classes-and-network-dynamics)
- [How to contribute](#how-to-contribute)
- [Roadmap](#roadmap)
- [Contact](#contact)
- [Support](#support)
- [References](#references)
- [Credits](#credits)
- [Contributors](#contributors)
- [Cite Us](#cite-us)
- [Other Details](#other-details)
- [Author](#author)
## Install and Uninstall
### Install Linux Tarballs
To install on Unix/Linux systems, execute the following from the command line:
`$ sudo tar xjf CXXGraph-{version}.tar.bz2`
To uninstall:
`$ sudo rm -f /usr/include/Graph.hpp /usr/include/CXXGraph*`
### Install RPM
To install on Fedora/CentOS/RedHat systems, execute the following from the command line:
`$ sudo rpm -ivh CXXGraph-{version}.noarch.rpm`
To uninstall:
`$ sudo rpm -e CXXGraph-{version}`
### Install DEB
To install on Debian/Ubuntu systems, execute the following from the command line:
`$ sudo dpkg -i CXXGraph_{version}.deb`
To uninstall:
`$ sudo apt-get remove CXXGraph`
### Install From Source
For self-compiled installations using CMake, execute the following from the command line once compilation is complete:
`$ sudo make install`
## Prerequisites
- The minimum C++ standard required is **C++17**
- A GCC compiler version 7.3.0 and later *OR* a MSVC compiler that supports C++17
## How to use
To use the library **simply include the header file `CXXGraph.hpp`**, (make sure to add the [include folder](https://github.com/ZigRazor/CXXGraph/tree/master/include) to your compiler's inlcude path).
CXXGraph revolves around the graph object which contains nodes and edges. This object can then be manipulated with a wide variety of algorithms. Please see the [examples section](#examples), [examples folder](https://github.com/ZigRazor/CXXGraph/tree/master/examples) and [website](https://zigrazor.github.io/CXXGraph/) for more information
## Examples
In this example, the shortest path between nodeA and nodeC is obtained using Dijkstra's algorithm.
```cpp
#include
#include "CXXGraph/CXXGraph.hpp"
int main(){
CXXGraph::Node nodeA("A", 1);
CXXGraph::Node nodeB("B", 2);
CXXGraph::Node nodeC("C", 3);
CXXGraph::DirectedWeightedEdge edge1("1", nodeA, nodeB, 1);
CXXGraph::DirectedWeightedEdge edge2("2", nodeB, nodeC, 1);
CXXGraph::UndirectedWeightedEdge edge3("3", nodeA, nodeC, 6);
CXXGraph::T_EdgeSet edgeSet;
edgeSet.insert(make_shared>(edge1));
edgeSet.insert(make_shared>(edge2));
edgeSet.insert(make_shared>(edge3));
CXXGraph::Graph graph(edgeSet);
CXXGraph::DijkstraResult res = graph.dijkstra(nodeA, nodeC);
for(auto node_user_id : res.path){
std::cout << node_user_id << '\n';
}
}
```
See more examples in the [examples folder](https://github.com/ZigRazor/CXXGraph/tree/master/examples).
## Unit-Test Execution
The Unit-Test requires CMake 3.9 and later, and the **[GoogleTest](https://github.com/google/googletest)** library.
### Install GoogleTest
[GoogleTest](https://github.com/google/googletest)
```bash
git clone https://github.com/google/googletest.git
cd googletest # Main directory of the cloned repository
mkdir -p build # Create a directory to hold the build output
cd build
cmake .. # Generate native build scripts for GoogleTest
make # Compile
sudo make install # Install in /usr/local/ by default
```
### How to Compile GoogleTest
From the base directory:
```bash
mkdir -p build # Create a directory to hold the build output
cd build # Enter the build folder
cmake -DTEST=ON .. # Generate native build scripts for GoogleTest,
make # Compile
```
### How to Run GoogleTest
After the build has compiled, run the "test_exe" executable in the "build" directory with the following command:
`./test_exe`
## Benchmark Execution
The Benchmark requires CMake 3.9 and later, the **GoogleTest** library, and the **Google Benchmark** library.
### Install Google Benchmark
[Google Benchmark](https://github.com/google/benchmark)
```bash
# Check out the library
$ git clone https://github.com/google/benchmark.git
# Google Benchmark requires GoogleTest as a dependency. Add the source tree as a subdirectory
$ git clone https://github.com/google/googletest.git benchmark/googletest
# Go to the library's root directory
$ cd benchmark
# Make a build directory to place the build output
$ cmake -E make_directory "build"
# Generate the build system files with CMake
$ cmake -E chdir "build" cmake -DCMAKE_BUILD_TYPE=Release ../
# If starting with CMake 3.13, you can use the following:
# cmake -DCMAKE_BUILD_TYPE=Release -S . -B "build"
# Build the library
$ cmake --build "build" --config Release
# Install the library
$ sudo cmake --build "build" --config Release --target install
```
### How to Compile Google Benchmark
From the base directory:
```bash
mkdir -p build # Create a directory to hold the build output
cd build # Enter the build folder
cmake -DBENCHMARK=ON .. # Generate native build scripts for Google Benchmark
make # Compile
```
### How to Run Google Benchmark
After the build has compiled, run the "benchmark" executable in the "build" directory with the following command:
`./benchmark`
### Benchmark Results
You can check the benchmark result using this [link](https://zigrazor.github.io/CXXGraph/dev/bench/).
## Packaging
### Tarballs
To create a tarball package, execute the following from the command line:
```bash
# Enter Packaging Directory
$ cd packaging
# Execute the script to generate tarballs
$ ./tarballs.sh
```
### RPM
#### (Fedora/CentOS/RedHat)
To create an RPM package, execute the following from the command line:
```bash
# Enter Packaging Directory
$ cd packaging/rpm
# Execute the script to generate tarballs
$ ./make_rpm.sh
```
### DEB
#### (Debian/Ubuntu)
To create a deb package, execute the following from the command line:
```bash
# Enter Packaging Directory
$ cd packaging/deb
# Execute the script to generate tarballs
$ ./make_deb.sh
```
## Algorithms, Classes and Network Dynamics
Both the [Doxygen documentation](https://rawcdn.githack.com/ZigRazor/CXXGraph/master/docs/html/index.html) and the [website](https://zigrazor.github.io/CXXGraph/) provide implementation and explanation information on the [classes](https://rawcdn.githack.com/ZigRazor/CXXGraph/master/docs/html/classes.html) and [algorithms](https://zigrazor.github.io/CXXGraph/component-explanation/regular-algorithm) of CXXGraph.
#### Classes
The Classes Explanation can be found in the [classes section](https://rawcdn.githack.com/ZigRazor/CXXGraph/master/docs/html/classes.html) of the [Doxygen documentation](https://rawcdn.githack.com/ZigRazor/CXXGraph/master/docs/html/index.html).
#### Network Dynamics
More information can be found [here](https://zigrazor.github.io/CXXGraph/component-explanation/network-dynamics).
- Adjacency Matrix
- Degree Matrix
- Laplacian Matrix
- Transition Matrix
### Algorithms
The following is a list of all the implemented algorithms, more information on the algorithms can be found [here](https://zigrazor.github.io/CXXGraph/component-explanation/regular-algorithm).
#### Graph Traversal Algorithms
- Breadth First Search (BFS)
- Depth First Search (DFS)
- Best First Search (a heuristic-based traversal)
- Bron–Kerbosch Algorithm (for finding maximal cliques; DFS-based)
#### Shortest Path Algorithms
- Dijkstra's Algorithm (single-source shortest path, non-negative weights)
- Bellman-Ford Algorithm (handles negative weights)
- Floyd–Warshall Algorithm (all-pairs shortest path)
- Dial's Algorithm (optimized Dijkstra for small integer weights)
#### Minimum Spanning Tree Algorithms
- Prim's Algorithm
- Kruskal's Algorithm
- Borůvka's Algorithm
#### Network Flow Algorithms
- Ford–Fulkerson Algorithm (maximum flow)
- Hopcroft–Karp Algorithm (maximum bipartite matching)
#### Connectivity and Component Detection
- Kosaraju's Algorithm (strongly connected components in directed graphs)
- Tarjan's Algorithm (strongly connected components or articulation points)
- Connectivity (general graph connectivity checking)
- Cycle Detection
#### Topological & Dependency Sorting
- Topological Sort
- Kahn’s Algorithm (BFS-based topological sorting)
- Tarjan’s Algorithm (DFS-based topological sorting)
#### Eulerian Path/Cycle Detection
- Hierholzer's Algorithm
#### Graph Transformation
- Transitive Reduction (reduce graph to essential edges while preserving reachability)
#### Graph Coloring Algorithms
- Welsh–Powell Coloring Algorithm
#### Partition Algorithms
- Vertex-Cut
- Edge Balanced Vertex-Cut
- Edge Balanced Vertex-Cut based on this [paper](https://arxiv.org/abs/2010.09007)
- Greedy Vertex-Cut
- High Degree Replicated First
## How to contribute
[](https://GitHub.com/ZigRazor/CXXGraph/graphs/contributors/)
If you want to give your support you can create a ***pull request*** [](https://GitHub.com/ZigRazor/CXXGraph/pull/) or report an ***issue*** [](https://GitHub.com/ZigRazor/CXXGraph/issues/).
If you want to change the code, fix an issue, or implement a new feature please read our [CONTRIBUTING Guide](https://github.com/ZigRazor/CXXGraph/blob/master/CONTRIBUTING.md).
If you want to discuss new features or you have any questions or suggestions about the library, please open a [Discussion](https://github.com/ZigRazor/CXXGraph/discussions) or simply chat on [](https://gitter.im/CXXGraph-Community/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
## Roadmap
| Completed | Description | Date of Completition |
| :-------: | :---------- | :-------------------: |
| :heavy_check_mark: | Release 0.4.0 | Oct 7, 2022 |
| :heavy_check_mark: | Release 0.5.0 | Mar 23, 2023 |
| :heavy_check_mark: | First Stable Release 1.0.0 | Mar 28, 2023 |
| :heavy_check_mark: | Release 1.0.1 | May 7, 2023 |
| :heavy_check_mark: | Release 1.1.0 | May 8, 2023 |
| :heavy_check_mark: | Stable Release 2.0.0 | Jun 1, 2023 |
| :heavy_check_mark: | Stable Release 3.0.0 | Nov 3, 2023 |
| :heavy_check_mark: | Release 3.1.0 | Jan 9, 2023 |
| :memo: | Introduce Hypergraph [#122](https://github.com/ZigRazor/CXXGraph/issues/122) | TBD |
| :memo: | Stable Release 4.0.0 | TBD |
## Stars History
[](https://star-history.com/#ZigRazor/CXXGraph&Date)
## Contact
E-mail :
[](https://gitter.im/CXXGraph-Community/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[GitHub Profile](https://github.com/ZigRazor) 

## Support
To support me, add a ***Star*** to the project [](https://GitHub.com/ZigRazor/CXXGraph/stargazers/) or ***follow me*** [](https://github.com/ZigRazor?tab=followers)
To stay updated, ***watch*** the project [](https://GitHub.com/ZigRazor/CXXGraph/watchers/)
## References
We are referenced by:
- [awesome-hpp](https://github.com/p-ranav/awesome-hpp)
- [cppreference.com](https://en.cppreference.com/w/cpp/links/libs)
- [awesome-cpp](https://github.com/fffaraz/awesome-cpp)
## Credits
Thanks to the community of [TheAlgorithms](https://github.com/TheAlgorithms) for some algorithm inspiration.
Thanks to [GeeksForGeeks](https://www.geeksforgeeks.org/) for some algorithm inspiration.
## Contributors
Thank you to all the people who have already contributed to CXXGraph!
[](https://github.com/ZigRazor/CXXGraph/graphs/contributors)
## Cited By
- Ruizhe Wang, Meng Xu, and N. Asokan. 2024. SeMalloc: Semantics-Informed Memory Allocator. In Proceedings of the 2024 on ACM SIGSAC Conference on Computer and Communications Security (CCS '24). Association for Computing Machinery, New York, NY, USA, 1375–1389.
## Cite Us
If you use this software please follow the [CITATION](https://github.com/ZigRazor/CXXGraph/blob/master/CITATION) instructions.
Thank you!
## Other Details
We participated in Hacktoberfest 2021, 2022 and 2023. Thank you to all the contributors!
View the [Estimated Value of the Project](https://www.openhub.net/p/CXXGraph/estimated_cost)
## Author
| [
@ZigRazor](https://github.com/ZigRazor) |
|:----:|