Jeremy Siek and a University o team. and Jeremy Siek and a University of Notre Dame team. · boost.org

Boost.Graph

M

D

C++ 14 Added in Boost 1.18.0

The BGL graph interface and graph components are generic, in the same sense as the Standard Template Library (STL).

This Release

Jeremy W. Murphy

Jeremy W. Murphy

Maintainer

Arnaud Becheler

Maintainer

Arnaud Becheler

Contributor - New

Andrea Cassioli

Contributor - New

Andrea Cassioli

Contributor - New

Peter Kerzum

Contributor - New

sdarwin

sdarwin

Contributor - New

Davide Iafrate

Contributor - New

Rene Rivera

Rene Rivera

Contributor

Pavel Samolysov

Contributor

Jan-Grimo Sobez

Jan-Grimo Sobez

Contributor

Murray Cumming

Contributor

Georgy Guminov

Contributor

Alexander Grund

Alexander Grund

Contributor

Tinko Bartels

Tinko Bartels

Contributor

Murray Cumming

Murray Cumming

Contributor

Andrey Semashev

Andrey Semashev

Contributor

Joris van Rantwijk

Contributor

Dependencies

Added

Removed

Boost Graph Library

Docs C++14 CI License: BSL-1.0 Boost release

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

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/visitors.hpp>
#include <iostream>
#include <limits>
#include <vector>
struct City {};
struct Road { int cost; };
using namespace boost;
using Graph = adjacency_list<vecS, vecS, directedS, City, Road>;
using Vertex = graph_traits<Graph>::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<Vertex> storage_pred(num_vertices(g));
    std::vector<int>    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<int>(), std::plus<int>(),
        std::numeric_limits<int>::max(), 0,
        dijkstra_visitor<null_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 for the complete catalogue.

Help and feedback

Using BGL

Install Boost via your package manager:

Manager Command
vcpkg vcpkg install boost-graph
Conan conan install --requires=boost/[*]
apt (Debian/Ubuntu) sudo apt install libboost-graph-dev
Homebrew (macOS) brew install boost

Then wire it into 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.

All Time

Jeremy Siek

Jeremy Siek

Contributor

Jeremiah Willcock

Jeremiah Willcock

Contributor

Douglas Gregor

Douglas Gregor

Contributor

John Maddock

John Maddock

Contributor

Andrew Sutton

Andrew Sutton

Contributor

Vladimir Prus

Vladimir Prus

Contributor

K. Noel Belcourt

K. Noel Belcourt

Contributor

Beman Dawes

Beman Dawes

Contributor

Aaron Windsor

Aaron Windsor

Contributor

Dave Abrahams

Dave Abrahams

Contributor

Ronald Garcia

Ronald Garcia

Contributor

nobody

Contributor

Cromwell D. Enage

Cromwell D. Enage

Contributor

jrmarsha

jrmarsha

Contributor

Daniel James

Daniel James

Contributor

Peter Dimov

Peter Dimov

Contributor

Daan Kolthof

Daan Kolthof

Contributor

Jürgen Hunold

Jürgen Hunold

Contributor

Lie-Quan Lee

Contributor

sehe

sehe

Contributor

Eric Niebler

Eric Niebler

Contributor

Sven Gato Redsun

Sven Gato Redsun

Contributor

Sebastian Brockmeyer

Sebastian Brockmeyer

Contributor

E Kawashima

E Kawashima

Contributor

Mads Jensen

Mads Jensen

Contributor

Jakob Lykke Andersen

Jakob Lykke Andersen

Contributor

Josef Cibulka

Contributor

Marshall Clow

Marshall Clow

Contributor

Alexander Lauser

Alexander Lauser

Contributor

Gennaro Prota

Contributor

Stephen Kelly

Stephen Kelly

Contributor

Alec Edgington

Alec Edgington

Contributor

andrea-cassioli-maersk

andrea-cassioli-maersk

Contributor

jiyi

Contributor

Josh Marshall

Josh Marshall

Contributor

Darin Adler

Contributor

Nicholas Edmonds

Nicholas Edmonds

Contributor

Valentyn Shtronda

Valentyn Shtronda

Contributor

Stefan Slapeta

Contributor

Jonathan Turkanis

Jonathan Turkanis

Contributor

yi-ji

yi-ji

Contributor

BenPope

BenPope

Contributor

Maël Valais

Maël Valais

Contributor

Edward Diener

Edward Diener

Contributor

Akira Takahashi

Akira Takahashi

Contributor

Daniela Engert

Daniela Engert

Contributor

Anthony Van Herrewege

Contributor

Troy D. Straszheim

Troy D. Straszheim

Contributor

Glen Fernandes

Glen Fernandes

Contributor

Steven Watanabe

