Esempio n. 1
0
def add2set(gset, elist, H):
    n = len(H)

    s = set()
    ss = set()

    eremove = {e: True for e in elist}

    for gnum in gset:
        g = bfu.num2CG(gnum, n)
        for e in elist:
            if not e[1] in g[e[0]]:
                gk.addanedge(g,e)
                num = bfu.g2num(g)
                if not num in s:
                    au = bfu.call_undersamples(g)
                    if not gk.checkconflict(H, g, au=au):
                        eremove[e] = False
                        s.add(num)
                        if gk.checkequality(H, g, au=au): ss.add(num)
                gk.delanedge(g,e)

    for e in eremove:
        if eremove[e]: elist.remove(e)

    return s, ss, elist
Esempio n. 2
0
def add2set(gset, elist, H):
    n = len(H)

    s = set()
    ss = set()

    eremove = {e: True for e in elist}

    for gnum in gset:
        g = bfu.num2CG(gnum, n)
        for e in elist:
            if not e[1] in g[e[0]]:
                gk.addanedge(g, e)
                num = bfu.g2num(g)
                if not num in s:
                    au = bfu.call_undersamples(g)
                    if not gk.checkconflict(H, g, au=au):
                        eremove[e] = False
                        s.add(num)
                        if gk.checkequality(H, g, au=au): ss.add(num)
                gk.delanedge(g, e)

    for e in eremove:
        if eremove[e]: elist.remove(e)

    return s, ss, elist
Esempio n. 3
0
 def prune(g):
     numh = bfu.g2num(g)
     cannotprune = True
     for l in gk.edgelist(gk.digonly(g)):
         gk.delanedge(g,l)
         if bfu.forms_loop(g, loop):
             cannotprune = False
             prune(g)
         gk.addanedge(g,l)
     if cannotprune: s.add(bfu.g2num(g))
Esempio n. 4
0
    def addedges(g, H, edges):
        if edges:
            nedges = prune_conflicts(H, g, edges)
            n = len(nedges)

            if n == 0: return None

            for i in range(n):
                gk.addanedge(g, nedges[i])
                if bfu.call_u_equals(g, H): s.add(bfu.g2num(g))
                s.add(addedges(g, H, nedges[:i] + nedges[i + 1:]))
                gk.delanedge(g, nedges[i])
Esempio n. 5
0
    def addedges(g,H,edges):
        if edges:
            nedges = prune_conflicts(H, g, edges)
            n = len(nedges)

            if n == 0: return None

            for i in range(n):
                gk.addanedge(g,nedges[i])
                if bfu.call_u_equals(g, H): s.add(bfu.g2num(g))
                addedges(g,H,nedges[:i]+nedges[i+1:])
                gk.delanedge(g,nedges[i])
Esempio n. 6
0
def add2set_(ds, H, cp, ccf, iter=1, verbose=True, capsize=100):
    n = len(H)
    n2 = n * n + n
    dsr = {}
    s = set()
    ss = set()

    pbar = start_progress_bar(iter, len(ds), verbose=verbose)

    c = 0

    for gnum in ds:
        g = bfu.num2CG(gnum, n)
        gnum = bfu.g2num(g)
        c += 1
        pbar.update(c)
        glist = []
        elist = []
        eset = set()
        for e in ds[gnum]:
            if not e[1] in g[e[0]]:
                gk.addanedge(g, e)
                num = bfu.g2num(g)
                ekey = (1 << (n2 - int(e[0], 10) * n - int(e[1], 10)))
                if ekey in ccf and skip_conflictors(num, ccf[ekey]):
                    gk.delanedge(g, e)
                    continue
                if not num in s:
                    if not bfu.call_u_conflicts(g, H):
                        #cf, gl2 = bfu.call_u_conflicts2(g, H)
                        #if not cf:
                        glist.append((num, ekey))
                        elist.append(e)
                        eset.add(ekey)
                        s.add(num)
                        if bfu.call_u_equals(g, H): ss.add(num)
                        if capsize <= len(ss): break
                        #if bfu.call_u_equals2(g, gl2, H): ss.add(num)
                gk.delanedge(g, e)

        for gn, e in glist:
            if e in cp:
                dsr[gn] = [ekey2e(k, n) for k in eset - cp[e]]
            else:
                dsr[gn] = elist
                if capsize <= len(ss): return dsr, ss

    pbar.finish()
    return dsr, ss
Esempio n. 7
0
def add2set_(ds, H, cp, ccf, iter=1, verbose=True, capsize=100):
    n = len(H)
    n2 = n*n +n
    dsr = {}
    s = set()
    ss = set()

    pbar = start_progress_bar(iter, len(ds), verbose = verbose)

    c = 0

    for gnum in ds:
        g = bfu.num2CG(gnum, n)
        c += 1
        pbar.update(c)
        glist = []
        elist = []
        eset = set()
        for e in ds[gnum]:
            if not e[1] in g[e[0]]:
                gk.addanedge(g,e)
                num = bfu.g2num(g)
                ekey = (1<<(n2 - int(e[0],10)*n - int(e[1],10)))
                if ekey in ccf and skip_conflictors(num,ccf[ekey]):
                    gk.delanedge(g,e)
                    continue
                if not num in s:
                    s.add(num)
                    if not bfu.call_u_conflicts(g, H):
                        #cf, gl2 = bfu.call_u_conflicts2(g, H)
                        #if not cf:
                        glist.append((num,ekey))
                        elist.append(e)
                        eset.add(ekey)
                        if bfu.call_u_equals(g, H):
                            ss.add(num)
                            #if bfu.call_u_equals2(g, gl2, H): ss.add(num)
                        if capsize <= len(ss): break
                gk.delanedge(g,e)

        for gn,e in glist:
            if e in cp:
                dsr[gn] = [ekey2e(k,n) for k in eset - cp[e]]
            else:
                dsr[gn] = elist
        if capsize <= len(ss): return dsr, ss

    pbar.finish()
    return dsr, ss
Esempio n. 8
0
def prune_conflicts(H, g, elist):
    """checks if adding an edge from the list to graph g causes a
    conflict with respect to H and if it does removes the edge
    from the list

    Arguments:
    - `H`: the undersampled graph
    - `g`: a graph under construction
    - `elist`: list of edges to check
    """
    l = []
    for e in elist:
        gk.addanedge(g, e)
        if not bfu.call_u_conflicts(g, H): l.append(e)
        gk.delanedge(g, e)
    return l
Esempio n. 9
0
def prune_conflicts(H, g, elist):
    """checks if adding an edge from the list to graph g causes a
    conflict with respect to H and if it does removes the edge
    from the list

    Arguments:
    - `H`: the undersampled graph
    - `g`: a graph under construction
    - `elist`: list of edges to check
    """
    l  = []
    for e in elist:
        gk.addanedge(g,e)
        if not bfu.call_u_conflicts(g, H): l.append(e)
        gk.delanedge(g,e)
    return l