我有一个关于VF2算法实现的问题。在许多情况下,一切似乎都运行得很完美,但是有一个问题我无法解决。
该算法在下面的示例中不起作用。在这个例子中,我们比较了两个相同的图形(见下图)。起始顶点为0。在s0中计算的集合P存储所有顶点对的幂集。

下面是我的实现所基于的关于VF2的出版物中包含的伪代码。
/*右侧的注释描述了我理解代码的方式:
我不确定创建P()集是否有效,如下所述。对的幂集按字典序按对的第一个值和第二个值进行迭代。
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)}) -即使图是同构的。
我在这里做错了什么?
发布于 2014-06-25 19:12:35
我认为要知道你的问题“我在这里做错了什么”,有必要在这里包含一些你的代码。你自己重新实现了代码,基于论文中提供的伪代码?或者您是在一些图形处理包的帮助下进行匹配?
对我来说,我没有时间深入研究细节,但我也使用图形,所以我尝试使用networkx (一个Python包)和Boost 1.55.0库(非常广泛的图形C++库)。您的示例和具有1000个节点、1500条边的图的另一个示例返回正确的匹配(图与自身匹配的简单情况)。
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}
https://stackoverflow.com/questions/19883567
复制相似问题