def set_destination_bounds(population, destinations, xmin, ymin, xmax, ymax, dest_no=1, teleport=True): '''teleports all persons within limits Function that takes the population and coordinates, teleports everyone there, sets destination active and destination as reached Keyword arguments ----------------- population : ndarray the array containing all the population information destinations : ndarray the array containing all the destination information xmin, ymin, xmax, ymax : int or float define the bounds on both axes where the individual can roam within after reaching the defined area dest_no : int the destination number to set as active (if more than one) teleport : bool whether to instantly teleport individuals to the defined locations ''' #teleport if teleport: population[:, 1] = np.random.uniform(low=xmin, high=xmax, size=len(population)) population[:, 2] = np.random.uniform(low=ymin, high=ymax, size=len(population)) #get parameters center为中间值 wander直接为最大值最小值的差(考虑随机分) x_center, y_center, x_wander, y_wander = get_motion_parameters( xmin, ymin, xmax, ymax) #set destination centers destinations[:, (dest_no - 1) * 2] = x_center destinations[:, ((dest_no - 1) * 2) + 1] = y_center #set wander bounds population[:, 13] = x_wander population[:, 14] = y_wander population[:, 11] = dest_no #set destination active population[:, 12] = 1 #set destination reached return population, destinations
def set_destination_bounds(population, destinations, polygon, dest_no=1, teleport=True): '''teleports all persons within limits Function that takes the population and coordinates, teleports everyone there, sets destination active and destination as reached Keyword arguments ----------------- population : ndarray the array containing all the population information destinations : ndarray the array containing all the destination information xmin, ymin, xmax, ymax : int or float define the bounds on both axes where the individual can roam within after reaching the defined area dest_no : int the destination number to set as active (if more than one) teleport : bool whether to instantly teleport individuals to the defined locations ''' #teleport if teleport: random_points_x = [ get_random_point_in_polygon() for _ in range(len(population)) ] population[:, 1] = np.append(list(list(zip(*random_points_x))[0])) population[:, 2] = np.append(list(list(zip(*random_points_x))[1])) #get parameters x_center, y_center, x_wander, y_wander = get_motion_parameters( xmin, ymin, xmax, ymax) #set destination centers destinations[:, (dest_no - 1) * 2] = x_center destinations[:, ((dest_no - 1) * 2) + 1] = y_center #set wander bounds population[:, 13] = x_wander population[:, 14] = y_wander population[:, 11] = dest_no #set destination active population[:, 12] = 1 #set destination reached return population, destinations
def go_to_location(patients, destinations, location_bounds, dest_no=1): '''sends patient to defined location Function that takes a patient an destination, and sets the location as active for that patient. Keyword arguments ----------------- population : ndarray the array containing all the population information destinations : ndarray the array containing all destinations information location_bounds : list or tuple defines bounds for the location the patient will be roam in when sent there. format: [xmin, ymin, xmax, ymax] dest_no : int the location number, used as index for destinations array if multiple possible destinations are defined`. TODO: vectorize ''' x_center, y_center, x_wander, y_wander = get_motion_parameters(location_bounds[0], location_bounds[1], location_bounds[2], location_bounds[3]) patients[:,13] = x_wander patients[:,14] = y_wander destinations[:,(dest_no - 1) * 2] = x_center destinations[:,((dest_no - 1) * 2) + 1] = y_center patients[:,11] = dest_no #set destination active return patients, destinations
def go_to_location(patient, destination, location_bounds, dest_no=1): '''sends patient to defined location Function that takes a patient an destination, and sets the location as active for that patient. Keyword arguments ----------------- patient : 1d array 1d array of the patient data, is a row from population matrix destination : 1d array 1d array of the destination data, is a row from destination matrix location_bounds : list or tuple defines bounds for the location the patient will be roam in when sent there. format: [xmin, ymin, xmax, ymax] dest_no : int the location number, used as index for destinations array if multiple possible destinations are defined`. TODO: vectorize ''' x_center, y_center, x_wander, y_wander = get_motion_parameters( location_bounds[0], location_bounds[1], location_bounds[2], location_bounds[3]) patient[13] = x_wander patient[14] = y_wander destination[(dest_no - 1) * 2] = x_center destination[((dest_no - 1) * 2) + 1] = y_center patient[11] = dest_no #set destination active return patient, destination