Boost 初始化自定义边类的内部边索引
我对BGL(boostgraphlibrary)非常陌生。当我尝试使用平面地图遍历时,我遇到了以下编译问题,有人能解释一下我做错了什么吗?导致错误的代码是:Boost 初始化自定义边类的内部边索引,boost,graph,Boost,Graph,我对BGL(boostgraphlibrary)非常陌生。当我尝试使用平面地图遍历时,我遇到了以下编译问题,有人能解释一下我做错了什么吗?导致错误的代码是: put(e_index, *ei, edge_count++); planar_face_traversal(g, &embedding[0], v_vis); planar_face_traversal(g, &embedding[0], e_vis); /usr/include/boost/property_ma
put(e_index, *ei, edge_count++);
planar_face_traversal(g, &embedding[0], v_vis);
planar_face_traversal(g, &embedding[0], e_vis);
/usr/include/boost/property_map/property_map.hpp:361: error: no match for 'operator=' in '(&((const boost::adj_list_edge_property_map<boost::undirected_tag, boost::detail::error_property_not_found, boost::detail::error_property_not_found&, long unsigned int, boost::property<boost::edge_bundle_t, Edge, boost::no_property>, boost::edge_index_t>&)pa))->boost::adj_list_edge_property_map<Directed, Value, Ref, Vertex, Property, Tag>::operator[] [with Directed = boost::undirected_tag, Value = boost::detail::error_property_not_found, Ref = boost::detail::error_property_not_found&, Vertex = long unsigned int, Property = boost::property<boost::edge_bundle_t, Edge, boost::no_property>, Tag = boost::edge_index_t, boost::adj_list_edge_property_map<Directed, Value, Ref, Vertex, Property, Tag>::key_type = boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>](k) = v'
/usr/include/boost/property_map/property_map.hpp:391: error: no match for 'operator+' in '((const boost::iterator_property_map<__gnu_cxx::__normal_iterator<std::map<long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, std::less<long unsigned int>, std::allocator<std::pair<const long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int> > > >*, std::vector<std::map<long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, std::less<long unsigned int>, std::allocator<std::pair<const long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int> > > >, std::allocator<std::map<long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, std::less<long unsigned int>, std::allocator<std::pair<const long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int> > > > > > >, boost::adj_list_edge_property_map<boost::undirected_tag, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, long unsigned int, const boost::property<boost::edge_bundle_t, Edge, boost::no_property>, boost::edge_index_t>, std::map<long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, std::less<long unsigned int>, std::allocator<std::pair<const long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int> > > >, std::map<long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, std::less<long unsigned int>, std::allocator<std::pair<const long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int> > > >&>*)this)->boost::iterator_property_map<__gnu_cxx::__normal_iterator<std::map<long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, std::less<long unsigned int>, std::allocator<std::pair<const long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int> > > >*, std::vector<std::map<long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, std::less<long unsigned int>, std::allocator<std::pair<const long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int> > > >, std::allocator<std::map<long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, std::less<long unsigned int>, std::allocator<std::pair<const long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int> > > > > > >, boost::adj_list_edge_property_map<boost::undirected_tag, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, long unsigned int, const boost::property<boost::edge_bundle_t, Edge, boost::no_property>, boost::edge_index_t>, std::map<long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, std::less<long unsigned int>, std::allocator<std::pair<const long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int> > > >, std::map<long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, std::less<long unsigned int>, std::allocator<std::pair<const long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int> > > >&>::iter + boost::get [with PropertyMap = boost::adj_list_edge_property_map<boost::undirected_tag, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, long unsigned int, const boost::property<boost::edge_bundle_t, Edge, boost::no_property>, boost::edge_index_t>, Reference = const boost::detail::error_property_not_found&, K = boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>]((*(const boost::put_get_helper<const boost::detail::error_property_not_found&, boost::adj_list_edge_property_map<boost::undirected_tag, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, long unsigned int, const boost::property<boost::edge_bundle_t, Edge, boost::no_property>, boost::edge_index_t> >*)(&((const boost::iterator_property_map<__gnu_cxx::__normal_iterator<std::map<long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, std::less<long unsigned int>, std::allocator<std::pair<const long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int> > > >*, std::vector<std::map<long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, std::less<long unsigned int>, std::allocator<std::pair<const long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int> > > >, std::allocator<std::map<long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, std::less<long unsigned int>, std::allocator<std::pair<const long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int> > > > > > >, boost::adj_list_edge_property_map<boost::undirected_tag, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, long unsigned int, const boost::property<boost::edge_bundle_t, Edge, boost::no_property>, boost::edge_index_t>, std::map<long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, std::less<long unsigned int>, std::allocator<std::pair<const long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int> > > >, std::map<long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, std::less<long unsigned int>, std::allocator<std::pair<const long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int> > > >&>*)this)->boost::iterator_property_map<__gnu_cxx::__normal_iterator<std::map<long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, std::less<long unsigned int>, std::allocator<std::pair<const long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int> > > >*, std::vector<std::map<long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, std::less<long unsigned int>, std::allocator<std::pair<const long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int> > > >, std::allocator<std::map<long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, std::less<long unsigned int>, std::allocator<std::pair<const long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int> > > > > > >, boost::adj_list_edge_property_map<boost::undirected_tag, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, long unsigned int, const boost::property<boost::edge_bundle_t, Edge, boost::no_property>, boost::edge_index_t>, std::map<long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, std::less<long unsigned int>, std::allocator<std::pair<const long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int> > > >, std::map<long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, std::less<long unsigned int>, std::allocator<std::pair<const long unsigned int, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int> > > >&>::index)), (*(const boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>*)(& v)))'
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/properties.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/property_map/property_map.hpp>
#include <boost/ref.hpp>
#include <vector>
#include <boost/graph/planar_face_traversal.hpp>
#include <boost/graph/boyer_myrvold_planar_test.hpp> using namespace boost;
// Some planar face traversal visitors that will // print the vertices and edges on the faces
class Vertex{ public:
int i;//just some variable
Vertex(){}
Vertex(int val){
i = val;
} };
class Edge{ public:
int i;//just some variable
Edge(){}
Edge(int val){
i = val;
} };
struct output_visitor : public planar_face_traversal_visitor { void begin_face() { std::cout << "New face: "; } void end_face() { std::cout << std::endl; } };
struct vertex_output_visitor : public output_visitor { void next_vertex(Vertex v) {
std::cout << v.i << " "; } };
struct edge_output_visitor : public output_visitor { void next_edge(Edge e) {
std::cout << e.i << " "; } };
int main(int argc, char** argv) {
typedef adjacency_list
< vecS,
vecS,
undirectedS,
Vertex,
Edge
>
graph;
// Create a graph - this is a biconnected, 3 x 3 grid. // It should have four small (four vertex/four edge) faces and // one large face that contains all but the interior vertex graph g;
typedef boost::graph_traits<graph>::vertex_descriptor VertexDescriptor; typedef boost::graph_traits<graph>::edge_descriptor EdgeDescriptor;
VertexDescriptor v0 = add_vertex(g); VertexDescriptor v1 = add_vertex(g); VertexDescriptor v2 = add_vertex(g); VertexDescriptor v3 = add_vertex(g); VertexDescriptor v4 = add_vertex(g); add_edge(v0,v1,g); add_edge(v1,v2,g); add_edge(v2,v3,g); add_edge(v3,v4,g); add_edge(v4,v0,g);
add_edge(v0,v2,g); add_edge(v0,v3,g);
add_edge(v1,v4,g); add_edge(v1,v3,g);
add_edge(v2, v4, g);
// Initialize the interior edge index property_map<graph, edge_index_t>::type e_index = get(edge_index, g);
graph_traits<graph>::edges_size_type edge_count = 0; graph_traits<graph>::edge_iterator ei, ei_end; for(boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei) {
put(e_index, *ei, edge_count++);
std::cout << *ei << std::endl; }
// Test for planarity - we know it is planar, we just want to // compute the planar embedding as a side-effect
typedef std::vector< graph_traits<graph>::edge_descriptor > vec_t; std::vector<vec_t> embedding(num_vertices(g)); std::cout << num_vertices(g) << std::endl; if (boyer_myrvold_planarity_test(boyer_myrvold_params::graph = g,
boyer_myrvold_params::embedding =
&embedding[0]
)
)
std::cout << "Input graph is planar" << std::endl; else
std::cout << "Input graph is not planar" << std::endl;
std::cout << std::endl << "Vertices on the faces: " << std::endl; vertex_output_visitor v_vis; planar_face_traversal(g, &embedding[0], v_vis);
std::cout << std::endl << "Edges on the faces: " << std::endl; output_visitor e_vis; planar_face_traversal(g, &embedding[0], e_vis);
return 0; }
put(e_索引,*ei,edge_计数+);
平面_面_遍历(g,&嵌入[0],v_-vis);
平面平面遍历(g,&嵌入[0],e_-vis);
/usr/include/boost/property_-map/property_-map.hpp:361:错误:中的“operator=”不匹配(&((const-boost::adj_-list_-edge_-property_-map&)pa))->boost::adj_-list_-edge_-property_-map::operator[][with Directed=boost::undirected_标记,Value=boost::detail::error_property_not_found,Ref=boost::detail::error_property_not_found&,Vertex=long unsigned int,property=boost::property=boost::edge_index_t,boost::adj_list_edge_edge_属性_map::key_type=boost::detail::edge_desc_impl](k)==v'
/usr/include/boost/property\u-map/property\u-map.hpp:391:错误:中的“运算符+”不匹配((const-boost::iterator\u-property\u-map*)this)->boost::iterator\u-property\u-map::iter+boost::get[with-PropertyMap=boost::adj\u-list\u-edge\u-property\u-map,Reference=const-boost::error\u-property\u-not-found&,K=boost::detail::detail::edge\u-desc impl]((*(const boost::put_get_helper*)(&((const boost::iterator_property_map*)this)->boost::iterator_property_map::index)),(*(const boost::detail::edge_desc_impl*)(&v))'
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括使用名称空间boost;
//一些平面遍历访问者,这些访问者将//打印面上的顶点和边
类顶点{public:
int i;//只是一些变量
顶点(){}
顶点(int-val){
i=val;
} };
类边缘{public:
int i;//只是一些变量
边(){}
边缘(int-val){
i=val;
} };
结构输出\访问者:公共平面\面\遍历\访问者{void begin \面(){std::cout您的代码有几个问题。导致编译器错误的一个原因是您的图形没有内部edge\u index
属性,您正在尝试使用该属性。将EdgeProperty
更改为属性
很容易解决。您的xxx\u输出也有问题ode>next\u vertex
和next\u edge
分别需要一个顶点描述符和一个边描述符。我在下面对它们进行了更改,以做一些“有用”的事情最后一个问题是,boyer\u myrvold\u planarity\u test
为您的图形返回false。由于我对问题域一无所知,我只是用找到的图形更改了您的图形
更新:如果要避免使用属性
,只需创建一个外部属性映射,然后将其传递到平面遍历
boyer\u myrvold\u平面度测试
无需传递边索引映射,除非同时使用参数kuratowski\u子图
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/properties.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/property_map/property_map.hpp>
#include <boost/graph/iteration_macros.hpp>
#include <boost/ref.hpp>
#include <vector>
#include <boost/graph/planar_face_traversal.hpp>
#include <boost/graph/boyer_myrvold_planar_test.hpp>
using namespace boost;
// Some planar face traversal visitors that will
// print the vertices and edges on the faces
class Vertex
{
public:
int i;//just some variable
Vertex(){}
Vertex(int val){
i = val;
}
};
class Edge
{
public:
int i;//just some variable
Edge(){}
Edge(int val){
i = val;
}
};
typedef adjacency_list
< vecS,
vecS,
undirectedS,
Vertex,
Edge
>
graph_type;
struct output_visitor : public planar_face_traversal_visitor
{
void begin_face() { std::cout << "New face: "; }
void end_face() { std::cout << std::endl; }
};
struct vertex_output_visitor : public output_visitor
{
vertex_output_visitor(const graph_type& g_):g(g_){}
template <typename VertexDesc>
void next_vertex(VertexDesc v)
{
//std::cout << g[v].i << " "; //This would do what you wanted if you initialize "i"
std::cout << get(vertex_index,g,v) << " ";
}
const graph_type& g;
};
struct edge_output_visitor : public output_visitor
{
edge_output_visitor(const graph_type& g_):g(g_){}
template <typename EdgeDesc>
void next_edge(EdgeDesc e)
{
//std::cout << g[e].i << " "; //This would do what you wanted
std::cout << source(e,g) << "-" << target(e,g) << " ";
}
const graph_type& g;
};
int main() {
// Create a graph - this is a biconnected, 3 x 3 grid.
// It should have four small (four vertex/four edge) faces and
// one large face that contains all but the interior vertex
graph_type g;
typedef boost::graph_traits<graph_type>::vertex_descriptor VertexDescriptor;
typedef boost::graph_traits<graph_type>::edge_descriptor EdgeDescriptor;
VertexDescriptor A = add_vertex(g);
VertexDescriptor B = add_vertex(g);
VertexDescriptor C = add_vertex(g);
VertexDescriptor D = add_vertex(g);
VertexDescriptor E = add_vertex(g);
add_edge(A,B,g);
add_edge(A,C,g);
add_edge(A,D,g);
add_edge(A,E,g);
add_edge(B,D,g);
add_edge(B,E,g);
add_edge(C,D,g);
add_edge(C,E,g);
add_edge(D,E,g);
typedef std::map<EdgeDescriptor, size_t> EdgeIndexMap;
EdgeIndexMap mapIndex;
boost::associative_property_map<EdgeIndexMap> my_edge_index_map(mapIndex);
graph_traits<graph_type>::edges_size_type current_index=0;
BGL_FORALL_EDGES(e,g,graph_type)
{
put(my_edge_index_map,e,current_index++);
std::cout << e << std::endl;
}
// Test for planarity - we know it is planar, we just want to
// compute the planar embedding as a side-effect
typedef std::vector< graph_traits<graph_type>::edge_descriptor > vec_t;
std::vector<vec_t> embedding(num_vertices(g));
std::cout << num_vertices(g) << std::endl;
//if you use the parameter "kuratowski_subgraph" you'll need to pass also my_edge_index_map
if (boyer_myrvold_planarity_test(boyer_myrvold_params::graph = g,
boyer_myrvold_params::embedding =
&embedding[0]
)
)
std::cout << "Input graph is planar" << std::endl;
else
std::cout << "Input graph is not planar" << std::endl;
std::cout << std::endl << "Vertices on the faces: " << std::endl;
vertex_output_visitor v_vis(g);
planar_face_traversal(g, &embedding[0], v_vis, my_edge_index_map);
std::cout << std::endl << "Edges on the faces: " << std::endl;
edge_output_visitor e_vis(g);
planar_face_traversal(g, &embedding[0], e_vis, my_edge_index_map);
return 0;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间boost;
//一些平面横穿将
//打印面上的顶点和边
类顶点
{
公众:
int i;//只是一些变量
顶点(){}
顶点(int-val){
i=val;
}
};
阶级边缘
{
公众:
int i;//只是一些变量
边(){}
边缘(int-val){
i=val;
}
};
typedef邻接列表
图_型;
结构输出访问者:公共平面访问者
{
void begin_face(){std::cout谢谢!您的代码正在运行!但是,我正在寻找一个使用bundle属性的解决方案,基本上避免使用属性,只使用Edge。有没有办法做到这一点?太好了!感谢您的帮助!