Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8829183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:46:38+00:00 2026-06-14T07:46:38+00:00

How can I calculate the connected components of a filtered graph using BGL? I’ve

  • 0

How can I calculate the connected components of a filtered graph using BGL? I’ve created a working filter that checks against a custom vertex property called “alive” and returns only the “living” vertices but connected_components chokes on the filtered_graph . I think it has something to do with the fact that the filtered graph has non-contiguous vertex ids and therefore an operator[] that was defined is now no longer defined but I’m not sure why or how to code around it.

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

The error messages that I get are (removing the genealogy):

/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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:46:39+00:00Added an answer on June 14, 2026 at 7:46 am

    You should use boost::filtered_graph > fG (G, boost::keep_all(), filter);. The signature for the filtered graph is filtered_graph<Graph, EdgePredicate, VertexPredicate> so you were using your vertex filter as an edge one. The last line in your error implies that boost::get(m_alive,x) requires that x be a vertex descriptor (unsigned int) and it was being passed an edge descriptor (const boost::detail::edge_desc_impl<boost::undirected_tag, unsigned int>).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am planning to develop an application that can calculate the limit of an
How can I calculate the taskbar height, so that my winapi app starts up
I can calculate the size of the files in a tarfile in this way:
Can someone explain with an example how we can calculate the time and space
Hi i was wondering if anyone knows how i can calculate the difference between
How can I calculate the date having only the week number and day of
I can easily calculate the age of a lead in minutes with a formula
How can I calculate a point (X,Y) a specified distance away, on a rotated
How can I calculate the number of differences between two NSStrings. Example: NSString 1
How can you calculate the following Friday at 3am as a datetime object? Clarification:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.