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 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
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