Beispiel #1
0
def bfs(src,dst,seeds,printLayers=False):
    # holds vertices in the current layer of the bfs
    Z = ak.unique(seeds)
    # holds the visited vertices
    V = ak.unique(Z) # holds vertices in Z to start with
    # frontiers
    F = [Z]
    while Z.size != 0:
        if printLayers:
            print("Z.size = ",Z.size," Z = ",Z)
        fZv = ak.in1d(src,Z) # find src vertex edges 
        W = ak.unique(dst[fZv]) # compress out dst vertices to match and make them unique
        Z = ak.setdiff1d(W,V) # subtract out vertices already visited
        V = ak.union1d(V,Z) # union current frontier into vertices already visited
        F.append(Z)
    return (F,V)
Beispiel #2
0
def conn_comp(src, dst, printCComp=False, printLayers=False):
    unvisited = ak.unique(src)
    if printCComp: print("unvisited size = ", unvisited.size, unvisited)
    components = []
    while unvisited.size > 0:
        # use lowest numbered vertex as representative vertex 
        rep_vertex = unvisited[0]
        # bfs from rep_vertex
        layers,visited = bfs(src,dst,ak.array([rep_vertex]),printLayers)
        # add verticies in component to list of components
        components.append(visited)
        # subtract out visited from unvisited vertices
        unvisited = ak.setdiff1d(unvisited,visited)
        if printCComp: print("  visited size = ", visited.size, visited)
        if printCComp: print("unvisited size = ", unvisited.size, unvisited)
    return components
Beispiel #3
0
    a = ak.randint(0, 2 * SIZE, SIZE)
    b = ak.randint(0, 2 * SIZE, SIZE)

    set_union = ak.union1d(a, b)
    print("union1d = ", set_union.size, set_union)
    # elements in a or elements in b (or in both a and b)
    passed = ak.all(ak.in1d(set_union, a) | ak.in1d(set_union, b))
    print("union1d passed test: ", passed)

    set_intersection = ak.intersect1d(a, b)
    print("intersect1d = ", set_intersection.size, set_intersection)
    # elements in a and elements in b (elements in both a and b)
    passed = ak.all(
        ak.in1d(set_intersection, a) & ak.in1d(set_intersection, b))
    print("intersect1d passed test: ", passed)

    set_difference = ak.setdiff1d(a, b)
    print("setdiff1d = ", set_difference.size, set_difference)
    # elements in a and not in b
    passes = ak.all(
        ak.in1d(set_difference, a) & ak.in1d(set_difference, b, invert=True))
    print("setdiff1d passed test: ", passed)

    set_xor = ak.setxor1d(a, b)
    print("setxor1d = ", set_xor.size, set_xor)
    # elements NOT in the intersection of a and b
    passes = ak.all(ak.in1d(set_xor, set_intersection, invert=True))
    print("setxor1d passed test: ", passed)

    ak.disconnect()