【问题标题】:How to get the edge mapping with boost::vf2_subgraph_iso如何使用 boost::vf2_subgraph_iso 获取边缘映射
【发布时间】:2019-09-14 20:05:39
【问题描述】:

boost::vf2_subgraph_iso 应该在给定的大图中找到给定较小图的诱导子图。传递给它的回调将获得一个映射作为输入。

template <typename CorrespondenceMap1To2, typename CorrespondenceMap2To1>
bool operator()(CorrespondenceMap1To2 f, CorrespondenceMap2To1 g) const{
    // boost::get(f, u) maps u in small to v in large
}

但是文档只提到了顶点映射。我知道可以通过映射每个边缘的源和目标来理解边缘映射。但我需要映射边缘的捆绑属性。

boost::get 似乎不适用于映射和边缘描述符。 boost::get(f, e) 产生以下错误消息。

error: no match for ‘operator[]’ (operand types are ‘const boost::iterator_property_map<__gnu_cxx::__normal_iterator<long unsigned int*, std::vector<long unsigned int, std::allocator<long unsigned int> > >, boost::vec_adj_list_vertex_id_map<bya::util::isomorphism::vertex_data, long unsigned int>, long unsigned int, long unsigned int&>’ and ‘const boost::detail::edge_desc_impl<boost::bidirectional_tag, long unsigned int>’)

【问题讨论】:

    标签: c++ boost graph boost-graph isomorphism


    【解决方案1】:

    是的,映射不适用于边缘描述符,因为它们不是顶点描述符。

    我建议在“其他”图中查找边缘。所以,例如

    Live On Coliru

    #include <boost/graph/adjacency_list.hpp>
    #include <boost/graph/vf2_sub_graph_iso.hpp>
    
    using namespace boost;
    
    struct VBundle { std::string name; };
    struct EBundle { int data = 0; };
    
    using G = adjacency_list<vecS, vecS, bidirectionalS, VBundle, EBundle>;
    using Edge = G::edge_descriptor;
    
    int main() {
        G small(4), large(5);
        small[0].name = "zero";
        small[1].name = "one";
        small[2].name = "two";
        small[3].name = "three";
        add_edge(0, 1, {33}, small);
        add_edge(1, 3, {44}, small);
        add_edge(2, 3, {55}, small);
    
        add_edge(4, 2, large); // 0->4, 1->2, 3->0, 2->3
        add_edge(2, 0, large);
        add_edge(3, 0, large);
    
        auto cb = [&](auto&& f, auto&&) {
            for (auto small_vd: make_iterator_range(vertices(small))) {
                auto large_vd = get(f, small_vd);
    
                std::cout << '(' << small_vd << ", " << large_vd << ") ";
                large[large_vd] = small[small_vd];
    
                for (Edge small_ed: make_iterator_range(out_edges(small_vd, small))) {
                    auto large_src = get(f, source(small_ed, small));
                    auto large_tgt = get(f, target(small_ed, small));
    
                    auto [large_ed, found] = edge(large_src, large_tgt, large);
                    assert(found);
    
                    // e.g. copy edge bundle to the smaller graph
                    large[large_ed] = small[small_ed];
                }
            }
    
            std::cout << std::endl;
            return true;
        };
    
        bool ok = vf2_subgraph_iso(small, large, cb);
    
        std::cout << std::boolalpha << ok << "\n";
    }
    

    打印出来

    (0, 4) (1, 2) (2, 3) (3, 0) 
    true
    

    但也会将相应的顶点和边束从小图复制到大图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 2015-05-17
      • 2021-07-10
      • 2019-03-04
      • 2016-05-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多