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)
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. 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));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.