2014-09-12 22 views
2

我有一個圖表,捆綁性提升:應用dijkstra_shortest_path()來filtered_graph

//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>,升壓的對象:: keep_all,boost :: filtered_graph,Filter>,boost :: keep_all >>,boost :: detail :: out_edge_iter,void *>,Edge> *>,unsigned long,boost :: detail :: edge_desc_impl,long >> '不能被分配,因爲它的拷貝分配操作符被隱式刪除 a = b; //要求賦值運算符 ^

什麼是不正確的?不能真正瞭解,如何解決這個問題。

回答

0

post所述,operator()應接受邊描述符而不是邊。

例如,你可以嘗試這樣的事:

bool operator() (const boost::graph_traits<graph_t>::edge_descriptor& e) const 
{ 
    ... get the variable edge of type Edge from the edge_descriptor e in some way ... 

    if(gr[edge].distance < 5) return 0; 
    return 1; 
} 

所有這些事情讓boost::graph很討厭使用。我希望開發人員能夠提高可用性,目前這種可用性非常差。

查看this post也是有用的。