# graph **Repository Path**: mirrors_boostorg/graph ## Basic Information - **Project Name**: graph - **Description**: Boost.org graph module - **Primary Language**: Unknown - **License**: BSL-1.0 - **Default Branch**: develop - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-24 - **Last Updated**: 2026-09-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Boost Graph Library [![Branch](https://img.shields.io/badge/branch-master-brightgreen.svg)](https://github.com/boostorg/graph/tree/master) [![Documentation](https://img.shields.io/badge/docs-master-brightgreen.svg)](https://www.boost.org/doc/libs/master/libs/graph/doc/html/graph/index.html) [![CI](https://github.com/boostorg/graph/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/boostorg/graph/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/boostorg/graph/branch/master/graph/badge.svg)](https://codecov.io/gh/boostorg/graph/branch/master) [![Deps](https://img.shields.io/badge/deps-master-brightgreen.svg)](https://pdimov.github.io/boostdep-report/master/graph.html) [![Enter the Matrix](https://img.shields.io/badge/matrix-master-brightgreen.svg)](https://regression.boost.org/master/developer/graph.html)
[![Branch](https://img.shields.io/badge/branch-develop-brightgreen.svg)](https://github.com/boostorg/graph/tree/develop) [![Documentation](https://img.shields.io/badge/docs-develop-brightgreen.svg)](https://www.boost.org/doc/libs/develop/libs/graph/doc/html/graph/index.html) [![CI](https://github.com/boostorg/graph/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/boostorg/graph/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/boostorg/graph/branch/develop/graph/badge.svg)](https://codecov.io/gh/boostorg/graph/branch/develop) [![Deps](https://img.shields.io/badge/deps-develop-brightgreen.svg)](https://pdimov.github.io/boostdep-report/develop/graph.html) [![Enter the Matrix](https://img.shields.io/badge/matrix-develop-brightgreen.svg)](https://regression.boost.org/develop/developer/graph.html)
[![Docs](https://img.shields.io/badge/docs-boost.org-blue.svg)](https://www.boost.org/doc/libs/release/libs/graph/doc/index.html) [![C++14](https://img.shields.io/badge/C%2B%2B-14-blue.svg)](https://en.cppreference.com/w/cpp/14) [![License: BSL-1.0](https://img.shields.io/badge/License-BSL_1.0-blue.svg)](https://www.boost.org/LICENSE_1_0.txt) [![Boost release](https://img.shields.io/github/v/release/boostorg/boost?label=Boost&color=orange)](https://github.com/boostorg/boost/releases) The Boost Graph Library (BGL) is a generic library that allows users to: 1. Represent graph data using different structures (adjacency matrix, adjacency list, compressed sparse row, vectors of vectors, user-defined data structures). 2. Attach user-defined data to vertices, edges, or the graph itself. 3. Run a large number of algorithms on the graph. 4. Inject user logic into algorithms using visitor hooks. ## Example [Try it on Compiler Explorer](https://godbolt.org/z/9Esszr9Ga) ```cpp #include #include #include #include #include #include struct City {}; struct Road { int cost; }; using namespace boost; using Graph = adjacency_list; using Vertex = graph_traits::vertex_descriptor; int main() { Graph g(4); add_edge(0, 1, Road{1}, g); add_edge(1, 2, Road{2}, g); add_edge(0, 2, Road{10}, g); add_edge(2, 3, Road{1}, g); // Storage: you control allocation, lifetime, and container type std::vector storage_pred(num_vertices(g)); std::vector storage_dist(num_vertices(g)); // Property maps: lightweight views into the storage auto index_map = get(vertex_index, g); auto costs_map = get(&Road::cost, g); auto predecessor_map = make_iterator_property_map(storage_pred.begin(), index_map); auto distance_map = make_iterator_property_map(storage_dist.begin(), index_map); dijkstra_shortest_paths(g, vertex(0, g), predecessor_map, distance_map, costs_map, index_map, std::less(), std::plus(), std::numeric_limits::max(), 0, dijkstra_visitor()); for (auto v : make_iterator_range(vertices(g))) std::cout << "distance to " << v << " = " << storage_dist[v] << "\n"; } ``` ``` distance to 0 = 0 distance to 1 = 1 distance to 2 = 3 distance to 3 = 4 ``` ## Algorithms BGL ships dozens of graph algorithms: shortest paths (Dijkstra, Bellman-Ford, A*, Floyd-Warshall, Johnson), spanning trees (Kruskal, Prim), maximum flow (Edmonds-Karp, push-relabel, Boykov-Kolmogorov), traversal (BFS, DFS, topological sort), planarity testing, isomorphism, component decomposition, and more. See the [full algorithm reference](https://becheler.github.io/graph/graph/algorithms/overview.html) for the complete catalogue. ## Help and feedback * **[GitHub Issues](https://github.com/boostorg/graph/issues)** for bug reports. Search before opening a new one. * **[GitHub Discussions](https://github.com/boostorg/graph/discussions)** for questions, design ideas, and general conversation about the library. * **[Boost mailing list](http://lists.boost.org/mailman/listinfo.cgi/boost-users)** for general Boost development. Use the `[graph]` tag in the subject line. * **CppLang Slack** for real-time chat. [Request an invite](https://cppalliance.org/slack/), then join the `#boost` channel. * **Direct contact with maintainers**: see [CONTRIBUTING.md#maintainers](CONTRIBUTING.md#maintainers). ## Using BGL Install Boost via your package manager: | Manager | Command | |---|---| | [vcpkg](https://vcpkg.io) | `vcpkg install boost-graph` | | [Conan](https://conan.io) | `conan install --requires=boost/[*]` | | apt (Debian/Ubuntu) | `sudo apt install libboost-graph-dev` | | Homebrew (macOS) | `brew install boost` | Then wire it into CMake: ```cmake find_package(Boost REQUIRED COMPONENTS graph) target_link_libraries(my_app PRIVATE Boost::graph) ``` Most of BGL is header-only. Linking `Boost::graph` is only required for the GraphViz and GraphML parsers. ## Building from source For working on BGL itself (building Boost from source, running the test suite), see [CONTRIBUTING.md](CONTRIBUTING.md).