外部属性映射绑定到std :: vector在boost图形库 [英] External property map tied to std::vector in boost graph library

查看:244
本文介绍了外部属性映射绑定到std :: vector在boost图形库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试定义boost图的外部属性。我使用一些捆绑的属性作为内部的:

I am currently trying to define external properties of a boost graph. I use some bundled properties as internal ones:

struct VertexProperties
{
  int demand;
};

struct EdgeProperties
{ 
  uint capacity;
  int cost;
};

typedef adjacency_list <vecS, vecS, bidirectionalS, VertexProperties, EdgeProperties> Graph;

但是,在算法期间,我需要一些外部属性,即我想能够映射边/ vertices我的图形存储在std :: vector中的元素,这样我可以通过operator [](Edge e)访问它们。我站在boost文档前面没有线索。它似乎我需要一个property_map,但我不知道如何使用这些与向量一起。到目前为止,我发现的唯一例子是从顶点到向量的映射,但由于顶点是无符号整数,这是微不足道的。

However, during the algorithm I need some external properties, that is I want to be able to map edges/vertices of my graph to elements stored in a std::vector in such a way that I can access them via operator[] (Edge e). I am standing in front of the boost documentation without a clue. It seems like I need a property_map, but I don't know how to use these together with vectors. The only examples that I found so far concern maps from vertices to a vector, but as the vertices are unsigned ints this is trivial.

我真的很失望, ,我认为这会节省我很多时间来实现和测试一个图类本身,我真的很难得到这个疯狂的模板元编程的东西...

I am really frustrated by boost so far, I think it would have saved me a lot of time to implement and test a graph class by myself, I really don get this crazy template metaprogramming stuff...

推荐答案

您可以创建外部属性映射,无论您的图表中有什么内部和/或捆绑的属性。在边上创建属性映射有点困难,因为您需要一个 edge_index 映射,而 adjacency_list 默认; compressed_sparse_row_graph 但它的结构大多是只读后构造。您可以在边上使用 associative_property_map ,或者创建一个边缘索引图作为内部属性(如果你不太频繁地更改图),填充它,然后使用它构建外部属性映射(例如使用 shared_array_property_map )。

You can create external property maps regardless of what internal and/or bundled properties are in your graph. Creating property maps on edges is somewhat more difficult because you need an edge_index map, and adjacency_list doesn't have those by default; compressed_sparse_row_graph does but its structure is mostly read-only after construction. You can either use associative_property_map on the edges, or create an edge index map as an internal property (if you don't change your graph too often), fill it, then use it to build the external property map (using shared_array_property_map, for example).

这篇关于外部属性映射绑定到std :: vector在boost图形库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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