C++ Boost

Frequently Asked Questions

  1. Why does the algorithm X work with adjacency_list where VertexList=vecS but not when VertexList=listS?

    Often the reason is that the algorithm expects to find the vertex_index property stored in the graph. When VertexList=vecS, the adjacency_list automatically has a vertex_index property. However, when VertexList=listS this is not the case, and the vertex_index property must be explicitly added, and initialized. For example,
      // specify the graph type
      typedef adjacency_list<listS, listS, undirectedS,
                             property<vertex_index_t, std::size_t>,
                             no_property
                            > graph_t;
    
      // construct a graph object
      graph_t G(num_nodes);
      // obtain a property map for the vertex_index property
      property_map<graph_t, vertex_index_t>::type
        index = get(vertex_index, G);
      // initialize the vertex_index property values
      graph_traits<graph_t>::vertex_iterator vi, vend;
      graph_traits<graph_t>::vertices_size_type cnt = 0;
      for(tie(vi,vend) = vertices(G); vi != vend; ++vi)
        put(index, *vi, cnt++);
    
  2. When using algorithm X, why do I get an error about a property not being found, such as:
    ../../../boost/concept_check.hpp:209: no match for
    `boost::detail::error_property_not_found & == 
     boost::detail::error_property_not_found &'
    
    or a message such as:
    ../../..\boost/graph/depth_first_search.hpp(78) : error C2664: 'white'
    : cannot convert parameter 1 from 
     'struct boost::detail::error_property_not_found'
     to 'enum boost::default_color_type'
    
    The reason is that the algorithm expected to find some property (like color or weight) attached to the vertices or edges of the graph, but didn't find it. You need to either add an interior property to the graph, or create an exterior property map for the property and pass it as an argument to the algorithm.