使用Boost successive_shortest_path_nonnegative_weights()捆绑属性
Use Boost successive_shortest_path_nonnegative_weights() with bundled properties
好吧,标题说明了一切,但我就是不能让它工作:(提供的程序是一个示例程序,用于演示目的-它不仅仅是从我的项目复制粘贴的)
#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,因为该算法仅在该版本中定义)
编辑:我解决了问题,几个小时后会给出答案。
解决方案是我使用了稍微错误的语法(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));
相关文章:
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- C++概念:如何使用'concept'检查模板化结构的属性?
- 子目录是否继承属性,例如add_definitions,include_directories和父Cmakelist.t
- 通过指向指针数组的指针访问子类的属性
- MSVC是否支持C++11样式的属性而不是__declspec
- QML:修改在不同QML文件(而非main.QML)中定义的子对象的属性
- 类的C++属性似乎已重新初始化
- Qt Quick-如何仅从c++代码与qml属性交互
- 用概念检查属性的类型
- C++如何将同一类的实例作为属性
- 按多个属性排序
- 主函数参数的属性
- "perf_event_attr"结构的"read_format"属性的选项到底是什么?
- C++删除未使用的类属性会导致 std::logic_error
- 无法使用 SWIG 在 Python 中实例化C++类(获取属性错误)
- 使用内存地址访问结构的属性值
- C++调用具有 *this 属性的单个帮助程序函数
- C++ 在堆栈中包含多态属性的类对象存储
- C++ 命名参数习惯用语 - 未设置字符串属性
- 使用 CTRP 时,是否访问访问父构造函数 UB 中的子属性?