首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VF2算法-实现

VF2算法-实现
EN

Stack Overflow用户
提问于 2013-11-10 05:56:02
回答 1查看 2.1K关注 0票数 2

我有一个关于VF2算法实现的问题。在许多情况下,一切似乎都运行得很完美,但是有一个问题我无法解决。

该算法在下面的示例中不起作用。在这个例子中,我们比较了两个相同的图形(见下图)。起始顶点为0。在s0中计算的集合P存储所有顶点对的幂集。

下面是我的实现所基于的关于VF2的出版物中包含的伪代码。

http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=B51AD0DAEDF60D6C8AB589A39A570257?doi=10.1.1.101.5342&rep=rep1&type=pdf

http://www.icst.pku.edu.cn/intro/leizou/teaching/2012-autumn/papers/part2/VF2%20A%20%28sub%29Graph%20Isomorphism%20Algorithm%20For%20Matching%20Large%20Graphs.pdf

/*右侧的注释描述了我理解代码的方式:

我不确定创建P()集是否有效,如下所述。对的幂集按字典序按对的第一个值和第二个值进行迭代。

代码语言:javascript
复制
PROCEDURE Match(s)
  INPUT: an intermediate state s; the initial state s0 has M(s0)=empty
  OUTPUT: the mappings between the two graphs
  IF M(s) covers all the nodes of G2 THEN
    OUTPUT M(s)
  ELSE
    Compute the set P(s) of the pairs candidate for inclusion in M(s)
    /*by powerset of all succesors from already matched M(s) if not empty or
    /*predestors to already matched M(s) if not empty
    /*or all possible not included vertices in M(s)
    FOREACH (n, m)∈ P(s)
      IF F(s, n, m) THEN
    Compute the state s ́ obtained by adding (n, m) to M(s)
    /*add n to M1(s), exclude from T1(s)
    /*add m to M2(s), exclude from T2(s)
    /*M1(s) is now M1(s'), other structures belong to s' too
    CALL Match(s′)
      END IF
    END FOREACH
    Restore data structures
    /*Return all structures as from before foreach
  END IF
END PROCEDURE

当算法转到s4时,当从函数恢复时,它会丢失有关良好顶点匹配的信息。它导致搜索子图同构({(0,0),(1,1),(2,2),(5,3),(6,4)}) -即使图是同构的。

我在这里做错了什么?

EN

回答 1

Stack Overflow用户

发布于 2014-06-25 19:12:35

我认为要知道你的问题“我在这里做错了什么”,有必要在这里包含一些你的代码。你自己重新实现了代码,基于论文中提供的伪代码?或者您是在一些图形处理包的帮助下进行匹配?

对我来说,我没有时间深入研究细节,但我也使用图形,所以我尝试使用networkx (一个Python包)和Boost 1.55.0库(非常广泛的图形C++库)。您的示例和具有1000个节点、1500条边的图的另一个示例返回正确的匹配(图与自身匹配的简单情况)。

代码语言:javascript
复制
import networkx as nx
G1 = nx.Graph()
G2 = nx.Graph()

G1.clear()
G2.clear()

G1.add_nodes_from(range(0,7))
G2.add_nodes_from(range(0,7))
G1.add_edges_from([(0,1), (1,2), (2,3), (3,4), (2,5), (5,6)])
G2.add_edges_from([(0,1), (1,2), (2,3), (3,4), (2,5), (5,6)])

from networkx.algorithms import isomorphism
GM = isomorphism.GraphMatcher(G2,G1)
print GM.is_isomorphic()
GM.mapping

真的

Out39:{0: 0,1: 1,2: 2,3: 3,4: 4,5: 5,6: 6}

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19883567

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档