BGL dijkstra_shortest_path algorithm method does not accept my color map exterior property

橙三吉。 提交于 2019-11-28 11:38:44

The error message says that compiler does not find proper vertex_index_t property - a critical element for all search algorithms from Boost.Graph. It is not enough to define a class VertexIndexMap, you also have to tell Boost that this is your "vertex_index".

You can try to add declarations similar to following:

class VertexIndexMap //maps vertex to index
{
public:
    typedef boost::readable_property_map_tag category; 
    typedef size_t  value_type;
    typedef value_type reference;
    typedef BusRouteGraph::vertex_descriptor key_type; 

    VertexIndexMap(const BusRouteGraph& g): _g(&g) {} 

    const BusRouteGraph * _g;
};

namespace boost {

template<>
struct property_map<BusRouteGraph, vertex_index_t > {
    typedef VertexIndexMap const_type;
    //typedef type const_type ; //-- we do not define type as "vertex_index_t" map is read-only 
};

VertexIndexMap get(boost::vertex_index_t, const BusRouteGraph & g )
{
    return VertexIndexMap(g);
}

VertexIndexMap::value_type get(VertexIndexMap map, VertexIndexMap::key_type vertex)
{
    return (*map._g)[vertex].id;
}

} //namespace boost

After that you can drop the loop which inits the index_map; instead we use standard "Boost-ish" way to get the index map

VertexIndexMap index_map = get(boost::vertex_index, g); ///replaces get(&BusStop::id, g);

Then everything should work OK.

Good luck!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!