我想使用Boost.Graph库中的push_relabel_max_flow
。
我已经生成了我的图表,这是我到目前为止的代码:
struct EdgeProps {
double capacity;
double residual_capacity;
Traits::edge_descriptor reverse;
};
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::no_property, EdgeProps > DirectedGraph;
DirectedGraph g;
std::vector<DirectedGraph::vertex_descriptor> vertices;
/* Filling the Graph with vertices and edges and saving the vertex-descriptors in "vertices" */
//...
//...
double flow = boost::push_relabel_max_flow(g,vertices[0],vertices[1],
vertex_index_map(boost::get(boost::vertex_index, g)).
residual_capacity_map(boost::get(&EdgeProps::residual_capacity, g)).
reverse_edge_map(boost::get(&EdgeProps::reverse, g)).
capacity_map(boost::get(&EdgeProps::capacity, g))
);
我在传递参数时遇到问题。我得到&#34; 形成对void的引用&#34; -errors:
/usr/local/include/boost/graph/detail/adjacency_list.hpp:2696: error: forming reference to void
typedef value_type& reference;
^
/usr/local/include/boost/graph/detail/adjacency_list.hpp:2697: error: forming reference to void
typedef const value_type& const_reference;
^
/usr/local/include/boost/graph/detail/adjacency_list.hpp:2701: error: forming reference to void
typename Graph::vertex_descriptor,Property,Tag> type;
^
这些并非全部,只有三个。如果您需要查看每一个,请发表评论,我会添加它们。 有没有人知道如何将参数传递给函数而不生成&#34; 参考void &#34; -error?
答案 0 :(得分:5)
boost::capacity_map
等功能可以利用named parameter idiom that the Boost Graph library provides。这些函数返回bgl_named_params
的实例,该实例具有添加更多命名参数的方法。因此,不是用逗号分隔参数,而是用点分隔它们;对于第一个之后的参数,不需要boost::
,因为它们是成员方法。
您原来的问题试图像这样打电话:
double flow = boost::push_relabel_max_flow(g, vertices[0], vertices[1],
boost::capacity_map(boost::get(&EdgeProps::capacity, g)),
boost::residual_capacity_map(boost::get(&EdgeProps::residual_capacity, g)),
boost::reverse_edge_map(boost::get(&EdgeProps::reverse, g)),
boost::vertex_index_map(boost::get(boost::vertex_index, g)));
不支持像这样传递bgl_named_params
的多个实例:它应该看起来像
double flow = boost::push_relabel_max_flow(g, vertices[0], vertices[1],
boost::capacity_map(boost::get(&EdgeProps::capacity, g)).
residual_capacity_map(boost::get(&EdgeProps::residual_capacity, g)).
reverse_edge_map(boost::get(&EdgeProps::reverse, g)));
省略vertex_index_map
参数。
只要图中的VertexList是std :: vector(即adjacency_list
的第二个模板参数是boost::vecS
),就会自动出现vertex_index属性,默认参数应该有效。
但是,在当前版本的Boost(1.61)中,最大流算法的命名参数不起作用。 这是Boost Issue 12038,并且在5月2日为fixed in the development branch。我可以确认上面的示例适用于当前的开发分支。
使用函数的7参数版本并传递所有必需的映射确实有效,但此版本不支持默认参数,因此您必须指定vertex_index映射。例如:
auto capacity = boost::get(&EdgeProps::capacity, g);
auto reverse = boost::get(&EdgeProps::reverse, g);
auto residcap = boost::get(&EdgeProps::residual_capacity, g);
auto indexmap = boost::get(boost::vertex_index, g);
double flow = boost::push_relabel_max_flow(g, vertices[0], vertices[1],
capacity, residcap, reverse, indexmap);
答案 1 :(得分:3)
据我所知,命名参数的解包代码中必定存在错误,因为以下内容编译得很干净:
<强> Live On Coliru 强>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/push_relabel_max_flow.hpp>
typedef boost::graph_traits<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS> > Traits;
struct EdgeProps {
double capacity;
double residual_capacity;
Traits::edge_descriptor reverse;
};
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::no_property, EdgeProps> DirectedGraph;
int main() {
DirectedGraph g;
std::vector<DirectedGraph::vertex_descriptor> vertices;
/* Filling the Graph with vertices and edges and saving the vertex-descriptors in "vertices" */
//...
//...
double flow = boost::push_relabel_max_flow(g, vertices[0], vertices[1],
boost::get(&EdgeProps::capacity, g),
boost::get(&EdgeProps::residual_capacity, g),
boost::get(&EdgeProps::reverse, g),
boost::get(boost::vertex_index, g)
);
}
您可能希望向库开发人员报告此事。