예제 #1
0
def generate_maze_sp(size,
                     xs,
                     ys,
                     x_axis_sp,
                     y_axis_sp,
                     normalize=True,
                     obstacle_ratio=.2,
                     map_style='blocks'):
    """
    Returns a maze ssp as well as an occupancy grid for the maze (both fine and coarse)
    """

    # Create a random maze with no inaccessible regions
    if map_style == 'maze':
        # temp hack to get the sizes right
        maze = generate_maze(map_style=map_style,
                             side_len=size + 2,
                             obstacle_ratio=obstacle_ratio)
    else:
        maze = generate_maze(map_style=map_style,
                             side_len=size,
                             obstacle_ratio=obstacle_ratio)

    # Map the maze structure to the resolution of xs and ys
    x_range = xs[-1] - xs[0]
    y_range = ys[-1] - ys[0]
    fine_maze = np.zeros((len(xs), len(ys)))

    for i, x in enumerate(xs):
        for j, y in enumerate(ys):
            xi = np.clip(int(np.round(((x - xs[0]) / x_range) * size)), 0,
                         size - 1)
            yi = np.clip(int(np.round(((y - ys[0]) / y_range) * size)), 0,
                         size - 1)
            # If the corresponding location on the coarse maze is a wall, make it a wall on the fine maze as well
            if maze[xi, yi] == 1:
                fine_maze[i, j] = 1

    # Create a region vector for the maze
    sp = generate_region_vector(desired=fine_maze,
                                xs=xs,
                                ys=ys,
                                x_axis_sp=x_axis_sp,
                                y_axis_sp=y_axis_sp,
                                normalize=normalize)

    return sp, maze, fine_maze
예제 #2
0
    'location': 'none',
    'goal_loc': 'none',
    'goal_vec': 'none',
    'bc_n_ring': 0,
    'hd_n_cells': 0,
    'csp_dim': 0,
    'goal_csp': False,
    'agent_csp': False,
    'goal_distance': args.goal_distance  # 0 means completely random
}

obs_dict = generate_obs_dict(params)

np.random.seed(params['seed'])

map_array = generate_maze(map_style=params['map_style'],
                          side_len=params['map_size'])

# map_array = np.array([
#     [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
#     [1, 1, 1, 1, 1, 1, 1, 1, 0, 1],
#     [1, 1, 1, 1, 1, 1, 1, 0, 0, 1],
#     [1, 1, 1, 1, 1, 1, 0, 0, 0, 1],
#     [1, 1, 1, 1, 1, 0, 0, 0, 0, 1],
#     [1, 1, 1, 1, 0, 0, 0, 0, 0, 1],
#     [1, 1, 1, 0, 0, 0, 0, 0, 0, 1],
#     [1, 1, 0, 0, 0, 0, 0, 0, 0, 1],
#     [1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
#     [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
# ])

env = GridWorldEnv(
if args.maze_dataset:
    coarse_maps = np.load(args.maze_dataset)['coarse_mazes']

# compute scaling and offset that will transform a value in the range (0, map-size) to (limit_low, limit_high)

map_size = coarse_maps.shape[1]
ssp_scaling = (args.limit_high - args.limit_low) / map_size
ssp_offset = map_size / 2.

for mi in range(args.n_maps):
    print("Map {} of {}".format(mi + 1, args.n_maps))

    if args.maze_dataset == '':
        # Generate maps if not given
        coarse_maps[mi, :, :] = generate_maze(map_style=params['map_style'],
                                              side_len=params['map_size'])

    env = GridWorldEnv(
        map_array=coarse_maps[mi, :, :],
        observations=obs_dict,
        movement_type=params['movement_type'],
        max_lin_vel=params['max_lin_vel'],
        max_ang_vel=params['max_ang_vel'],
        continuous=params['continuous'],
        max_steps=params['episode_length'],
        fixed_episode_length=params['fixed_episode_length'],
        dt=params['dt'],
        screen_width=300,
        screen_height=300,
        # TODO: use these parameters appropriately, and save them with the dataset
        csp_scaling=