我使用 boost graph 来管理图表,我需要制作一个 maxmin 树。
现在我尝试使用 boost dijkstra 算法,但我使用指向我的类的指针作为顶点属性,而不是使用typedef property<vertex_index_t, int> my_prop
,我现在无法更改它。
那么如何为我的图表创建前驱图和距离图呢?
我的代码如下所示(并且这些前驱图和距离图不起作用):
struct LinkStruct {...};
class Node {...};
typedef Node* NodePtr;
typedef adjacency_list<listS, listS, bidirectionalS, NodePtr, LinkStruct> MyGraph;
typedef MyGraph::vertex_descriptor vertex_descriptor;
MyGraph m_graph;
// Fill the graph
{...}
// Dijkstra parameters
std::vector<vertex_descriptor> result_tree(some_struct.size(), MyGraph::null_vertex());
std::vector<uint32_t> result_distances(some_struct.size(), 0);
// Compute maxmin tree
dijkstra_shortest_paths_no_color_map(
m_graph, // Graph
root_vertex, // Start vertex
weight_map( boost::get(&LinkStruct::weight, m_graph) ). // Link property map
distance_compare( [](uint32_t first, uint32_t second) -> bool {
return first > second; } ). // Compare maxmin path lengths (if maxmin > maxmin)
distance_combine( [](uint32_t first, uint32_t second) -> uint32_t {
return (first > second) ? second : first; } ). // Get min weight of the path
predecessor_map( make_iterator_property_map(result_tree.begin(),
boost::get(vertex_index, m_graph)) ). // Result tree
distance_map( make_iterator_property_map(result_distances.begin(),
boost::get(vertex_index, m_graph)) ) // Result distances
);
P.S.
我在顶点定义中使用指针,因为我有许多具有相同节点的图。
也许有某种方法可以在不更改图定义中的顶点属性的情况下进行?