C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Boost Graph Library:潜在的Bug大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
即使图中没有循环,BGL的depth_first_search算法有时会对访问者调用BACk_edge().根据后缘的定义,根据Boost的 DFS Visitor Documentation,这不应该发生.请注意,仅当listS用作顶点和边的表示时,这才是可重现的.

下面的代码示例(应该按原样编译)构造一个包含两个节点和一个边的图.它错误地打印“后缘”.我在这做错了吗?或者这是一个错误

#include <iostream>
using namespace std;

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/depth_first_search.hpp>
#include <boost/graph/visitors.hpp>
using namespace boost;

typedef boost::property<boost::vertex_index_t,std::size_t> VertexProperties;
typedef boost::adjacency_list<boost::listS,boost::listS,boost::bidirectionalS,VertexProperties> Graph;  // Graph object type

typedef boost::graph_Traits<Graph>::vertex_descriptor Vertex;
typedef boost::graph_Traits<Graph>::edge_descriptor Edge;

class VisitorClass : public dfs_visitor<> {
 public:
  VisitorClass() {}

  template <typename Edge,typename Graph>
  void BACk_edge(Edge,const Graph&) const {
    cout << "BACk edge" << endl;
  }
};

int
main() {
  Graph g;
  Vertex v = add_vertex(g);
  Vertex u = add_vertex(g);

  bool inserted;
  tie(tuples::ignore,inserted) = add_edge(v,u,g);
  assert(inserted);

  VisitorClass vst;
  depth_first_search(g,visitor(vst));
  // Should not print "BACk edge",but does.

  return 0;
}

在Mac OS 10.7上使用i686-apple-darwin11-llvm-g -4.2测试Boost 1.46.1;
在Debian 2.6.32-34squeeze1上使用gcc 4.4.5使用Boost 1.42.0进行测试.

解决方法

您提交了一个错误,但您没有跟进.

不久之后,你得到了答案:

我尝试了这个(修复拼写错误)并且工作正常:

#include <boost/graph/iteration_macros.hpp>

int main() {
  Graph g;   
  Vertex v = add_vertex(g);   
  Vertex u = add_vertex(g);

  graph_Traits<Graph>::vertices_size_type i = 0;  
  BGL_FORall_VERTICES(v,i++);

  bool inserted;   
  tie(tuples::ignore,g); 
  assert(inserted);

  VisitorClass vst;   
  depth_first_search(g,visitor(vst));
// Should not print "BACk edge",but does.

  return 0;
  }

(至少,它不再打印“后缘”)

大佬总结

以上是大佬教程为你收集整理的Boost Graph Library:潜在的Bug全部内容,希望文章能够帮你解决Boost Graph Library:潜在的Bug所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。