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 |
|---|---|
|
Built-in vertex numbering (automatic with |
|
Secondary indices (used by isomorphism algorithms) |
|
Vertex labels |
|
Shortest-path distances |
|
Algorithm traversal colors |
|
Degree properties |
|
Used by Sloan ordering |
|
Used by Sloan ordering |
|
DFS time stamps |
|
Predecessor in shortest-path tree |
|
Disjoint sets rank |
|
Betweenness centrality values |
|
Biconnected components lowpoint |
|
Min-cost flow potentials |
|
Disjoint sets root |
Edge tags
| Tag | Typical use |
|---|---|
|
Edge numbering (must be supplied manually, unlike |
|
Edge labels |
|
Edge weights / costs |
|
Edge traversal colors |
|
Max-flow capacity |
|
Max-flow residual capacity |
|
Reverse-edge descriptor (max-flow) |
|
Current flow (min-cost flow) |
|
Edge betweenness centrality |
|
Edge discovery time |