我有一个捆绑属性的图表
//property
struct Edge
{
int distance;
};
//graph
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, Node, Edge> graph_t;
//predicate
template <typename Graph>
struct Filter
{
const Graph gr;
Filter(const Graph &g): gr(g) {}
bool operator() (const Edge &e) const {
if(gr[e].distance < 5) return 0;
return 1;
}
};
Filter <graph_t> filter(g);
boost::filtered_graph <graph_t, Filter <graph_t> > fg(g, filter);
我想将dijkstra_shortest_path算法应用于过滤图 .
std::vector<int> d(num_vertices(fg));
std::vector<v> p(boost::num_vertices(fg));
boost::dijkstra_shortest_paths(fg, nodes[0], boost::weight_map(get(&Edge::distance, fg))
.distance_map(boost::make_iterator_property_map(d.begin(), get(boost::vertex_index, fg)))
.predecessor_map(boost::make_iterator_property_map(p.begin(), get(boost::vertex_index, fg))));
我得到的错误,编译时:
/Users/artem/Documents/boost_1_55_0/boost/concept_check.hpp:142:错误:'boost :: filter_iterator>类型的对象,boost :: keep_all,boost :: filtered_graph,Filter>,boost :: keep_all >>,提升:: detail :: out_edge_iter,void *>,Edge> *>,unsigned long,boost :: detail :: edge_desc_impl,long >>>'无法分配,因为其拷贝赋值运算符被隐式删除a = b; //需要赋值运算符^
什么是不正确的?无法真正理解,如何解决这个问题 .
1 回答
如post中所述,您的
operator()
应接受边描述符而不是边 .例如,您可以尝试这样的事情:
所有这些都使
boost::graph
非常讨厌使用 . 我希望开发人员能够提高可用性,目前这种可用性非常差 .看看this post可能也很有用 .