Steven Watanabe

Contributor

Daniel Yang

Contributor

Guillaume Melquiond

Guillaume Melquiond

Contributor

vslashg

vslashg

Contributor

Marcel Raad

Marcel Raad

Contributor

George Williams

George Williams

Contributor

Michael A. Jackson

Michael A. Jackson

Contributor

Victor A. Wagner Jr.

Contributor

Kolya Matteo

Kolya Matteo

Contributor

Aleksey Gurtovoy

Contributor

Björn Karlsson

Contributor

Andreas Huber

Contributor

Ahmed Charles

Ahmed Charles

Contributor

James E. King III

James E. King III

Contributor

marcinz

marcinz

Contributor

Arvin Schnell

Arvin Schnell

Contributor

Justin Viiret

Justin Viiret

Contributor

coderakki

coderakki

Contributor

felix

felix

Contributor

Arne B

Contributor

Jared Grubb

Jared Grubb

Contributor

Daniel J. H

Daniel J. H

Contributor

Ola Nilsson

Ola Nilsson

Contributor

mikael

mikael

Contributor

Lorenz Breidenbach

Lorenz Breidenbach

Contributor

akumta

akumta

Contributor

Matt Barr

Contributor

Denis Davydov

Denis Davydov

Contributor

Andreas Scherer

Andreas Scherer

Contributor

David Einstein

David Einstein

Contributor

Pavel I. Kryukov

Pavel I. Kryukov

Contributor

Rasmus Ahlberg

Contributor

John Zhang

John Zhang

Contributor

Mateusz Polnik

Mateusz Polnik

Contributor

Billy K. Poon

Billy K. Poon

Contributor

Viktor T

Viktor T

Contributor

Marc Glisse

Marc Glisse

Contributor

Andy Shulman

Contributor

Jonathan Wakely

Jonathan Wakely

Contributor

Caleb Epstein

Contributor

Louis Dionne

Louis Dionne

Contributor

hermann@stamm-wilbrandt.de

Contributor

Jared Khan

Jared Khan

Contributor

康小广

康小广

Contributor

Neil Groves

Neil Groves

Contributor

Alexander Zaitsev

Alexander Zaitsev

Contributor

Ashish Kumar

Ashish Kumar

Contributor

Philip Allgaier

Philip Allgaier

Contributor

char-lie

char-lie

Contributor

Vicky Vergara

Vicky Vergara

Contributor

Anthony Eden

Anthony Eden

Contributor

Jesse Li

Jesse Li

Contributor

etienneINSA

etienneINSA

Contributor

Antony Polukhin

Antony Polukhin

Contributor

Alex Hagen-Zanker

Alex Hagen-Zanker

Contributor

Jiachen Dong

Jiachen Dong

Contributor

Kohei Takahashi

Kohei Takahashi

Contributor

Nik Reiman

Nik Reiman

Contributor

hlynurf

hlynurf

Contributor

Joaquin M. López Muñoz

Joaquin M. López Muñoz

Contributor

Shoaib Meenai

Shoaib Meenai

Contributor

Ciro Santilli

Ciro Santilli

Contributor

Jens Maurer

Jens Maurer

Contributor

Francois Kritzinger

Francois Kritzinger

Contributor

ꓪꓱꓱꓠꓛꓧ

ꓪꓱꓱꓠꓛꓧ

Contributor

Derek McBlane

Derek McBlane

Contributor

l00574988

Contributor

Bruno Martinez

Bruno Martinez

Contributor

Roland Schwarz

Roland Schwarz

Contributor

Romain Geissler

Romain Geissler

Contributor

Matt Pulver

Matt Pulver

Contributor

Stephan Diederich

Stephan Diederich

Contributor

Tuukka Norri

Tuukka Norri

Contributor

Bryce Adelstein-Lelbach

Bryce Adelstein-Lelbach

Contributor

Thomas Witt

Thomas Witt

Contributor

Alisdair Meredith

Alisdair Meredith

Contributor

Jurko Gospodnetić

Jurko Gospodnetić

Contributor

Conrad Poelman

Conrad Poelman

Contributor

Julien DELACROIX

Contributor

Noel Belcourt

Noel Belcourt

Contributor

Katrin Leinweber

Katrin Leinweber

Contributor

Jean-Michaël Celerier

Jean-Michaël Celerier

Contributor

Alan Somers

Alan Somers

Contributor

Jedrzej Solecki

Contributor

Joel de Guzman

Joel de Guzman

Contributor

Stefan Hammer

Contributor

Fábio Silva

Fábio Silva

Contributor

Myles1

Myles1

Contributor

Vadim Peretokin

Vadim Peretokin

Contributor

Eugene Zelenko

Contributor

Read the original on boost.org ↗