def _create_unique_random_target(start_pos,x_bound,y_bound, z_bound,r_bound,existing_targets): target_center = Coordinate(np.random.uniform(x_bound[0],x_bound[1]),(np.random.uniform(y_bound[0],y_bound[1])),(np.random.uniform(z_bound[0],z_bound[1]))) target_radius = np.random.uniform(r_bound[0],r_bound[1]) target_candidate = TargetBall(target_center.x,target_center.y,target_center.z,target_radius) for target in existing_targets: if _is_overlapping(target,target_candidate) or _is_within(start_pos,target_center,target_radius): target_candidate =_create_unique_random_target(start_pos,x_bound,y_bound,z_bound,r_bound,existing_targets) break return target_candidate
def read_env_from_file(filename,line_number): targets = [] hazards = [] file = open(filename) environment_line = "" # We iterate to the desired line to avoid loading all lines into memory for i, line in enumerate(file): if i == line_number: environment_line = line break target_string = environment_line.split("-")[0] hazard_string = environment_line.split("-")[1] target_list_string = target_string.split(";") hazard_list_string = hazard_string.split(";") for t in target_list_string: # "10,10,5" l = t.split(",") try: x = int(l[0]) y = int(l[1]) r = int(l[2]) except Exception: raise ValueError("Coordinates in file are not numbers!") target_ball = TargetBall(x,y,r) targets.append(target_ball) for h in hazard_list_string: # "10,10,5" l = h.split(",") try: x = int(l[0]) y = int(l[1]) r = int(l[2]) except Exception: raise ValueError("Coordinates in file are not numbers!") hazard_ball = Hazard(x,y,r) hazards.append(hazard_ball) return targets, hazards
def _read_env_from_file(filename,line_number): if line_number == 0: print("Cannot read environments specification from line 0 as it is used for documentation") print("Line number must be 1 or higher!") sys.exit() targets = [] hazards = [] file = open(filename) environment_line = "" # We iterate to the desired line to avoid loading all lines into memory for i, line in enumerate(file): if i == line_number: environment_line = line break target_string = environment_line.split("/")[0] target_list_string = target_string.split(";") for t in target_list_string: # "10,10,5" l = t.split(",") try: x =l[0] y = l[1] z = l[2] r = l[3] x = int(x) y = int(y) z = int(z) r = int(r) except Exception: print(target_string) print(target_list_string) print("t;",t) print("l;",l) raise ValueError("Coordinates in file are not numbers!") target_ball = TargetBall(x,y,z,r) targets.append(target_ball) try: hazard_string = environment_line.split("/")[1] hazard_list_string = hazard_string.split(";") for h in hazard_list_string: # "10,10,5" l = h.split(",") try: x = l[0] y = l[1] z = l[2] r = l[3] x = int(x) y = int(y) z = int(z) r = int(r) except Exception: raise ValueError("Coordinates in file are not numbers!") hazard_ball = Hazard(x,y,z,r) hazards.append(hazard_ball) except Exception: hazards = [] return targets, hazards
TARGET_BOUND_Y = [0.1*SCREEN_Y,0.6*SCREEN_Y] TARGET_BOUND_Z = [0.5*SCREEN_Z,0.9*SCREEN_Z] TARGET_RADII_BOUND = [20,50] TARGET_BOUNDS = [TARGET_BOUND_X,TARGET_BOUND_Y,TARGET_BOUND_Z,TARGET_RADII_BOUND] HAZARD_BOUND_X = [0,SCREEN_X] HAZARD_BOUND_Y = [0,SCREEN_Y] HAZARD_BOUND_Z = [0,SCREEN_Z] HAZARD_RADII_BOUND = [20,50] HAZARD_BOUNDS = [HAZARD_BOUND_X,HAZARD_BOUND_Y,HAZARD_BOUND_Z,HAZARD_RADII_BOUND] targets = [] for _ in range(4): target_center = Coordinate(np.random.uniform(TARGET_BOUND_X[0],TARGET_BOUND_X[1]),np.random.uniform(TARGET_BOUND_Y[0],TARGET_BOUND_Y[1]),np.random.uniform(TARGET_BOUND_Z[0],TARGET_BOUND_Z[1])) target_radius = np.random.uniform(TARGET_RADII_BOUND[0],TARGET_RADII_BOUND[1]) target_candidate = TargetBall(target_center.x,target_center.y,target_center.z,target_radius) targets.append(target_candidate) <<<<<<< HEAD:gym-drill/gym_drill/envs/ObservationSpace.py hazards = [] ======= hazards = [] # Additional data DIAGONAL = np.sqrt(SCREEN_X**2 + SCREEN_Y**2) TARGET_DISTANCE_BOUND = [0,DIAGONAL] RELATIVE_ANGLE_BOUND = [-np.pi,np.pi] EXTRA_DATA_BOUNDS = [TARGET_DISTANCE_BOUND,RELATIVE_ANGLE_BOUND] # [Distance, angle between current direction and target direction] >>>>>>> 2914a7ab17b685790fbbcc82ad796d416a700bb1:2D-version/gym-drill/gym_drill/envs/ObservationSpace.py for _ in range(4):