嗯,标题说明了一切,但我根本无法让它工作:(提供的程序是示例程序,出于演示目的 - 它不仅仅是从我的项目中复制粘贴)
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/successive_shortest_path_nonnegative_weights.hpp>
#include <boost/property_map/property_map.hpp>
#include <boost/tuple/tuple.hpp>
typedef boost::adjacency_list_traits<boost::vecS, boost::vecS, boost::directedS> DirectedGraphTraits;
struct VertexProperty{ };
struct EdgeProperty{
double edge_capacity;
double edge_weight;
DirectedGraphTraits::edge_descriptor reverse_edge;
EdgeProperty(double distance, DirectedGraphTraits::edge_descriptor reverseEdge) :
edge_capacity(1), edge_weight(distance), reverse_edge(reverseEdge) {
};
EdgeProperty(double distance) :
edge_capacity(0), edge_weight(-distance){}
EdgeProperty(){};
};
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertexProperty, EdgeProperty> DirectedGraph;
void addEdge(DirectedGraph::vertex_descriptor source, DirectedGraph::vertex_descriptor target, double distance, DirectedGraph g){
std::pair<DirectedGraphTraits::edge_descriptor,bool> reverse = (boost::add_edge(source,target,EdgeProperty(distance),g));
boost::add_edge(target,source,EdgeProperty(distance,reverse.first),g);
}
int main(void) {
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertexProperty, EdgeProperty> DirectedGraph;
DirectedGraph g(6+2);
//add some edges here
//From source
addEdge(0,1,.0,g); addEdge(0,2,.0,g); addEdge(0,3,.0,g);
//Middle
addEdge(1,4,.2,g); addEdge(2,5,.3,g); addEdge(3,4,.1,g); addEdge(3,5,.4,g);
//To sink
addEdge(4,7,.0,g); addEdge(5,7,.0,g); addEdge(6,7,.0,g);
boost::successive_shortest_path_nonnegative_weights(g,0,7,
boost::capacity_map(boost::get(&EdgeProperty::edge_capacity,g))).
boost::reverse_edge_map(boost::get(&EdgeProperty::reverse_edge,g)).
boost::weight_map(boost::get(&EdgeProperty::edge_weight,g)));
std::cout<<"Hi";
return 0;
}
我收到以下错误:
error: ‘boost::reverse_edge_map’ is not a member of ‘boost::bgl_named_params<boost::bundle_property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertexProperty, EdgeProperty>, boost::detail::edge_desc_impl<boost::directed_tag, long unsigned int>, EdgeProperty, double>, boost::edge_capacity_t, boost::no_property>’
我哪里错了? (我正在使用Boost 1.55,因为该算法仅在该版本中定义)
编辑:我解决了问题,将在几个小时内提供答案。
答案 0 :(得分:1)
解决方案是我使用了稍微错误的语法(boost::
说明符,它们实际上没有必要)并且我没有输出映射。解决方案:
std::map<DirectedGraph::edge_descriptor, int> edge2rescap;
boost::associative_property_map<std::map<DirectedGraph::edge_descriptor, int> > out(edge2rescap);
boost::successive_shortest_path_nonnegative_weights(g, 0, 7,
capacity_map(boost::get(&EdgeProperty::edge_capacity, g))
.reverse_edge_map(boost::get(&EdgeProperty::reverse_edge, g))
.weight_map(boost::get(&EdgeProperty::edge_weight, g))
.residual_capacity_map(out));