def test_example(self):
        experiment_name = 'test_example'

        register_custom_components()

        # test training for a few thousand frames
        cfg = custom_parse_args(argv=['--algo=APPO', '--env=my_custom_env_v1', f'--experiment={experiment_name}'])
        cfg.num_workers = 2
        cfg.train_for_env_steps = 100000
        cfg.save_every_sec = 1
        cfg.decorrelate_experience_max_seconds = 0
        cfg.seed = 0
        cfg.device = 'cpu'

        status = run_algorithm(cfg)
        self.assertEqual(status, ExperimentStatus.SUCCESS)

        # then test the evaluation of the saved model
        cfg = custom_parse_args(
            argv=['--algo=APPO', '--env=my_custom_env_v1', f'--experiment={experiment_name}'],
            evaluation=True,
        )
        cfg.device = 'cpu'
        status, avg_reward = enjoy(cfg, max_num_frames=1000)

        directory = experiment_dir(cfg=cfg)
        self.assertTrue(isdir(directory))
        shutil.rmtree(directory, ignore_errors=True)
        # self.assertFalse(isdir(directory))

        self.assertEqual(status, ExperimentStatus.SUCCESS)

        # not sure if we should check it here, it's optional
        # maybe a longer test where it actually has a chance to converge
        self.assertGreater(avg_reward, 60)
Beispiel #2
0
import matplotlib.pyplot as plt

mygraph = graph()

print(mygraph)
machine_number = 300
sample_number = 500
epsilon = 0.1
delta = 0.1
time_list = range(300)
eta = 0.7
gamma = 1
a = 0.5 * (1 + eta) * math.log(4 * mygraph.leaf_node_number *
                               (1 + eta) / delta / (1 - eta))
cm = 1
cp = 1

a1 = run_algorithm.run_algorithm(mygraph, machine_number, sample_number,
                                 epsilon, delta, time_list, eta, gamma, a,
                                 'paper', cm)
a2 = run_uct.run_uct_new(mygraph, machine_number, sample_number, time_list,
                         eta, gamma, cp)

plt.plot(time_list, a1, label='P-MCGS', lw=3)
plt.plot(time_list, a2, label='P-UCT', lw=3)

plt.xlabel("iterations", size=21)
plt.ylabel("error", size=21)
plt.legend(fontsize=18)
plt.savefig('final_MCG_UCT_tree.pdf')
    save_results = ["Yes", "No"]
    show_results = ["Yes", "No"]
    dimensions = ["1D", "2D", "3D"]
    algorithms = [
        "Random Walk", "Greedy - Look-ahead", "Beam Search",
        "Branch-n-Bound - probabilty-based", "Hill Climber"
    ]
    proteins = parse_data()

    # Get the user's choices
    choices = get_choices(save_results, show_results, dimensions, algorithms,
                          proteins)
    choice_save, choice_show, choice_dimension, choice_algorithm, choice_protein = choices

    # Run the chosen algorithm
    results = run_algorithm(algorithms, choice_algorithm, choice_protein,
                            choice_dimension)
    protein, energies, matrix_sizes, start, elapsed_time, parameters = results

    # Determine the total protein solutions evaluated from the energies dictionary
    total_evaluated = sum(energies.values())

    # Convert the unix timestamps to dates and/or hours, minutes and seconds)
    start_time = time.strftime("%Y-%m-%d_%H-%M-%S", time.gmtime(start))
    elapsed_HHMMSS = time.strftime("%H:%M:%S", time.gmtime(elapsed_time))

    print(f"\nAlgorithm finished\nElapsed time: {elapsed_HHMMSS}")

    # Saves the results to a csv file and saves the figures as png files
    if choice_save == "Yes":

        with open("results/results.csv", "a", encoding="utf-8") as file:
def main():
    """Script entry point."""
    register_custom_components()
    cfg = custom_parse_args()
    status = run_algorithm(cfg)
    return status
delta = 0.1
time_list = range(1500)
eta = 0.7
gamma = 1
#algo = 'paper'
a = 0.5 * (1 + eta) * math.log(4 * mygraph.leaf_node_number *
                               (1 + eta) / delta / (1 - eta))
cm = 1

result1 = []
machine_number = 1
while machine_number <= 256:
    #    print(machine_number)
    result1.append(
        run_algorithm.run_algorithm(mygraph, machine_number, sample_number,
                                    epsilon, delta, time_list, 0.7, gamma, a,
                                    'paper', cm))
    machine_number = machine_number * 4

result2 = []
machine_number = 1
while machine_number <= 256:
    result2.append(
        run_algorithm.run_algorithm(mygraph, machine_number, sample_number,
                                    epsilon, delta, time_list, 100000, gamma,
                                    a, 'naive', cm))
    machine_number = machine_number * 4

my_result = open('final_linearly_speedup_result_MCG_graph.txt', 'w')
for i in range(5):
    for j in range(len(time_list) - 1):
Beispiel #6
0
def main_menu():
    pathfinding_algs = ['d', 'bi_d', 'a*']
    maze_generation_algs = ['r_bt', 'el', 'kr', 'prim']
    hover, maze, pf, mg, wg, e_maze, e_pf = None, None, None, False, False, None, None
    while True:
        menu_surface.fill(WHITE)
        rects = blit_text(hover, maze, pf, e_maze, e_pf, mg, wg)
        x, y = pygame.mouse.get_pos()
        x, y = x / (WIN.get_width() / menu_surface.get_width()), y / (
            WIN.get_height() / menu_surface.get_height())
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key in (pygame.K_q, pygame.K_ESCAPE):
                    sys.exit()
                elif event.key == pygame.K_RETURN:
                    pf_alg = pathfinding_algs[pf] if pf is not None else None
                    maze_alg = maze_generation_algs[
                        maze] if maze is not None else None
                    if pf_alg is not None:
                        ra.run_algorithm(pf_alg, maze_alg, mg, wg)
            if event.type == pygame.MOUSEBUTTONDOWN:
                if event.button == 1:
                    clicked = [rect.collidepoint((x, y)) for rect in rects]
                    if 1 in clicked:
                        chosen = clicked.index(1)
                        if chosen <= 2:
                            pf = chosen
                            e_pf = None
                        elif chosen < 7:
                            maze = chosen - 3
                            e_maze = None
                            wg = False
                        elif chosen == 7:
                            if maze is not None:
                                mg = True
                        elif chosen == 8:
                            if maze is None:
                                wg = True
                elif event.button == 3:
                    clicked = [rect.collidepoint((x, y)) for rect in rects]
                    if 1 in clicked:
                        undone = clicked.index(1)
                        if undone <= 2:
                            e_pf = undone
                            if pf == e_pf:
                                pf = None
                        elif undone < 7:
                            e_maze = undone - 3
                            if maze == e_maze:
                                maze = None
                                mg = False
                        elif undone == 7:
                            mg = False
                        else:
                            wg = False

        # check for hovering over the algorithm options
        hover = [rect.collidepoint((x, y)) for rect in rects]
        if 1 in hover:
            hover = hover.index(1)
        else:
            hover = None

        # transform the menu surface to the current screen dimensions
        WIN.blit(pygame.transform.scale(menu_surface,
                                        WIN.get_rect().size), (0, 0))
        pygame.display.update()