加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – Boost Graph Library:捆绑属性并跨边迭代

发布时间:2020-12-16 07:27:28 所属栏目:百科 来源:网络整理
导读:只是试图了解Boost图库,我有几个问题.我正在编写一些代码,它是围绕BGL图形的包装类.我的想法是,我可以操作我想要的图形,然后调用包装器方法以GEXF( XML)格式输出图形. 我的代码是这样的: struct Vertex { std::string label; ...};struct Edge { std::strin
只是试图了解Boost图库,我有几个问题.我正在编写一些代码,它是围绕BGL图形的包装类.我的想法是,我可以操作我想要的图形,然后调用包装器方法以GEXF( XML)格式输出图形.

我的代码是这样的:

struct Vertex {
   std::string label;
   ...
};

struct Edge {
   std::string label;
   double weight;
   ...
};

typedef boost::adjacency_list<boost::vecS,boost::vecS,boost::directedS,Vertex,Edge> GraphType;

template <typename Graph>
class GEXF
{
   private:
      Graph graph;
   ...
};

template <typename Graph>
void GEXF<Graph>::buildXML()
{
   ...

   // output the edges
   property_map<adjacency_list<>,edge_index_t>::type edge_id = get(edge_index,graph);
   GraphType::edge_iterator e,e_end;
   for(tie(e,e_end) = edges(graph); e != e_end; ++e)
   {
      xmlpp::Element *edge = ePtr->add_child("edge");

      // next line gives an error,property not found
      edge->set_attribute("id",tostring<size_t>(get(edge_id,*e)));
      edge->set_attribute("source",tostring<size_t>(source(*e,graph)));
      edge->set_attribute("target",tostring<size_t>(target(*e,graph)));
   }
}

...
// instantiate in main():
GEXF<GraphType> gexf;

这是我的问题:

>当我使用捆绑属性时,我可以访问vertex_index,但我无法访问edge_index.如何访问边缘索引?
>在上面的代码中,我想保持GEXF类的通用性,但是当我尝试声明Graph :: edge_iterator e,e_end时遇到了问题.上面的代码有效,但它使用的是具体类型.我应该如何一般性地声明edge_iterator?

解决方法

默认情况下,boost :: adjacency_list< ...>中没有edge_index.对象,因为维护一个会影响复杂性.您必须自己创建一个,但必须注意它提供所需的功能.

以前:

Boost Subgraph and Bundled properties

edge_index zero for all edges?

Boost Graph edges with indexes

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读