This documentation is being rewritten. If something looks off, please cross-check with the Boost 1.91.0 Boost.Graph docs and open an issue.

Internal Property Tags (Legacy)

Prefer bundled properties for new code. This page documents the older tag-based approach that attaches properties via property<> template chains at graph definition time.

When tags are required

Some BGL utilities only work with tag-based internal properties. For example, randomize_property<edge_weight_t>(g, gen) calls get(Property(), g) internally, which requires the property to be declared as an internal tag in the graph type. Bundled properties will not satisfy this lookup.

Unlike vertex_index_t which is automatic with vecS, there is no automatic edge_index. If you need an edge index (e.g. for exterior edge property maps), you must declare it as an internal property and assign values manually when adding edges.

Syntax

Declare the property when you define the graph type:

using Graph = adjacency_list<vecS, vecS, directedS,
    no_property,
    property<edge_weight_t, double>>;

Obtain the property map through the tag:

auto weight = get(edge_weight, g);
double w = get(weight, some_edge);
put(weight, some_edge, 3.14);

Chain multiple properties with a nested property<>:

using Graph = adjacency_list<vecS, vecS, directedS,
    no_property,
    property<edge_weight_t, int,
        property<edge_color_t, default_color_type>>>;

Example

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/random.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <iostream>

using namespace boost;
using Graph = adjacency_list<vecS, vecS, directedS,
    no_property, property<edge_weight_t, double>>;

int main() {
    Graph g;
    add_edge(0, 1, g);
    add_edge(1, 2, g);
    add_edge(2, 0, g);
    add_edge(0, 2, g);

    // randomize_property requires tag-based internal properties
    mt19937 gen(42);
    randomize_property<edge_weight_t>(g, gen);

    // obtain the property map via the tag
    auto weight = get(edge_weight, g);

    graph_traits<Graph>::edge_iterator ei, ei_end;
    for (tie(ei, ei_end) = edges(g); ei != ei_end; ++ei) {
        std::cout << source(*ei, g) << " -> " << target(*ei, g)
                  << "  weight=" << get(weight, *ei) << "\n";
    }
}
0 -> 1  weight=1.60864e+09
0 -> 2  weight=3.42113e+09
1 -> 2  weight=4.08329e+09
2 -> 0  weight=7.87846e+08

Available tags

Vertex tags

Tag Typical use

vertex_index_t

Built-in vertex numbering (automatic with vecS)

vertex_index1_t, vertex_index2_t

Secondary indices (used by isomorphism algorithms)

vertex_name_t

Vertex labels

vertex_distance_t, vertex_distance2_t

Shortest-path distances

vertex_color_t

Algorithm traversal colors

vertex_degree_t, vertex_in_degree_t, vertex_out_degree_t

Degree properties

vertex_current_degree_t

Used by Sloan ordering

vertex_priority_t

Used by Sloan ordering

vertex_discover_time_t, vertex_finish_time_t

DFS time stamps

vertex_predecessor_t

Predecessor in shortest-path tree

vertex_rank_t

Disjoint sets rank

vertex_centrality_t

Betweenness centrality values

vertex_lowpoint_t

Biconnected components lowpoint

vertex_potential_t

Min-cost flow potentials

vertex_root_t

Disjoint sets root

Edge tags

Tag Typical use

edge_index_t

Edge numbering (must be supplied manually, unlike vertex_index)

edge_name_t

Edge labels

edge_weight_t, edge_weight2_t

Edge weights / costs

edge_color_t

Edge traversal colors

edge_capacity_t

Max-flow capacity

edge_residual_capacity_t

Max-flow residual capacity

edge_reverse_t

Reverse-edge descriptor (max-flow)

edge_flow_t

Current flow (min-cost flow)

edge_centrality_t

Edge betweenness centrality

edge_discover_time_t

Edge discovery time

Graph tags

Tag Typical use

graph_name_t

Name of the graph (used by GraphViz I/O)

graph_visitor_t

Internal use by algorithms