添加外部属性以包含图中顶点的索引(提升)

发布于 2024-12-13 00:36:56 字数 2210 浏览 0 评论 0原文

我正在尝试使用 associative_property_map 来包含顶点索引,但使用以下简单代码时出现以下错误,问题是什么?

#include <boost/graph/iteration_macros.hpp>
#include <boost/graph/adjacency_list.hpp>

using namespace std;
using namespace boost;

struct NodeData
{
    int label;
};

struct EdgeData
{
    int age;
};

typedef map<vecS, size_t> IndexMap;
IndexMap mapIndex;
associative_property_map<IndexMap> propmapIndex(mapIndex);

typedef adjacency_list<setS, setS, undirectedS, NodeData, EdgeData> Graph;
typedef Graph::vertex_descriptor NodeID;
typedef Graph::edge_descriptor EdgeID;

int main()
{
    Graph g;

    NodeID n0 = add_vertex(g); g[n0].label = -1;
    NodeID n1 = add_vertex(g); g[n1].label = -1;

    EdgeID edge; bool ok;
    tie(edge, ok) = boost::add_edge(n0, n1, g);
    if (ok) g[edge].age = 10;

    int i=0;
    BGL_FORALL_VERTICES(v, g, Graph)
    {
        put(propmapIndex, v, i++);
    }

    return 0;
}

错误:

c:\program files\codeblocks\mingw\bin..\lib\gcc\mingw32\4.4.1........\include\boost\property_map\property_map.hpp||中

函数'void boost::put(const boost::put_get_helper&, K, const V&) [PropertyMap = boost::associative_property_map, std::allocator >

<块引用> <块引用>

,引用 = unsigned int&,K = void*,V = int]':| C:\Users\memo\Desktop\Debuged\boostGraph\main.cpp|39|实例化自 这里| c:\程序 文件\codeblocks\mingw\bin..\lib\gcc\mingw32\4.4.1........\include\boost\property_map\property_map.hpp|361|错误: 与 '(const boost::associative_property_map, std::分配器> > >&)((const boost::associative_property_map, std::分配器> > >*)(&pa))[k]'| c:\程序 文件\codeblocks\mingw\bin..\lib\gcc\mingw32\4.4.1........\include\boost\property_map\property_map.hpp|498|注意: 候选人是: 类型名称 UniquePairAssociativeContainer::value_type::second_type& boost::associative_property_map::operator[](const 类型名 UniquePairAssociativeContainer::key_type&) const [with UniquePairAssociativeContainer = std::map, std::allocator >; >]| ||=== 构建完成:1 个错误,0 个警告 ===|

谢谢

I'm trying to use an associative_property_map to include index for vertices, but I get the following error with the following simple code, what is the problem ?

#include <boost/graph/iteration_macros.hpp>
#include <boost/graph/adjacency_list.hpp>

using namespace std;
using namespace boost;

struct NodeData
{
    int label;
};

struct EdgeData
{
    int age;
};

typedef map<vecS, size_t> IndexMap;
IndexMap mapIndex;
associative_property_map<IndexMap> propmapIndex(mapIndex);

typedef adjacency_list<setS, setS, undirectedS, NodeData, EdgeData> Graph;
typedef Graph::vertex_descriptor NodeID;
typedef Graph::edge_descriptor EdgeID;

int main()
{
    Graph g;

    NodeID n0 = add_vertex(g); g[n0].label = -1;
    NodeID n1 = add_vertex(g); g[n1].label = -1;

    EdgeID edge; bool ok;
    tie(edge, ok) = boost::add_edge(n0, n1, g);
    if (ok) g[edge].age = 10;

    int i=0;
    BGL_FORALL_VERTICES(v, g, Graph)
    {
        put(propmapIndex, v, i++);
    }

    return 0;
}

Errors:

c:\program files\codeblocks\mingw\bin..\lib\gcc\mingw32\4.4.1........\include\boost\property_map\property_map.hpp||In

function 'void boost::put(const boost::put_get_helper&, K, const V&)
[with PropertyMap = boost::associative_property_map, std::allocator >

, Reference = unsigned int&, K = void*, V = int]':| C:\Users\memo\Desktop\Debuged\boostGraph\main.cpp|39|instantiated from
here| c:\program
files\codeblocks\mingw\bin..\lib\gcc\mingw32\4.4.1........\include\boost\property_map\property_map.hpp|361|error:
no match for 'operator[]' in '(const boost::associative_property_map,
std::allocator > > >&)((const boost::associative_property_map,
std::allocator > > >*)(& pa))[k]'| c:\program
files\codeblocks\mingw\bin..\lib\gcc\mingw32\4.4.1........\include\boost\property_map\property_map.hpp|498|note:
candidates are: typename
UniquePairAssociativeContainer::value_type::second_type&
boost::associative_property_map::operator[](const typename
UniquePairAssociativeContainer::key_type&) const [with
UniquePairAssociativeContainer = std::map, std::allocator > >]| ||===
Build finished: 1 errors, 0 warnings ===|

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心碎无痕… 2024-12-20 00:36:56

顶点描述符必须指定给 IndexMap,因此它是 map 而不是 map

<...>
typedef Graph::vertex_descriptor NodeID;

typedef map<NodeID, size_t> IndexMap;
IndexMap mapIndex;
associative_property_map<IndexMap> propmapIndex(mapIndex);
<...>

// indexing all vertices
int i=0;
BGL_FORALL_VERTICES(v, g, Graph)
{
   put(propmapIndex, v, i++);
}

The vertex descriptor must be specified to IndexMap, so it's map<NodeID, size_t> and not map<vecS, size_t> :

<...>
typedef Graph::vertex_descriptor NodeID;

typedef map<NodeID, size_t> IndexMap;
IndexMap mapIndex;
associative_property_map<IndexMap> propmapIndex(mapIndex);
<...>

// indexing all vertices
int i=0;
BGL_FORALL_VERTICES(v, g, Graph)
{
   put(propmapIndex, v, i++);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文