コード例 #1
0
def post_geocast(t, q, q_log):
    """
    Compute actual utility & average travel cost in simulation
    """
    if q is None:
        return [None for _ in range(6)]
    cells = []
    no_workers = 0
    workers = np.zeros(shape=(2, 0))  # worker locations
    for i in range(len(q)):
        cell = q[i]
        cells.append([cell, log_cell_info(cell), q_log[i]])
        if cell.n_data is not None:
            if Params.PARTIAL_CELL_SELECTION and i == len(q) - 1:
                _workers = rect_query_points(cell.n_data, cell.n_box)
            else:
                _workers = cell.n_data
            no_workers += _workers.shape[1]
            workers = np.concatenate([workers, _workers], axis=1)

    hops_count, coverage, hops_count2 = 0, 0, 0
    if workers.shape[1] > 0:
        hops_count, coverage, hops_count2 = hops_expansion(
            t, workers.transpose(), Params.NETWORK_DIAMETER)

    return no_workers, workers, cells, hops_count, coverage, hops_count2
コード例 #2
0
def post_geocast(t, q, q_log):
    """
    Compute actual utility & average travel cost in simulation
    """
    if q is None:
        return [None for _ in range(6)]
    cells = []
    no_workers = 0
    workers = np.zeros(shape=(2, 0))  # worker locations
    for i in range(len(q)):
        cell = q[i]
        cells.append([cell, log_cell_info(cell), q_log[i]])
        if cell.n_data is not None:
            if Params.PARTIAL_CELL_SELECTION and i == len(q) - 1:
                _workers = rect_query_points(cell.n_data, cell.n_box)
            else:
                _workers = cell.n_data
            no_workers += _workers.shape[1]
            workers = np.concatenate([workers, _workers], axis=1)

    hops_count, coverage, hops_count2 = 0, 0, 0
    if workers.shape[1] > 0:
        hops_count, coverage, hops_count2 = hops_expansion(t, workers.transpose(), Params.NETWORK_DIAMETER)

    return no_workers, workers, cells, hops_count, coverage, hops_count2
コード例 #3
0
def geocast_knn(data, t):
    # find all workers in MTD

    # find all workers in the query
    MTD_RECT = np.array([[t[0] - Params.ONE_KM * Params.MTD, t[1] - Params.ONE_KM * Params.MTD],
                         [t[0] + Params.ONE_KM * Params.MTD, t[1] + Params.ONE_KM * Params.MTD]])
    locs = rect_query_points(data, MTD_RECT).transpose()
    locs = sorted(locs, key=lambda loc: distance(loc[0], loc[1], t[0], t[1]))

    u, dist, found = 0, 0, False
    workers = np.zeros(shape=(2, 0))
    for loc in locs:
        workers = np.concatenate([workers, np.array([[loc[0]], [loc[1]]])], axis=1)
        _dist = distance(loc[0], loc[1], t[0], t[1])
        u_c = acc_rate(Params.MTD, _dist)
        u = 1 - (1 - u) * (1 - u_c)
        if is_performed(u_c):
            if not found:
                found = True
                dist = _dist
        if u >= Params.U:
            break

    # simulation
    isPerformed, worker, dist_fcfs = performed_tasks(workers, Params.MTD, t, True)
    hops_count, coverage, hops_count2 = hops_expansion(t, workers.transpose(), Params.NETWORK_DIAMETER)

    if isPerformed:  # the task is performed
        return workers.shape[1], True, dist, dist_fcfs, hops_count, coverage, hops_count2

    return workers.shape[1], False, None, None, hops_count, coverage, hops_count2