简体   繁体   English

结合使用Boost Boost_shortest_path_nonnegative_weights()和捆绑属性

[英]Use Boost successive_shortest_path_nonnegative_weights() with bundled properties

Well, the title says it all,b ut I simply cannot get it to work: (the program provided is a sample program, for demonstration purposes - it's not just copy-pasted from my project) 好吧,标题说明了一切,但我根本无法使它正常工作:(提供的程序是示例程序,出于演示目的-不仅仅是从我的项目中复制粘贴)

#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;
}

I get the following error: 我收到以下错误:

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>’

Where am I going wrong? 我要去哪里错了? (I'm using Boost 1.55 since the algorithm is only defined in that version) (我正在使用Boost 1.55,因为该算法仅在该版本中定义)

Edit: I solved the problem, will supply answer in a few hours. 编辑:我解决了问题,将在几个小时内提供答案。

The solution was that I used slightly wrong syntax ( boost:: specifiers where they were really not necessary) and I did not have an output map. 解决的办法是我使用了稍微错误的语法(在实际上没有必要的地方使用boost::说明符),并且没有输出映射。 Solution: 解:

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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM