增加一个外部属性包括图(增强)指数vertix [英] adding an external property to include index for vertix in graph (boost)
问题描述
我试图用一个associative_property_map包括顶点指数,但我得到了下面的错误有以下简单的code,这是什么问题?
的#include<升压/图/ iteration_macros.hpp>
#包括LT&;升压/图/ adjacency_list.hpp>使用命名空间std;
使用名字空间boost;结构NODEDATA
{
INT标签;
};结构EdgeData
{
INT年龄;
};typedef的地图和LT;血管内皮细胞,为size_t> IndexMap;
IndexMap mapIndex;
associative_property_map< IndexMap> propmapIndex(mapIndex);的typedef的adjacency_list<套,,undirectedS,NODEDATA,EdgeData>图形;
图表的typedef :: vertex_descriptor的节点ID;
图表的typedef :: edge_descriptor的EdgeID的;诠释的main()
{
图克; 节点ID N0 = add_vertex(G);政[N0] .label = -1;
节点ID N1 = add_vertex(G);政[N1] .label = -1; EdgeID的边缘;布尔OK;
领带(边,OK)=提振::的add_edge(N0,N1,G);
如果(OK)G [边]。年龄= 10; INT I = 0;
BGL_FORALL_VERTICES(V,G,图表)
{
把(propmapIndex,V,I ++);
} 返回0;
}
错误:
C:\\程序files\\$c$cblocks\\mingw\\bin..\\lib\\gcc\\mingw32\\4.4.1........\\include\\boost\\property_map\\property_map.hpp||In
功能无效的boost ::把(常量的boost :: put_get_helper和放大器,K,常量V&安培;)
[与PropertyMap =的boost :: associative_property_map,性病::分配器>
,参考= unsigned int类型和放大器,K =无效*,V = INT]:| C:\\用户\\备忘录\\桌面\\ Debuged \\ boostGraph \\ main.cpp中| 39 |从实例
这里| C:\\程序
files\\$c$cblocks\\mingw\\bin..\\lib\\gcc\\mingw32\\4.4.1........\\include\\boost\\property_map\\property_map.hpp|361|error:
敌不过操作符[]'中'(常量的boost :: associative_property_map,
性病::分配器>>>&安培;)((常量的boost :: associative_property_map,
性病::分配器>>> *)(安培; PA))[K]'| C:\\程序
files\\$c$cblocks\\mingw\\bin..\\lib\\gcc\\mingw32\\4.4.1........\\include\\boost\\property_map\\property_map.hpp|498|note:
候选人是:类型名
UniquePairAssociativeContainer :: VALUE_TYPE :: second_type&安培;
提高:: associative_property_map :: operator []的(常量类型名称
UniquePairAssociativeContainer ::为key_type&放大器;)常量[与
UniquePairAssociativeContainer =的std ::地图,性病::分配器>>] | || ===
构建完成:1错误,0警告=== |
块引用>
块引用>
块引用>感谢
解决方案顶点描述符必须指定IndexMap,所以它的
地图<节点ID,为size_t>
,而不是地图<血管内皮细胞,为size_t>
:< ...>
图表的typedef :: vertex_descriptor的节点ID;typedef的地图和LT;节点ID,为size_t> IndexMap;
IndexMap mapIndex;
associative_property_map< IndexMap> propmapIndex(mapIndex);
< ...>//索引所有的顶点
INT I = 0;
BGL_FORALL_VERTICES(V,G,图表)
{
把(propmapIndex,V,I ++);
}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
解决方案The vertex descriptor must be specified to IndexMap, so it's
map<NodeID, size_t>
and notmap<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++); }
这篇关于增加一个外部属性包括图(增强)指数vertix的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!