def show_the_model(args):
    """Show the problem"""
    floor = construct_default_floor_plan()
    goal = np.array([0.8, 0.8])
    env = SensorSingleGoalProblem(floor, goal)
    if args.novio:
        env.out_vio_step = 1
    if args.harder:
        env.x0lb[0] = 0.1
        env.x0ub[0] = 0.9
        env.x0lb[1] = 0.1
        env.x0ub[1] = 0.9
    env_name = str(env)
    print('Environment is %s' % env_name)

    config = pu.get_train_gym_config(env_name=env_name)
    sim_n = args.num
    v_x0, v_xf, v_traj = pu.policy_rollout(env, config, sim_n, False, True)
    plt.switch_backend('TkAgg')
    fig, axes = pl.subplots(sim_n)
    for i in range(sim_n):
        ax = axes[i]
        sim_rst = v_traj[i]
        x, u, dt = sim_rst['state'], sim_rst['action'], sim_rst['dt']
        floor.draw(ax)
        circle1 = plt.Circle((goal[0], goal[1]), 0.05, color='g')
        ax.add_artist(circle1)
        ax.plot(*x[:, :2].T)
    plt.savefig('gallery/%s-%d-cases.pdf' % (env_name, sim_n))
    plt.show()
Exemplo n.º 2
0
def show_the_model(args):
    """Show the problem"""
    floor = construct_default_floor_plan()
    goal = np.array([0.8, 0.8])
    env = SingleGoalProblem(floor, goal)
    env.x0lb[:2] = [0.1, 0.1]
    env.x0ub[:2] = [0.9, 0.9]
    if args.novio:
        env.out_vio_step = 1
    env_name = str(env)

    config = pu.get_train_gym_config(env_name=env_name)
    sim_n = args.num
    v_x0, v_xf, v_traj = pu.policy_rollout(env, config, sim_n, False, True)
    # fig, ax = pld.get3dAxis()
    matplotlib.use('TkAgg')
    plt.switch_backend('TkAgg')
    fig, axes = pl.subplots(sim_n)
    for i in range(sim_n):
        sim_rst = v_traj[i]
        x, u, dt = sim_rst['state'], sim_rst['action'], sim_rst['dt']
        ax = axes[i]
        floor.draw(ax)
        circle1 = plt.Circle((0.8, 0.8), 0.05, color='g')
        ax.add_artist(circle1)
        ax.plot(*x[:, :2].T)
    fig.tight_layout()
    plt.savefig('gallery/%s-%d-cases.pdf' % (env_name, sim_n))
    plt.show()
Exemplo n.º 3
0
def show_the_model(args):
    """Show the model"""
    env, floor, update_fun = construct_env(args)
    env_name = 'update_%s' % str(env)
    config = pu.get_train_gym_config(env_name=env_name, seed=np.random.randint(100), num_frames=2e6)
    sim_n = args.num
    v_x0, v_xf, v_traj = pu.policy_rollout(env, config, sim_n, show=False, return_traj=True)
    plt.switch_backend('TkAgg')
    fig, axes = pl.subplots(sim_n)
    for i in range(sim_n):
        ax = axes[i]
        sim_rst = v_traj[i]
        x, u, dt = sim_rst['state'], sim_rst['action'], sim_rst['dt']
        floor.draw(ax)
        ax.plot(*x[:, :2].T)
    plt.savefig('gallery/%s-%d-cases.pdf' % (env_name, sim_n))
    plt.show()
Exemplo n.º 4
0
def show_the_model(args):
    """Show the problem"""
    env, floor = construct_env()
    env_name = str(env)
    print('Environment is %s' % env_name)

    config = pu.get_train_gym_config(env_name=env_name)
    sim_n = args.num
    v_x0, v_xf, v_traj, v_goal = pu.policy_rollout(env, config, sim_n, show=False, return_traj=True, return_goal=True)
    plt.switch_backend('TkAgg')
    fig, axes = pl.subplots(sim_n)
    for i in range(sim_n):
        ax = axes[i]
        sim_rst = v_traj[i]
        goal = v_goal[i]
        x, u, dt = sim_rst['state'], sim_rst['action'], sim_rst['dt']
        floor.draw(ax)
        circle1 = plt.Circle((goal[0], goal[1]), 0.05, color='g')
        ax.add_artist(circle1)
        ax.plot(*x[:, :2].T)
    plt.savefig('gallery/%s-%d-cases.pdf' % (env_name, sim_n))
    plt.show()
def perform_mass_test(args):
    """Do a massive simulation on this problem."""
    floor = construct_default_floor_plan()
    goal = np.array([0.8, 0.8])
    env = SensorSingleGoalProblem(floor, goal)
    if args.novio:
        env.out_vio_step = 1
    env.x0lb[0] = 0.1
    env.x0ub[0] = 0.9
    env.x0lb[1] = 0.1
    env.x0ub[1] = 0.9
    env_name = str(env)
    env.out_vio_step = 1  # do this anyway
    print('Environment is %s' % env_name)

    config = pu.get_train_gym_config(env_name=env_name)
    sim_n = args.num
    v_x0, v_xf, v_flag = pu.policy_rollout(env, config, sim_n, show=False, return_success=True)
    succeed = np.sum(v_flag == 1)
    collision = np.sum(v_flag == -1)
    print('succeed in %d / %d' % (succeed, sim_n))
    print('collision in %d / %d' % (collision, sim_n))
    print('0.1:', np.sum(np.linalg.norm(v_xf - np.array([0.8, 0.8, 0, 0]), axis=1) < 0.1))
    with open('succeed_log.txt', 'at') as f:
        f.write('Env:%s' % env_name)
        f.write('Succeed: %d' % succeed)
        f.write('Collision: %d' % collision)
    return
    fig, ax = pl.subplots()
    plt.switch_backend('TkAgg')
    floor.draw(ax)
    ax.scatter(*v_x0[mask0, :2].T, label='Succeed')
    ax.scatter(*v_x0[~mask0, :2].T, label='Failure')
    ax.legend()
    fig.savefig('gallery/%s-massive-sim-x0.pdf' % env_name)
    plt.show()