你没有显示任何代码(除了你不想写的......)。
具体形式取决于此。例如。这是捆绑的权重属性:
Live On Coliru
#include <boost/graph/adjacency_list.hpp>
#include <boost/range/iterator_range.hpp>
struct VertexProps { };
struct EdgeProps { double weight; };
int main() {
boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertexProps, EdgeProps> g;
for (auto ed : boost::make_iterator_range(edges(g)))
g[ed].weight = 1.0;
}
当然,您基本上可以通过适当的默认值实现相同的效果:
struct EdgeProps { double weight = 1.0; };
你甚至不需要循环。
带有属性映射
先从上面改编:
auto weight_map = get(&EdgeProps::weight, g);
for (auto ed : boost::make_iterator_range(edges(g)))
weight_map[ed] = 1.0;
内部属性
这也适用于捆绑属性以外的其他东西:
Live On Coliru
#include <boost/graph/adjacency_list.hpp>
#include <boost/range/iterator_range.hpp>
int main() {
boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::no_property, boost::property<boost::edge_weight_t, double> > g;
auto weight_map = get(boost::edge_weight, g);
for (auto ed : boost::make_iterator_range(edges(g)))
weight_map[ed] = 1.0;
}
外部属性
或具有完全外部属性
using Graph = boost::adjacency_list<>;
Graph g(10);
std::map<Graph::edge_descriptor, double> weights;
auto weight_map = boost::make_assoc_property_map(weights);
for (auto ed : boost::make_iterator_range(edges(g)))
weight_map[ed] = 1.0;
最后
如果目标只是具有相同的权重,只需使用常量映射:
auto weight_map = boost::make_constant_property<Graph::edge_descriptor>(1.0);