在BOOST GRAPH中定义图形后,在构造函数中初始化filtered_graph对象 [英] To initialize a filtered_graph object in constructor after graph is defined in BOOST GRAPH

查看:299
本文介绍了在BOOST GRAPH中定义图形后,在构造函数中初始化filtered_graph对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在boost中初始化filtered_graph中有一个查询。

I have a query in initializing filtered_graph in boost.

这里是我的代码,

 // predicate 
 template <typename TGraph>
 struct edge_predicate
 {
   bool operator()(const typename boost::graph_traits<TGraph>::edge_descriptor& v) const
   {
     return true //testing purpose
    }
  };

// class 
class A{

 typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, Node_Info, Edge_Info > Graph_t;
 typedef boost::filtered_graph < Graph_t , edge_predicate > FilteredGraphType_t;

 // members
 Graph G;
 FilteredGraphType_t FG() ; // empty filter graph ???

 // constructor for A
 template < ..typename list > 
 A (  ... input iterators list...  )
 {
    fill the graph G with some values passed in constructor argument list.

    // predicate
    edge_predicate< Graph_t >  EPred;

    //filtered_graph
    FilteredGraphType_t FG( G, EPred);   // I am passing on edge predicate.
 }

};

// member function:
FilteredGraphType_t&   get_filtered_graph() 
{   
   return FG; 
 }

问题:

FG是A类的成员,G也是A的成员。最初G是空对象,所以是FG我想的,..

FG is a member of class A, and G is also a member of A. Initially G is empty object, so is FG I suppose,..

A,我用我的逻辑(如顶点数,边缘等)填充图G.
现在,我想创建一个过滤器FG (它是A类的成员)在图G(G填充后)。

In constructor of A, I fill Graph G with my logic ( such as number of vertices, edges etc ). Now, I want to create a filter FG (which is member of class A) over graph G (after G is filled).

我想要的原因是,这个过滤的图形作为一个其他类构造函数的引用传递。这迫使我把FG作为类A的成员(我可以在A本身的构造函数中创建过滤器图的新实例,但它不会用于返回对FG的引用。)

The reason I want this is that this filtered graph is passed as a reference to some other class constructor. This forces me to make FG as member of class A. ( I could create new instance of filter graph in constructor of A itself, but it wont serve the purpose of returning the reference to FG. )

我希望很清楚。请建议

推荐答案

您可以让您的代码编译并运行正常。请尝试按如下方式重新组织构造函数:

You can make your code compile and work OK. Try reorganizing the constructor as follows:

// constructor for A
 template < ..typename list > 
 A (  ... input iterators list...  )
      : G() //calls constructor for G
      , EPred(...) //some constructor for predicate
      , FG( boost::make_filtered_graph(G, EPred) ) //creates your filtered graph
{
// fill the graph G with some values passed in constructor argument list.
}

其余代码可保持不变。

这篇关于在BOOST GRAPH中定义图形后,在构造函数中初始化filtered_graph对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