Boost图清除边参数不匹配
据Boost图清除边参数不匹配,boost,boost-graph,Boost,Boost Graph,据 清除边缘的声明是: void clear\u out\u边(顶点描述符u、邻接列表&g) 我的文件中有以下内容: typedef adjacency_list< vecS, vecS, directedS, property< vertex_name_t, std::string, property<vertex_index_t, int, property<vertex_color_t, boost::default_col
清除边缘的声明是:
void clear\u out\u边(顶点描述符u、邻接列表&g)
我的文件中有以下内容:
typedef adjacency_list<
vecS, vecS, directedS,
property<
vertex_name_t, std::string,
property<vertex_index_t, int,
property<vertex_color_t, boost::default_color_type,
property<vertex_distance_t, double,
property<vertex_predecessor_t, Traits::edge_descriptor>
> > > >,
property<
edge_index_t, int,
property<edge_capacity_t, double,
property<edge_weight_t, double,
property<edge_residual_capacity_t, double,
property<edge_reverse_t, Traits::edge_descriptor>
> > > > >
Graph;
Graph g;
编译器抱怨:
重载函数“boost::clear\u out\u edges”的实例与参数列表不匹配——参数类型为:(boost::range\u detail::integer\u迭代器,图形)C/C++(304)
我对此感到惊讶,因为通过typedef,g
是类邻接列表
的对象
非常感谢您的帮助。您正在使用v
,就像它是一个描述符,但它是一个迭代器一样。取消引用它:
clear_out_edges(*v, g);
我是否可以建议进行一点现代化,或许可以使用捆绑属性,而不必使用命名空间?从古老的文档样本中复制粘贴了太多的代码,这些文档样本是为了在c++03上编译而编写的
#include <boost/graph/adjacency_list.hpp>
using namespace boost;
using Traits = adjacency_list_traits<vecS, vecS, directedS>;
using Graph = adjacency_list<
vecS, vecS, directedS,
property<vertex_name_t, std::string,
property<vertex_index_t, int,
property<vertex_color_t, boost::default_color_type,
property<vertex_distance_t, double,
property<vertex_predecessor_t,
Traits::edge_descriptor>>>>>,
property<edge_index_t, int,
property<edge_capacity_t, double,
property<edge_weight_t, double,
property<edge_residual_capacity_t, double,
property<edge_reverse_t,
Traits::edge_descriptor>>>>>>;
int main()
{
Graph g(10);
for (auto v : boost::make_iterator_range(vertices(g))) {
clear_out_edges(v, g);
}
}
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/edmonds_karp_max_flow.hpp>
#include <boost/graph/boykov_kolmogorov_max_flow.hpp>
struct VertexProps { std::string name; };
struct EdgeProps { double capacity = 0, weight = 0, residual = 0; };
using Graph = boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS,
VertexProps, EdgeProps>;
using V = Graph::vertex_descriptor;
using E = Graph::edge_descriptor;
int main()
{
Graph g(10);
for (auto v : boost::make_iterator_range(vertices(g))) {
clear_out_edges(v, g);
}
auto idmap = get(boost::vertex_index, g);
std::vector<boost::default_color_type> colors(num_vertices(g));
std::vector<E> predecessors(num_vertices(g));
std::vector<double> distances(num_vertices(g));
auto weightmap = get(&EdgeProps::weight, g);
auto capacity_map = get(&EdgeProps::capacity, g);
auto residual_map = get(&EdgeProps::residual, g);
std::map<E, E> reverse_edges;
V src = 0;
V sink = 1;
boost::edmonds_karp_max_flow(
g, src, sink,
boost::color_map(colors.data())
.vertex_index_map(idmap)
.distance_map(distances.data())
.predecessor_map(predecessors.data())
.weight_map(weightmap)
.capacity_map(capacity_map)
.residual_capacity_map(residual_map)
.reverse_edge_map(boost::make_assoc_property_map(reverse_edges)));
}
请记住,boykov_kolmogorov_max_flow
存在一个已知问题(请参阅和)
添加了一些草图,谢谢您,一如既往地为您提供详细的答案。我确实在研究一个最大流问题,您提供的示例非常贴切。
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/edmonds_karp_max_flow.hpp>
#include <boost/graph/boykov_kolmogorov_max_flow.hpp>
struct VertexProps { std::string name; };
struct EdgeProps { double capacity = 0, weight = 0, residual = 0; };
using Graph = boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS,
VertexProps, EdgeProps>;
using V = Graph::vertex_descriptor;
using E = Graph::edge_descriptor;
int main()
{
Graph g(10);
for (auto v : boost::make_iterator_range(vertices(g))) {
clear_out_edges(v, g);
}
auto idmap = get(boost::vertex_index, g);
std::vector<boost::default_color_type> colors(num_vertices(g));
std::vector<E> predecessors(num_vertices(g));
std::vector<double> distances(num_vertices(g));
auto weightmap = get(&EdgeProps::weight, g);
auto capacity_map = get(&EdgeProps::capacity, g);
auto residual_map = get(&EdgeProps::residual, g);
std::map<E, E> reverse_edges;
V src = 0;
V sink = 1;
boost::edmonds_karp_max_flow(
g, src, sink,
boost::color_map(colors.data())
.vertex_index_map(idmap)
.distance_map(distances.data())
.predecessor_map(predecessors.data())
.weight_map(weightmap)
.capacity_map(capacity_map)
.residual_capacity_map(residual_map)
.reverse_edge_map(boost::make_assoc_property_map(reverse_edges)));
}