コード例 #1
0
ファイル: traversal.py プロジェクト: undercoveridiot/gunfolds
def supergraphs_in_eq(g, g2, rate=1):
    '''Find  all supergraphs of g  that are also in  the same equivalence
    class with respect to g2 and the rate.
    Currently works only for bfu.undersample by 1
    '''
    if bfu.undersample(g, rate) != g2:
        raise ValueError('g is not in equivalence class of g2')

    s = set()

    def addnodes(g, g2, edges):
        if edges:
            masks = []
            for e in edges:
                if ok2addanedge(e[0], e[1], g, g2, rate=rate):
                    masks.append(True)
                else:
                    masks.append(False)
            nedges = [edges[i] for i in range(len(edges)) if masks[i]]
            n = len(nedges)
            if n:
                for i in range(n):
                    mask = addanedge(g, nedges[i])
                    s.add(g2num(g))
                    addnodes(g, g2, nedges[:i] + nedges[i + 1:])
                    delanedge(g, nedges[i], mask)

    edges = gk.edgelist(gk.complement(g))
    addnodes(g, g2, edges)
    return s
コード例 #2
0
ファイル: traversal.py プロジェクト: undercoveridiot/gunfolds
def eqsearch(g2, rate=1):
    '''Find  all  g  that are also in  the equivalence
    class with respect to g2 and the rate.
    '''

    s = set()
    noop = set()

    @memo1
    def addnodes(g, g2, edges):
        if edges:
            masks = []
            for e in edges:
                if ok2addanedge_(e[0], e[1], g, g2, rate=rate):
                    masks.append(True)
                else:
                    masks.append(False)
            nedges = [edges[i] for i in range(len(edges)) if masks[i]]
            n = len(nedges)
            if n:
                for i in range(n):
                    mask = addanedge(g, nedges[i])
                    if bfu.undersample(g, rate) == g2:
                        s.add(g2num(g))
                    addnodes(g, g2, nedges[:i] + nedges[i + 1:])
                    delanedge(g, nedges[i], mask)
                return s
            else:
                return noop
        else:
            return noop

    g = cloneempty(g2)
    edges = gk.edgelist(gk.complement(g))
    addnodes(g, g2, edges)
    return s