Ejemplo n.º 1
0
    def test_compare_random_individuals(self):
        individual_1 = Individual.generate(individual_type=3,
                                           config=Config.get_instance())

        RandomManager.clear_random_values()
        RandomManager.load_random_values(self._random_file)
        individual_2 = Individual.generate(individual_type=3,
                                           config=Config.get_instance())

        self.assertTrue(individual_1.compare(individual_2))
Ejemplo n.º 2
0
    def setUpClass(cls):
        config_file = os.path.join(MLCIntegrationTest.TEST_DIRECTORY,
                                   './configuration.ini')
        ev_script = os.path.join(MLCIntegrationTest.TEST_DIRECTORY,
                                 './default_evaluation_script.py')
        preev_script = os.path.join(MLCIntegrationTest.TEST_DIRECTORY,
                                    './default_preevaluation_script.py')

        # Load the config
        config = Config.get_instance()
        config.read(config_file)

        # Load randoms from file
        random_file = 'matlab_randoms.txt'
        RandomManager.clear_random_values()
        RandomManager.load_random_values(random_file)

        # Create the workspace directory
        try:
            os.makedirs(MLCIntegrationTest.WORKSPACE_DIR)
        except OSError:
            shutil.rmtree(MLCIntegrationTest.WORKSPACE_DIR)
            os.makedirs(MLCIntegrationTest.WORKSPACE_DIR)

        # Create a new experiment, which will be used to
        cls._mlc = MLCLocal(working_dir=MLCIntegrationTest.WORKSPACE_DIR)
        cls._mlc.new_experiment(
            experiment_name=MLCIntegrationTest.EXPERIMENT_NAME,
            experiment_configuration=config_file,
            evaluation_script=ev_script,
            preevaluation_script=preev_script)
        cls._mlc.open_experiment(
            experiment_name=MLCIntegrationTest.EXPERIMENT_NAME)

        for generation_params in MLCIntegrationTest.GENERATIONS:
            if isinstance(generation_params, int):
                cls._mlc.go(experiment_name=MLCIntegrationTest.EXPERIMENT_NAME,
                            to_generation=generation_params)

            elif isinstance(generation_params, list):
                cls._mlc.go(experiment_name=MLCIntegrationTest.EXPERIMENT_NAME,
                            from_generation=generation_params[0],
                            to_generation=generation_params[1])

            else:
                raise Exception(
                    "Integration test, bad value for generations param")

        # List with individuals data
        cls._indivs = []
        cls._populate_indiv_dict()

        cls._pops = []
        cls._populate_pop_dict()
Ejemplo n.º 3
0
def main():
    # MATLAB random numbers, used in integration tests
    RandomManager.load_random_values(
        "./tests/integration_tests/matlab_randoms.txt")

    # load configuration
    config = initialize_config()

    # set logger
    log_mode = config.get('LOGGING', 'logmode')
    set_logger(log_mode)

    simulation = Simulation()
    mlc = Application(simulation)
    mlc.go(to_generation=3, display_best=False)
    raw_input("Press enter to continue...")
Ejemplo n.º 4
0
    def setUp(self):
        set_logger("testing")

        # Load randoms from file
        random_file = './mlc/unit_matlab_randoms.txt'
        RandomManager.clear_random_values()
        RandomManager.load_random_values(random_file)

        config = Config.get_instance()
        config.read(
            os.path.join(mlc_config_path.get_test_path(),
                         'mlc/individual/configuration.ini'))

        self._individual_l0 = Individual("(root (cos 5.046))")
        self._individual_l1 = Individual(
            "(root (log (sin (exp (tanh 3.6284)))))")
        self._individual_l2 = Individual(
            "(root (cos (* (+ (* -1.912 -9.178) (cos S0)) 3.113)))")
        self._individual_l3 = Individual(
            "(root (log (/ (* (sin 4.37) (- -8.815 -3.902)) (log (+ 2.025 -8.685)))))"
        )
        self._individual_l4 = Individual("(root S0)")
Ejemplo n.º 5
0
 def _load_random_values(self):
     RandomManager.clear_random_values()
     RandomManager.load_random_values(MLCWorkspaceTest.FILE_WITH_RANDOMS)