2012-11-13 5 views
3

BGL을 사용하여 필터링 된 그래프의 연결된 구성 요소를 어떻게 계산합니까? "활성"이라는 사용자 지정 버텍스 속성을 확인하고 "살아있는"버텍스 만 반환하지만 filtered_graphconnected_components 쵸크를 반환하는 필터를 만들었습니다. 나는 필터링 된 그래프가 인접하지 않은 버텍스 ID를 가지므로 정의 된 operator[]이 더 이상 정의되어 있지 않지만 왜 또는 어떻게 코딩해야하는지 잘 모르겠다는 사실과 관련이 있다고 생각합니다. 나는 (계보를 제거)하는 얻을필터링 된 그래프의 연결된 구성 요소를 찾으십시오.

typedef boost::adjacency_list<boost::hash_mapS, boost::vecS, boost::undirectedS, VertexProperties> Graph; 
typedef boost::property_map<Graph, ::vertex_alive_t>::type AliveMap; 

template <typename AliveMap> 
struct vertex_is_alive { 
    vertex_is_alive() { } 
    vertex_is_alive(AliveMap alive) : m_alive(alive) { } 
    template <typename Vertex> 
    bool operator()(const Vertex& v) const { 
    return boost::get(m_alive,v) == STILL_ALIVE_CODE; 
    } 
    AliveMap m_alive; 
}; 

Graph G; 
//generate G... 
int N = boost::num_vertices(G); 
vector<int> component(N); 
int num = boost::connected_components(G, &component[0]); 
//do something with component and play around with vertex_alive statuses...this part works fine. 
vertex_is_alive<AliveMap> filter(boost::get(::vertex_alive_t(), G)); 
boost::filtered_graph<Graph, vertex_is_alive<AliveMap> > fG (G, filter); 
int num = boost::connected_components(fG, &component[0]); 
//this makes it choke 

오류 메시지 :

/usr/local/include/boost/property_map/property_map.hpp:354:56: error: no match for ‘operator[]’ in ‘((const boost::vec_adj_list_vertex_property_map<boost::adjacency_list<boost::hash_mapS, boost::vecS, boost::undirectedS, boost::property<vertex_alive_t, unsigned int> >, boost::adjacency_list<boost::hash_mapS, boost::vecS, boost::undirectedS, boost::property<vertex_alive_t, unsigned int> >*, unsigned int, unsigned int&, vertex_alive_t>&)pa)[k]’ 
/usr/local/include/boost/property_map/property_map.hpp:354:56: note: candidate is: 
In file included from /usr/local/include/boost/graph/adjacency_list.hpp:245:0, 
       from main.cpp:1: 
/usr/local/include/boost/graph/detail/adjacency_list.hpp:2465:24: note: Reference boost::vec_adj_list_vertex_property_map<Graph, GraphPtr, ValueType, Reference, Tag>::operator[](boost::vec_adj_list_vertex_property_map<Graph, GraphPtr, ValueType, Reference, Tag>::key_type) const [with Graph = boost::adjacency_list<boost::hash_mapS, boost::vecS, boost::undirectedS, boost::property<vertex_alive_t, unsigned int> >; GraphPtr = boost::adjacency_list<boost::hash_mapS, boost::vecS, boost::undirectedS, boost::property<vertex_alive_t, unsigned int> >*; ValueType = unsigned int; Reference = unsigned int&; Tag = vertex_alive_t; boost::vec_adj_list_vertex_property_map<Graph, GraphPtr, ValueType, Reference, Tag>::key_type = unsigned int] 
/usr/local/include/boost/graph/detail/adjacency_list.hpp:2465:24: note: no known conversion for argument 1 from ‘const boost::detail::edge_desc_impl<boost::undirected_tag, unsigned int>’ to ‘boost::vec_adj_list_vertex_property_map<boost::adjacency_list<boost::hash_mapS, boost::vecS, boost::undirectedS, boost::property<vertex_alive_t, unsigned int> >, boost::adjacency_list<boost::hash_mapS, boost::vecS, boost::undirectedS, boost::property<vertex_alive_t, unsigned int> >*, unsigned int, unsigned int&, vertex_alive_t>::key_type {aka unsigned int}’ 
+1

'boost :: filtered_graph <그래프, 부스트 :: keep_all, vertex_is_alive > fG (G, boost :: keep_all(), filter);'를 사용해야합니다. 필터링 된 그래프의 서명은 ' filtered_graph '이므로 꼭지점 필터를 가장자리로 사용했습니다. 오류의 마지막 줄은'boost :: get (m_alive, x)'는 x가 정점 기술자 (unsigned int)이고 가장자리 설명자 (const boost :: detail :: edge_desc_impl ). –

답변

2

당신은 부스트 ​​:: filtered_graph를 사용한다> FG (G는 부스트 : keep_all(), 필터); 필터링 된 그래프의 서명은 filtered_graph<Graph, EdgePredicate, VertexPredicate>이므로 꼭지점 필터를 가장자리로 사용했습니다. 오류의 마지막 줄은 boost :: get (m_alive, x)는 x가 정점 설명자 (unsigned int)이고 가장자리 설명자 (const boost::detail::edge_desc_impl<boost::undirected_tag, unsigned int>)가 전달되어야 함을 의미합니다.

관련 문제