什么是属性映射在BOOST? [英] What is a property map in BOOST?

查看:196
本文介绍了什么是属性映射在BOOST?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能解释一个升压初学者喜欢我什么是属性映射在加速?
尝试使用BGL计算强连接的部件,当我遇到这来了。
我去扔了属性映射和图形模块的文档,仍然不知道这是怎么回事。
借此code,例如:
- 什么是make_iterator_property_map功能做什么?
- 而这是什么code的含义:获得(的vertex_index,G)?

 的#include<升压/ config.hpp>
#包括LT&;矢量>
#包括LT&;&iostream的GT;
#包括LT&;升压/图/ strong_components.hpp>
#包括LT&;升压/图/ adjacency_list.hpp>INT
主要()
{
  使用名字空间boost;
  的typedef的adjacency_list<血管内皮细胞,血管内皮细胞,directedS>图形;
  const int的N = 6;
  图G(N);
  的add_edge(0,1,G);
  的add_edge(1,1,G);
  的add_edge(1,3,G);
  的add_edge(1,4,G);
  的add_edge(3,4,G);
  的add_edge(3,0,G);
  的add_edge(4,3,G);
  的add_edge(5,2,G);  的std ::矢量<&INT GT; C(N);
  INT NUM = strong_components
    (G,make_iterator_property_map(c.begin(),拿到(的vertex_index,G),C [0]));  性病::法院LT&;< 总数部分组成:&所述;&下; NUM<<的std :: ENDL;
  的std ::矢量< INT> ::迭代器I;
  对于(I = c.begin(!); I = c.end(); ++ I)
    性病::法院LT&;< 顶点<<我 - c.begin()
      << 是组件<< * I<<的std :: ENDL;
  返回EXIT_SUCCESS;
}


解决方案

其核心PropertyMaps是数据访问的抽象。在泛型编程非常迅速出现的一个问题是:我如何获得一些对象相关的数据?它可以被存储在对象本身,该对象可以是一个指针,它可能是在一些映射结构的对象之外。

您当然可以封装在一个仿函数数据访问,但很快变得单调乏味,你找一个更窄的解决方案,一个在升压选择是PropertyMaps。

记住,这仅仅是概念。具体的实例是例如一个的std ::地图(有一些语法适应),(再次,一些语法自适应)返回键的成员函数。

对你的编辑: make_iterator_property_map 构建一个<一个href=\"http://www.boost.org/doc/libs/1_55_0/libs/property_map/doc/iterator_property_map.html\">iterator_property_map.第一个参数为偏移计算的基础上的迭代器。第二个参数又是一个property_map做偏移计算。总之这提供了一种使用 vertex_descriptor的写根据<$ C指数数据到矢量$ C> vertex_descriptor的

Can someone explain to a Boost beginner like me what is a property map is in Boost? I came across this when trying to use the BGL for calculating strong connected components. I went throw the documentation for the property map and graph module and still don't know what to make of it. Take this code, for example: - what is the make_iterator_property_map function doing? - and what is the meaning of this code: get(vertex_index, G) ?

#include <boost/config.hpp>
#include <vector>
#include <iostream>
#include <boost/graph/strong_components.hpp>
#include <boost/graph/adjacency_list.hpp>

int
main()
{
  using namespace boost;
  typedef adjacency_list < vecS, vecS, directedS > Graph;
  const int N = 6;
  Graph G(N);
  add_edge(0, 1, G);
  add_edge(1, 1, G);
  add_edge(1, 3, G);
  add_edge(1, 4, G);
  add_edge(3, 4, G);
  add_edge(3, 0, G);
  add_edge(4, 3, G);
  add_edge(5, 2, G);

  std::vector<int> c(N);
  int num = strong_components
    (G, make_iterator_property_map(c.begin(), get(vertex_index, G), c[0]));

  std::cout << "Total number of components: " << num << std::endl;
  std::vector < int >::iterator i;
  for (i = c.begin(); i != c.end(); ++i)
    std::cout << "Vertex " << i - c.begin()
      << " is in component " << *i << std::endl;
  return EXIT_SUCCESS;
}

解决方案

PropertyMaps at their core are an abstraction of data access. A problem that comes up very quickly in generic programming is: How do I get data associated with some object? It could be stored in the object itself, the object could be a pointer, it could be outside of the object in some mapping structure.

You can of course encapsulate data-access in a functor, but that becomes tedious very quickly and you look for a more narrow solution, the one chosen in Boost are PropertyMaps.

Remember this is just the concept. Concrete instances are for example an std::map (with some syntactic adaption), a function returning a member of the key (again, with some syntactic adaption).

Towards your edit: make_iterator_property_map builds an iterator_property_map. The first argument provides an iterator for a basis of offset calculations. The second argument is again a property_map to do the offset calculation. Together this provides a way to use an vertex_descriptor to write data to the vector based on the index of the vertex_descriptor.

这篇关于什么是属性映射在BOOST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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