How to use boost::graph dijkstra's algorithm if vertex properties are pointers?

后端 未结 1 1827
说谎
说谎 2021-01-25 02:19

I use boost graph to manage graphs and I need to make a maxmin tree.
Now I\'m trying to use boost dijkstra\'s algorithm, but I use a pointer to my class as a vertex property

1条回答
  •  清歌不尽
    2021-01-25 03:17

    Q.
    If I understant it right, I use make_iterator_property_map to create an external property map, but in order to create it I need to pass the vertex ID property map. But I can't access it through boost::get, because vertex property is a pointer. What type should I pass to boost::get(some_type, m_graph) to get such ID map?

    You make /any type of propertymap that satisfies the requirement/. You don't need to associate it with the graph. You can simply pass it to the algorithms when you need to (which also makes it clear at which point you promise to have the graph data and the propertymap in synch).

    It just occurred to me that in fact you might be able to get a pass on that last issue - the burden of maintaining the property map. That is, if your index can be derived from the pointer value (perhaps retrieved from the struct it points to).

    You can use the

    • transform_value_property_map
    • function_property_map
    • perhaps both combined with e.g. compose_property_map

    Each of these types has a corresponding deducing factory method make_transform_value_property_map, make_function_property_map etc. so that you don't have to manually spell out the resulting types.

    You can search my older answers for examples of what can be done with these.

    Samples:

    • Dijkstra graph with a table of weights on each edge
    • Weight map as function in Boost Graph Dijkstra algorithm
    • General point about Property Map map set/get requests into C++ class/structure changes

    0 讨论(0)
提交回复
热议问题