CXXGraph Documentation

repository·master·Indexed 20 days ago

https://github.com/zigrazor/cxxgraph

A comprehensive, header-only C++17 library for managing graph algorithms, designed as a developer-friendly alternative to the Boost Graph Library (BGL). It provides a wide range of implementations for graph traversal (BFS, DFS), shortest paths (Dijkstra, Bellman-Ford, Floyd-Warshall), MST (Prim, Kruskal, Borůvka), network flow, connectivity, topological sorting, and network dynamics matrices such as Adjacency and Laplacian matrices.

Tokens
2.5K
Snippets
12
Records
15
Agent score
22%

What's inside CXXGraph

  1. Install Google Benchmark for benchmarking

    master

    To run benchmarks, you need Google Benchmark, which depends on GoogleTest.

    1. Clone Google Benchmark: git clone https://github.com/google/benchmark.git
    2. Clone GoogleTest as a subdirectory of benchmark: git clone https://github.com/google/googletest.git benchmark/googletest
    3. Navigate to the benchmark directory: cd benchmark
    4. Create a build directory: mkdir build
    5. Generate build files: cmake -DCMAKE_BUILD_TYPE=Release -S . -B build (or cmake -E chdir "build" cmake -DCMAKE_BUILD_TYPE=Release ../)
    6. Build: cmake --build "build" --config Release
    7. Install: sudo cmake --build "build" --config Release --target install
    git clone https://github.com/google/benchmark.git
    git clone https://github.com/google/googletest.git benchmark/googletest
    cd benchmark
    cmake -E make_directory "build"
    cmake -E chdir "build" cmake -DCMAKE_BUILD_TYPE=Release ../
    cmake --build "build" --config Release
    sudo cmake --build "build" --config Release --target install
  2. Install GoogleTest for unit testing

    master

    CXXGraph unit tests require GoogleTest. To install it from source:

    1. Clone the repository: git clone https://github.com/google/googletest.git
    2. Create a build directory: mkdir -p build && cd build
    3. Generate build scripts: cmake ..
    4. Compile: make
    5. Install: sudo make install (installs to /usr/local/ by default).
    git clone https://github.com/google/googletest.git
    cd googletest
    mkdir -p build
    cd build
    cmake ..
    make
    sudo make install
  3. Install CXXGraph on Linux via Tarballs

    master

    To install CXXGraph on Unix/Linux systems using tarballs, extract the archive to your system using tar with sudo privileges.

    To uninstall, manually remove the header files from /usr/include/.

    # Install
    $ sudo tar xjf CXXGraph-{version}.tar.bz2
    
    # Uninstall
    $ sudo rm -f /usr/include/Graph.hpp /usr/include/CXXGraph*
  4. How to use CXXGraph in your project

    master

    CXXGraph is a header-only library. To use it, include the main header file at the top of your source code. Ensure the library's include directory is added to your compiler's include path.

    The core abstraction is the graph object, which contains nodes and edges. You can manipulate this object using the library's various algorithms.

    #include <CXXGraph/CXXGraph.hpp>
    
    // Your code here
  5. Generate benchmark results in JSON format

    master

    To generate a JSON file containing benchmark results, execute the ./benchmark binary with the following flags:

    • --benchmark_out=<filename>: Specifies the output filename.
    • --benchmark_out_format=json: Sets the output format to JSON.
    • --benchmark_repetitions=20: Runs the benchmark 20 times to ensure statistical relevance.

    Ensure you provide a valid filename for the output.

    ./benchmark --benchmark_out=<filename> --benchmark_out_format=json --benchmark_repetitions=20
  6. Compile and run a CXXGraph example

    master

    To compile a C++ file using CXXGraph, use g++ with the C++17 standard. You must provide the include paths for both the main CXXGraph header and the build-generated headers.

    Assuming you are in the directory containing your example.cpp:

    1. Compile: g++ <path_to/folder/example.cpp> -I <path_to/CXXGraph/include> -I <path_to/CXXGraph/build/include> -std=c++17
    2. Run: ./a.out
    # Compile
    g++ <path_to/folder/example.cpp> -I <path_to/CXXGraph/include> \
      -I <path_to/CXXGraph/build/include> -std=c++17
    
    # Run
    ./a.out
  7. Install CXXGraph via RPM (Fedora/CentOS/RedHat)

    master

    Use the rpm package manager to install or uninstall CXXGraph on Fedora, CentOS, or RedHat systems.

    # Install
    $ sudo rpm -ivh CXXGraph-{version}.noarch.rpm
    
    # Uninstall
    $ sudo rpm -e CXXGraph-{version}
  8. Compare two benchmark JSON files

    master

    To compare the results of two different benchmark runs, use the compare.py script. The script requires the directory where benchmarks are stored and the absolute paths to the two JSON files you wish to compare.

    Usage pattern: ./compare.py <benchmark_dir> <path_to_file1.json> <path_to_file2.json>

    ./compare.py benchmarks /workspaces/CXXGraph/benchmark/results/file1.json /workspaces/CXXGraph/benchmark/results/file2.json