Boost子图复制构造函数不适用于Qt 5.0.2和MinGW

Boost Subgraph Copy Constructor not working with Qt 5.0.2 and MinGW

本文关键字:MinGW Qt 适用于 子图 复制 构造函数 不适用 Boost      更新时间:2023-10-16

我的项目使用的是Qt 4.8和minGW编译器以及boost 1.46.0,但现在我已经改用Qt 5.0.2和minGW编译以及boost 1.55.0,但子图的复制构造函数工作不好。它不是将顶点添加到子图(如果执行调试,则在顶点列表中显示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。

这是解决这个问题的一些方法,因为在boost 1_55_0中没有实现子图复制构造函数来执行深度复制。我尝试过更新boost子图副本构造函数。只需在boost的子图.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);
    //         }
    //       }
}