我正在使用Qt 4.8和minGW编译器,我的项目使用boost 1.46.0,但现在我已经使用Boost 1.55.0转移到Qt 5.0.2和MinGW编译器,但是子图的复制构造函数运行不正常。它没有向子图添加顶点(如果执行调试,则在顶点列表中显示0个项目。)
typedef boost::adjacency_list< boost::listS,
boost::vecS,
boost::bidirectionalS,
boost::property<boost::vertex_index_t, int ,
property<vertex_position_t, point, VertexProperties> > ,
boost::property<boost::edge_index_t,int , EdgeProperties>,
boost::property<graph_custom_prop_t,GraphProperties> >
Graph;
typedef boost::subgraph< Graph > SubGraph;
我正在接受gMainGraph的输入,我需要将其复制到m_gMainGraph
SubGraph* m_gMainGraph;
m_gMainGraph = new SubGraph(gMainGraph);
子图正在创建,但子图中的顶点和边没有被创建,只会被添加到最顶层的父图。 在上面的代码中,gMainGraph没有被深深地复制到m_gMainGraph。
答案 0 :(得分:0)
这是解决此问题的一些方法,因为未实现子图复制构造函数以在boost 1_55_0中执行深层复制。 我试过更新boost子图复制构造器。只需在boost的subgraph.hpp文件中使用以下代码即可。您需要评论1.52.0中的一些代码并使用以下更改。
// copy constructor
/*Updated the copy constructor to work properly
As it's working in 1.46.0 and not in 1.52.0, In 1.52.0, the subgraph constructor is not itrating the child of child subgraphs
So only the direct children of main subgraph was getting copied*/
subgraph(const subgraph& x)
: m_graph(x.m_graph), m_parent(x.m_parent), m_edge_counter(x.m_edge_counter) //Added m_graph(x.m_graph)
, m_global_vertex(x.m_global_vertex), m_global_edge(x.m_global_edge)
{
// This loop belongs to 1.46.0
for(typename ChildrenList::const_iterator i = x.m_children.begin();
i != x.m_children.end(); ++i)
{
m_children.push_back(new subgraph<Graph>( **i ));
}
/* 1.52.0 code*/
// if(x.is_root())
// {
// m_graph = x.m_graph;
// }
// // Do a deep copy (recursive).
// // Only the root graph is copied, the subgraphs contain
// // only references to the global vertices they own.
// typename subgraph<Graph>::children_iterator i,i_end;
// boost::tie(i,i_end) = x.children();
// for(; i != i_end; ++i)
// {
// subgraph<Graph> child = this->create_subgraph();
// child = *i;
// vertex_iterator vi,vi_end;
// boost::tie(vi,vi_end) = vertices(*i);
// for (;vi!=vi_end;++vi)
// {
// add_vertex(*vi,child);
// }
// }
}