Esempio n. 1
0
        The number of succesful runs 
    """
    for run in range(num_runs):
        fitness = eval_fitness(net, max_bal_steps=additional_steps)
        if fitness < config.fitness_threshold:
            return run
    return num_runs


if __name__ == '__main__':
    # Determine path to configuration file. This path manipulation is
    # here so that the script will run successfully regardless of the
    # current working directory.
    config_path = os.path.join(local_dir, 'two_pole_markov_config.ini')

    # Clean results of previous run if any or init the ouput directory
    utils.clear_output(out_dir)

    # Run the experiment
    pole_length = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]
    num_runs = len(pole_length)
    for i in range(num_runs):
        cart.LENGTH_2 = pole_length[i] / 2.0
        solved = run_experiment(config_path, n_generations=100, silent=True)
        print("run: %d, solved: %s, half-length: %f" %
              (i + 1, solved, cart.LENGTH_2))
        if solved:
            print("Solution found in: %d run, short pole length: %f" %
                  (i + 1, pole_length[i]))
            break
Esempio n. 2
0
                        help='The width of the records subplot')
    parser.add_argument('--height',
                        type=int,
                        default=400,
                        help='The height of the records subplot')
    args = parser.parse_args()

    if not (args.maze == 'medium' or args.maze == 'hard'):
        print('Unsupported maze configuration: %s' % args.maze)
        exit(1)

    # Determine path to configuration file.
    config_path = os.path.join(local_dir, 'maze_config.ini')

    trial_out_dir = os.path.join(out_dir, args.maze)

    # Clean results of previous run if any or init the ouput directory
    utils.clear_output(trial_out_dir)

    # Run the experiment
    maze_env_config = os.path.join(local_dir, '%s_maze.txt' % args.maze)
    maze_env = maze.read_environment(maze_env_config)

    # visualize.draw_maze_records(maze_env, None, view=True)

    print("Starting the %s maze experiment" % args.maze)
    run_experiment(config_file=config_path,
                   maze_env=maze_env,
                   trial_out_dir=trial_out_dir,
                   n_generations=args.generations,
                   args=args)