def _create_unique_random_hazard(start_pos, x_bound, y_bound, z_bound, r_bound, existing_obstacles): hazard_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]))) hazard_radius = np.random.uniform(r_bound[0], r_bound[1]) hazard_candidate = Hazard(hazard_center.x, hazard_center.y, hazard_center.z, hazard_radius) for obstacle in existing_obstacles: if _is_overlapping(obstacle, hazard_candidate) or _is_within( start_pos, hazard_center, hazard_radius): hazard_candidate = _create_unique_random_hazard( start_pos, x_bound, y_bound, z_bound, r_bound, existing_obstacles) break return hazard_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
def _create_unique_random_hazard(start_pos,x_bound,y_bound,z_bound,r_bound,existing_obstacles): hazard_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] ))) hazard_radius = np.random.uniform(r_bound[0],r_bound[1]) hazard_candidate = Hazard(hazard_center.x,hazard_center.y,hazard_center.z,hazard_radius) for obstacle in existing_obstacles:
<<<<<<< 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): hazard_center = Coordinate(np.random.uniform(HAZARD_BOUND_X[0],HAZARD_BOUND_X[1]),np.random.uniform(HAZARD_BOUND_Y[0],HAZARD_BOUND_Y[1]),np.random.uniform(HAZARD_BOUND_Z[0],HAZARD_BOUND_Z[1])) hazard_radius = np.random.uniform(HAZARD_RADII_BOUND[0],HAZARD_RADII_BOUND[1]) hazard_candidate = Hazard(hazard_center.x,hazard_center.y,hazard_center.z,hazard_radius) hazards.append(hazard_candidate) <<<<<<< HEAD:gym-drill/gym_drill/envs/ObservationSpace.py print("Creating obs_space") print() obs_space = ObservationSpace(SPACE_BOUNDS,TARGET_BOUNDS,HAZARD_BOUNDS,BIT_BOUNDS,targets,hazards,Coordinate(1000,1000,1000)) print("test hazard window") obs_space.update_hazard_window(Coordinate(600,600,600)) print(obs_space.hazard_window) ======= """ print("Here are the targets")