Пример #1
0
def mono_pruning(q_id, q, k, index, cache):
    IO = 0
    partitions = list(common.partitions(q, index.space, 6))
    points = index.points
    vd = index.voronoi_diagram
    candidate_idx = set()
    candidates = list()
    for partition in partitions:
        h = MinHeap()
        h.push((0, q_id, q))
        visited = {q_id}
        knn = list()
        while len(h) > 0 and len(knn) < k:
            dist, o, p = h.pop()
            if o != q_id and partition.intersects(p):
                knn.append((o, p, dist))
                if o not in candidate_idx:
                    candidate_idx.add(o)
                    candidates.append((o, p, dist))
            for neighbor in vd.neighbors(o):
                if neighbor not in visited:
                    visited.add(neighbor)
                    if neighbor in cache:
                        neighbor_p = cache[neighbor]
                    else:
                        neighbor_p = points[neighbor]
                        cache[neighbor] = neighbor_p
                        IO += 1
                    if partition.intersects(vd.cell(neighbor)):
                        h.push((neighbor_p.distance(q), neighbor, neighbor_p))
    return candidates, IO
Пример #2
0
def bi_pruning(q_id, q, k, index, cache):
    IO = 0
    partitions = list(common.partitions(q, index.space, 6))
    region_list = list()
    points = index.points
    vd = index.voronoi_diagram
    for partition in partitions:
        h = MinHeap()
        h.push((0, q_id, q))
        visited = {q_id}
        knn = list()
        while len(h) > 0 and len(knn) < k:
            dist, o, p = h.pop()
            if o != q_id and partition.intersects(p):
                knn.append((o, p, dist))
            for neighbor in vd.neighbors(o):
                if neighbor not in visited:
                    visited.add(neighbor)
                    if neighbor in cache:
                        neighbor_p = cache[neighbor]
                    else:
                        neighbor_p = points[neighbor]
                        cache[neighbor] = neighbor_p
                        IO += 1
                    if partition.intersects(vd.cell(neighbor)):
                        h.push((neighbor_p.distance(q), neighbor, neighbor_p))
        if len(knn) > 0:
            r = knn[-1][2]
            if r > 0:
                region_list.append(
                    common.sector(q, r, partition.angles).buffer(0.01))
    region = reduce(lambda x, y: x.union(y), region_list)
    return region, IO
Пример #3
0
def pruning(q_id, q, k, index, partition_num):
    partitions = common.partitions(q, index.space, partition_num)
    sigLists = [[] for i in range(partition_num)]
    upper_arc_radius_heaps = [common.MaxHeap() for i in range(partition_num)]
    shaded_areas = [calculate_shaded_area(partition, partition.r) for partition in partitions]
    h = common.MinHeap()
    IO = 0
    h.push((0, index.root))
    while len(h) > 0:
        e_dist, e = h.pop()
        if may_contains_significant_facility(e, shaded_areas):
            if e.is_data_node:
                pruneSpace(q_id, e, k, partitions, sigLists, upper_arc_radius_heaps, shaded_areas)
            else:
                for child in e.children:
                    h.push((child.geom.distance(q), child))
                    IO += 1

    unpruned_area_list = list()
    for i in range(partition_num):
        r_b = min(upper_arc_radius_heaps[i].first(), partitions[i].r)
        angles = [2 * pi / partition_num * i, 2 * pi / partition_num * (i + 1)]
        if r_b > 0:
            unpruned_area_list.append(common.sector(q, r_b, angles).buffer(0.01))
    unpruned_area = reduce(lambda x, y: x.union(y), unpruned_area_list)

    return sigLists, unpruned_area, IO
Пример #4
0
def bi_pruning(q_id, q, k, index, cache):
    IO = 0
    partitions = list(common.partitions(q, index.space, 6))
    region_list = list()
    points = index.points
    vd = index.voronoi_diagram
    visited = {q_id}
    H = common.MinHeap()
    S = [common.MaxHeap() for i in range(6)]
    for neighbor_id in vd.neighbors(q_id):
        if neighbor_id in cache:
            neighbor_p = cache[neighbor_id]
        else:
            neighbor_p = points[neighbor_id]
            cache[neighbor_id] = neighbor_p
            IO += 1
        H.push((1, neighbor_id, neighbor_p))
        visited.add(neighbor_id)
    while len(H) > 0:
        gd_p, p_id, p = H.pop()
        for i in range(6):
            if partitions[i].intersects(p):
                if len(S[i]) < k:
                    dist_bound = float('inf')
                else:
                    dist_bound = S[i].first()[0]
                dist_p = p.distance(q)
                if gd_p <= k and dist_p < dist_bound:
                    S[i].push((dist_p, p_id, p))
                    for neighbor_id in vd.neighbors(p_id):
                        if neighbor_id not in visited:
                            if neighbor_id in cache:
                                neighbor_p = cache[neighbor_id]
                            else:
                                neighbor_p = points[neighbor_id]
                                cache[neighbor_id] = neighbor_p
                                IO += 1
                            gd_neighbor = gd_p + 1
                            visited.add(neighbor_id)
                            H.push((gd_neighbor, neighbor_id, neighbor_p))
    for i in range(6):
        s = sorted(S[i])
        if len(s) >= k:
            r = s[k - 1][0]
        elif len(s) > 0:
            r = s[-1][0]
        else:
            r = 0
        if r > 0:
            region_list.append(
                common.sector(q, r, partitions[i].angles).buffer(0.01))
    region = reduce(lambda x, y: x.union(y), region_list)
    return region, IO
Пример #5
0
def mono_pruning(q_id, q, k, index, cache):
    IO = 0
    partitions = list(common.partitions(q, index.space, 6))
    region_list = list()
    points = index.points
    vd = index.voronoi_diagram
    visited = {q_id}
    H = common.MinHeap()
    S = [common.MaxHeap() for i in range(6)]
    for neighbor_id in vd.neighbors(q_id):
        if neighbor_id in cache:
            neighbor_p = cache[neighbor_id]
        else:
            neighbor_p = points[neighbor_id]
            cache[neighbor_id] = neighbor_p
            IO += 1
        H.push((1, neighbor_id, neighbor_p))
        visited.add(neighbor_id)
    while len(H) > 0:
        gd_p, p_id, p = H.pop()
        for i in range(6):
            if partitions[i].intersects(p):
                if len(S[i]) < k:
                    dist_bound = float('inf')
                else:
                    dist_bound = S[i].first()[0]
                dist_p = p.distance(q)
                if gd_p <= k and dist_p < dist_bound:
                    S[i].push((dist_p, p_id, p))
                    for neighbor_id in vd.neighbors(p_id):
                        if neighbor_id not in visited:
                            if neighbor_id in cache:
                                neighbor_p = cache[neighbor_id]
                            else:
                                neighbor_p = points[neighbor_id]
                                cache[neighbor_id] = neighbor_p
                                IO += 1
                            gd_neighbor = gd_p + 1
                            visited.add(neighbor_id)
                            H.push((gd_neighbor, neighbor_id, neighbor_p))
    candidate_idx = set()
    candidates = list()
    for i in range(6):
        s = sorted(S[i])
        if len(s) >= k:
            s = s[:k]
        for dist, p_id, p in s:
            if p_id not in candidate_idx:
                candidate_idx.add(p_id)
                candidates.append((p_id, p, dist))
    return candidates, IO