コード例 #1
0
 def test_enviroment_generation_4(self):
     """
     Checks if the enviroment dictionary has "size" key
     """
     table = load_input("_generated_inputs_/5x4.txt")
     enviroment, _ = parse_input_a_estrella(table)
     assert "size" in enviroment.keys()
コード例 #2
0
 def test_enviroment_generation_1(self):
     """
     Checks if the enviroment dictionary size is fine
     """
     table = load_input("_generated_inputs_/5x4.txt")
     enviroment, _ = parse_input_a_estrella(table)
     assert len(list(enviroment.keys())) == 3
コード例 #3
0
    def __init__(self, args=None, enviroment=None, app_root=""):
        self.args = args
        enviroment, graph = parse_input_a_estrella(
            load_input(self.args.tablero_inicial))
        self.enviroment = enviroment or {}  # Estado del (todo) ambiente
        self.graph = graph or Graph()  # Grafo de todo el ambiente

        self.app_root = format_path(app_root)
        self.folders = ["Output"]
        check_root(self.app_root, self.folders)

        self.counter = 0
        self.last = ""
コード例 #4
0
    def test_input_consistency_3(self):
        """
        Checks that the input table is according to the default valid characters
        """
        result = True

        valid_characters = get_characters()

        # Valid table
        table = load_input("_generated_inputs_/5x4.txt")
        for row in table:
            for character in row:
                result = result and character in valid_characters.values()
        assert result
コード例 #5
0
    def __init__(self, args=None, enviroment=None, app_root=""):
        self.args = args
        enviroment, _ = parse_input_a_estrella(
            load_input(self.args.tablero_inicial))
        self.enviroment = enviroment or {}  # Estado del (todo) ambiente
        self.app_root = format_path(app_root)
        self.folders = ["Output"]
        check_root(self.app_root, self.folders)

        # Setting the first direction
        if args.arriba:
            self.direction = "up"
        elif args.derecha:
            self.direction = "right"
        elif args.abajo:
            self.direction = "down"
        elif args.izquierda:
            self.direction = "left"

        # Board definition
        self.matrix = [[" " for _ in range(self.enviroment['size'][0])]
                       for _ in range(self.enviroment['size'][1])]
        self.bunny = self.enviroment['bunny']
        self.carrots = len(self.enviroment['carrot'])
        self.matrix[self.bunny[0]][self.bunny[1]] = 'C'
        for carrot in self.enviroment['carrot']:
            self.matrix[carrot[0]][carrot[1]] = 'Z'

        # Hyper Params
        # Costs
        self.complete_reward = 10000
        self.carrot_reward = 50
        self.movement_pen = 1
        self.directioner_pen = 5

        # Evolve
        self.size_of_population = args.individuos
        self.mutation_rate = args.taza_mutacion
        self.number_of_child = 20
        self.generations = args.generaciones
        self.policy = args.politica

        # Debug
        self.save_files = args.guardar_archivos
        self.print_result = args.show_graphic

        if self.save_files:
            self.clear_directory()
コード例 #6
0
 def test_input(self):
     """
     Tests an arbitrary input of 4x5 and checks that the dimensions are correct
     """
     table = load_input("_generated_inputs_/5x4.txt")
     assert len(table) == 4 and len(table[0]) == 5 + 1  # EOL character
コード例 #7
0
 def test_input_consistency_2(self):
     """
     Tests an arbitrary input of 4x5 and checks that it has a bunny
     """
     table = load_input("_generated_inputs_/5x4.txt")
     assert sum(row.count("C") for row in table) == 1
コード例 #8
0
 def test_input_consistency_1(self):
     """
     Tests an arbitrary input of 4x5 and checks that it has indeed 2 carrots
     """
     table = load_input("_generated_inputs_/5x4.txt")
     assert sum(row.count("Z") for row in table) == 2