我有一个包含1500万(百万)个DAG(有向无环图 - 实际上是有向超立方体)的集合,我想从中删除同构。针对此问题,有哪些常见算法?每个图形都相当小,是N维的超立方体,其中N为3到6(目前为止),因此对于N = 6情况,每个图形有64个节点。
使用networkx和python,我像这样实现了它,对于像300k(千)这样的小数据集非常有效(在几天内运行得很好)。
def isIsomorphicDuplicate(hcL, hc):
"""checks if hc is an isomorphism of any of the hc's in hcL
Returns True if hcL contains an isomorphism of hc
Returns False if it is not found"""
#for each cube in hcL, check if hc could be isomorphic
#if it could be isomorphic, then check if it is
#if it is isomorphic, then return True
#if all comparisons have been made already, then it is not an isomorphism and return False
for saved_hc in hcL:
if nx.faster_could_be_isomorphic(saved_hc, hc):
if nx.fast_could_be_isomorphic(saved_hc, hc):
if nx.is_isomorphic(saved_hc, hc):
return True
return False
更好的方法是将每个图转换为其规范顺序,对集合进行排序,然后删除重复项。这样可以避免通过二进制is_isomophic()测试来检查15M个图中的每一个。我相信上述实现类似于O(N!N)(不考虑同构时间),而干净的转换为规范顺序并排序应该需要O(N)用于转换+O(log(N)N)用于搜索+O(N)用于去除重复项. O(N!N)>>O(log(N)N)
我在Canonical graph labeling的论文中找到了一些信息,但非常简洁,只有数学公式,没有伪代码:"McKay's Canonical Graph Labeling Algorithm" - http://www.math.unl.edu/~aradcliffe1/Papers/Canonical.pdf
tldr: 我需要通过二进制同构性检查来检查大量的图形,这几乎是不可能的。我相信通常通过规范顺序来解决这个问题。是否存在任何已打包的算法或已发表的易于实现的算法(即具有伪代码)?
faster_could_be_isomorphic()
已经在做的:(哈哈。我的问题更多地针对N!N到logN*N部分。这有意义吗?将所有内容转换为规范形式,排序,然后删除重复项。否则,您必须逐个将每个项目与每个其他项目进行比较(在规范化之前无法排序)。 - SwimBikeRun