예제 #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 selection_WST(data, t, tree=None):
    # find all workers in MTD
    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 = 0
    workers, dists = np.zeros(shape=(2, 0)), []

    # find workers who would perform the task
    for loc in locs:
        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):
            workers = np.concatenate(
                [workers, np.array([[loc[0]], [loc[1]]])], axis=1)
            dists.append(dist)

    # simulation
    if workers.shape[1] == 0:  # no workers
        return 0, False, None, None, None, None, None

    return len(locs), True, 0, random.choice(dists), 0, 0, 0
예제 #4
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
def geocast_naive(tree, data, L, FCFS, U, seed):
    query = scaling_query(tree, L, U)

    # find all workers in the query
    locs = rect_query_points(data, query).transpose()
    # actual utility & average travel cost
    isPerformed, dist = performed_tasks_naive(locs, Params.MTD, L, FCFS, seed)

    if isPerformed:  # the task is performed
        return len(locs), True, dist
    return len(locs), False, dist
예제 #6
0
def geocast_naive(tree, data, L, FCFS, U, seed):
    query = scaling_query(tree, L, U)

    # find all workers in the query
    locs = rect_query_points(data, query).transpose()
    # actual utility & average travel cost
    isPerformed, dist = performed_tasks_naive(locs, Params.MTD, L, FCFS, seed)

    if isPerformed:  # the task is performed
        return len(locs), True, dist
    return len(locs), False, dist
예제 #7
0
def simulation_geocast(t, q, FCFS):
    dist = None
    for i in range(len(q)):
        cell = q[i]
        if Params.PARTIAL_CELL_SELECTION and i == len(q) - 1 and cell.n_data is not None:
            _workers = rect_query_points(cell.n_data, cell.n_box)
        else:
            _workers = cell.n_data
        performed, worker, dist = performed_tasks(_workers, Params.MTD, t, FCFS)
        if performed:  # the task is performed
            return True, worker, dist
    return False, None, dist
예제 #8
0
def simulation_geocast(t, q, FCFS):
    dist = None
    for i in range(len(q)):
        cell = q[i]
        if Params.PARTIAL_CELL_SELECTION and i == len(q) - 1 and cell.n_data is not None:
            _workers = rect_query_points(cell.n_data, cell.n_box)
        else:
            _workers = cell.n_data
        performed, worker, dist = performed_tasks(_workers, Params.MTD, t, FCFS)
        if performed:  # the task is performed
            return True, worker, dist
    return False, None, dist
예제 #9
0
def simple_post_geocast(t, q, q_log):
    """
    Compute actual utility & average travel cost in simulation
    """
    if q is None:
        return [None for _ in range(6)]
    no_workers = 0
    workers = np.zeros(shape=(2, 0))  # worker locations
    for i in range(len(q)):
        if q[i].n_data is not None:
            if Params.PARTIAL_CELL_SELECTION and i == len(q) - 1:
                _workers = rect_query_points(q[i].n_data, q[i].n_box)
            else:
                _workers = q[i].n_data
            no_workers += _workers.shape[1]
            workers = np.concatenate([workers, _workers], axis=1)

    hops_count = 0
    if workers.shape[1] > 0:
        hops_count = simple_hops_expansion(workers.transpose(), Params.NETWORK_DIAMETER)

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

    hops_count = 0
    if workers.shape[1] > 0:
        hops_count = simple_hops_expansion(workers.transpose(),
                                           Params.NETWORK_DIAMETER)

    return no_workers, workers, len(q), hops_count
예제 #11
0
def selection_WST(data, t, tree=None):
    # find all workers in MTD
    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 = 0
    workers, dists = np.zeros(shape=(2, 0)), []

    # find workers who would perform the task
    for loc in locs:
        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):
            workers = np.concatenate([workers, np.array([[loc[0]], [loc[1]]])], axis=1)
            dists.append(dist)

    # simulation
    if workers.shape[1] == 0:  # no workers
            return 0, False, None, None, None, None, None

    return len(locs), True, 0, random.choice(dists), 0, 0, 0