【发布时间】:2023-03-31 17:30:02
【问题描述】:
我正在尝试将boost::lengauer_tarjan_dominator_tree 与带有custom vertex properties 的图形一起使用,但甚至无法编译一个简单的示例:
#include <vector>
#include <iterator>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dominator_tree.hpp>
#include <boost/property_map/property_map.hpp>
struct GraphNode
{
explicit GraphNode(unsigned i) : index {i} {}
unsigned index;
};
using Graph = boost::adjacency_list<boost::listS, boost::listS,
boost::bidirectionalS, GraphNode, boost::no_property>;
using Vertex = boost::graph_traits<Graph>::vertex_descriptor;
int main()
{
Graph g {};
const auto u = boost::add_vertex(GraphNode {0}, g);
const auto v = boost::add_vertex(GraphNode {1}, g);
const auto x = boost::add_vertex(GraphNode {2}, g);
const auto y = boost::add_vertex(GraphNode {3}, g);
const auto z = boost::add_vertex(GraphNode {4}, g);
boost::add_edge(u, v, g);
boost::add_edge(u, x, g);
boost::add_edge(v, y, g);
boost::add_edge(x, y, g);
boost::add_edge(y, z, g);
const auto index_map = boost::get(&GraphNode::index, g);
std::vector<Vertex> dom_tree_pred_vector(boost::num_vertices(g),
boost::graph_traits<Graph>::null_vertex());
auto dom_tree_pred_map = boost::make_iterator_property_map(std::begin(dom_tree_pred_vector),
index_map);
boost::lengauer_tarjan_dominator_tree(g, u, dom_tree_pred_map);
}
我试图根据文档中给出的example 进行调整。
这是错误信息的一部分:
/usr/local/include/boost/graph/detail/adjacency_list.hpp:2544:33: error: cannot form a reference to 'void'
typedef const value_type& const_reference;
^
/usr/local/include/boost/graph/dominator_tree.hpp:355:31: error: no matching function for call to 'get'
const IndexMap indexMap = get(vertex_index, g);
我还尝试使用该方法的第二种形式显式传递索引映射,但没有成功。我注意到这个方法接口似乎与其他图形方法有点不同,例如depth_first_search,其中vertex_index_map 是一个命名参数。
是否可以将此方法与自定义顶点属性一起使用?
【问题讨论】:
标签: c++ boost boost-graph