Exemplo n.º 1
0
    def test_inactive_mower(self):

        # Test that having no instructions doesn't crash the simulation
        # Also check that inactive mowers still occupy positions

        lawn_size = (2, 0)
        mowers_configs = [((0, 0, 'S'), []), ((2, 0, 'W'), ["F", "F", "F"])]

        final_mowers = simulation.run(lawn_size, mowers_configs)

        assert (final_mowers[0][0], final_mowers[0][1],
                final_mowers[0][2]) == (0, 0, 'S')
        assert (final_mowers[1][0], final_mowers[1][1],
                final_mowers[1][2]) == (1, 0, 'W')
Exemplo n.º 2
0
    def test_out_of_bounds(self):

        # During this example, mowers will try to go out of bounds

        lawn_size = (3, 3)
        mowers_configs = [((0, 1, 'W'), ["F", "R", "F"]),
                          ((3, 3, 'E'), ["F", "R", "R"])]

        final_mowers = simulation.run(lawn_size, mowers_configs)

        assert (final_mowers[0][0], final_mowers[0][1],
                final_mowers[0][2]) == (0, 2, 'N')
        assert (final_mowers[1][0], final_mowers[1][1],
                final_mowers[1][2]) == (3, 3, 'W')
Exemplo n.º 3
0
    def test_base_example(self):

        # Base example given with the instructions of the test
        lawn_size = (5, 5)
        mowers_configs = [
            ((1, 2, 'N'), ["L", "F", "L", "F", "L", "F", "L", "F", "F"]),
            ((3, 3, 'E'), ["F", "F", "R", "F", "F", "R", "F", "R", "R", "F"])
        ]

        final_mowers = simulation.run(lawn_size, mowers_configs)

        assert (final_mowers[0][0], final_mowers[0][1],
                final_mowers[0][2]) == (1, 3, 'N')
        assert (final_mowers[1][0], final_mowers[1][1],
                final_mowers[1][2]) == (5, 1, 'E')
Exemplo n.º 4
0
    def test_concurrency(self):

        # During this example mowers will try to go on occupied positions
        # First mower 2 where mower 1 already is
        # Then mower 1 will want to move before mower 2 leaves the square free

        lawn_size = (3, 3)
        mowers_configs = [((0, 3, 'N'), ["F", "F", "R", "F"]),
                          ((2, 3, 'W'), ["F", "F", "L", "F"])]

        final_mowers = simulation.run(lawn_size, mowers_configs)

        assert (final_mowers[0][0], final_mowers[0][1],
                final_mowers[0][2]) == (0, 3, 'E')
        assert (final_mowers[1][0], final_mowers[1][1],
                final_mowers[1][2]) == (1, 2, 'S')
Exemplo n.º 5
0
 #
 # QTop
 #
 # Copyright (c) 2016 Jacob Marks ([email protected])
 #
 # This file is part of QTop.
 #
 # QTop is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
import numpy as np
import sys
sys.path.append('../')
from src import common, simulation, error_models
sys.path.append('../src')
from decoders import dsp

################## Color Code Simulation ##################
path_to = str(sys.argv[1])
model = error_models.Depolarizing()
decoder = dsp.DSP_decoder()
L_vals = [9,11,13]
p_vals = np.linspace(0.05,0.13,15)
num_trials = 30000
d = 2
sim = simulation.simulation(d, '6-6-6 Color Code', [model, 'Depolarizing Channel'], [decoder, 'DSP'], path_to)
simulation.run(sim, L_vals, p_vals, num_trials)

Exemplo n.º 6
0
def start_sim():
    simulation.run()
    eel.redraw()
    print("done")
Exemplo n.º 7
0
    # Get the required config file
    root_path = os.getcwd()
    configs_folder = os.path.join(root_path, "configs")
    config_name = args.config
    config_path = os.path.join(configs_folder, config_name)

    # Create a parser for the config file
    parser = Parser(config_path)
    # Parse the config file to get the lawn size and the mowers parameters
    lawn_size, mowers_configs = parser.parse_config_file()
    logging.info(f"Lawn size: {lawn_size}")
    logging.info(f"Number of mowers: {len(mowers_configs)}")

    # Run the simulation using the created mowers
    # And get the final positions of the mowers
    final_mowers_status = simulation.run(lawn_size, mowers_configs,
                                         args.verbose)

    # Saving the results in the output folder
    # And printing them if verbose is enabled
    logging.info("\nEnd Results")
    results = ""
    for i, mower_status in enumerate(final_mowers_status):
        logging.info(f"Mower n°{i}")
        logging.info(
            f"Position: ({mower_status[0]}, {mower_status[1]}), Orientation: {mower_status[2]}"
        )
        results += f"{mower_status[0]} {mower_status[1]} {mower_status[2]}\n"
    os.makedirs(os.path.join(root_path, "output"), exist_ok=True)
    with open(os.path.join(root_path, "output", config_name), "w+") as f:
        f.write(results)
        f.close()