示例#1
0
    def test_go_and_get_individuals(self):
        # load random values for the simulation
        self._load_random_values()

        # Execute a simulation
        mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR)
        mlc.new_experiment("test_go_and_check", MLCWorkspaceTest.ORIGINAL_CONFIGURATION)
        mlc.open_experiment("test_go_and_check")
        mlc.go("test_go_and_check", 2)

        # obtain individuals
        individuals = mlc.get_individuals("test_go_and_check")

        # check number of individuals
        self.assertEqual(len(individuals), 11)

        # TODO: Check individual values
        for indiv_id, indiv_data in individuals.items():
            self.assertIsInstance(indiv_data, IndividualData)

        # Test Update Individual Cost in all generations
        mlc.update_individual_cost("test_go_and_check", 2, 1000, 1001)

        indiv_data = mlc.get_individuals("test_go_and_check")[2]
        self.assertEqual(indiv_data.get_appearances(), 2)
        self.assertEqual(indiv_data.get_cost_history(), {1: [(1000.0, 1001)], 2: [(1000.0, 1001)]})
        mlc.close_experiment("test_go_and_check")
        mlc.delete_experiment("test_go_and_check")
示例#2
0
 def test_open_and_close_experiment(self):
     mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR)
     mlc.open_experiment(MLCWorkspaceTest.ORIGINAL_EXPERIMENT)
     mlc.close_experiment(MLCWorkspaceTest.ORIGINAL_EXPERIMENT)
     try:
         mlc.get_experiment_configuration(MLCWorkspaceTest.ORIGINAL_EXPERIMENT)
         self.assertTrue(False, "Configuration from a closed experiment should not be obtained")
     except MLC.api.mlc.ClosedExperimentException:
         self.assertTrue(True)
示例#3
0
    def test_get_info_empty_simulation(self):
        mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR)
        mlc.open_experiment(MLCWorkspaceTest.ORIGINAL_EXPERIMENT)
        info = mlc.get_experiment_info(MLCWorkspaceTest.ORIGINAL_EXPERIMENT)

        self._assert_key_value(info, "name", MLCWorkspaceTest.ORIGINAL_EXPERIMENT)
        self._assert_key_value(info, "generations", 0)
        self._assert_key_value(info, "individuals", 0)
        self._assert_key_value(info, "individuals_per_generation", 10)

        mlc.close_experiment(MLCWorkspaceTest.ORIGINAL_EXPERIMENT)
        mlc.delete_experiment(MLCWorkspaceTest.ORIGINAL_EXPERIMENT)
示例#4
0
    def test_obtain_configuration(self):
        mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR)
        mlc.open_experiment(MLCWorkspaceTest.ORIGINAL_EXPERIMENT)
        configuration = mlc.get_experiment_configuration(MLCWorkspaceTest.ORIGINAL_EXPERIMENT)
        mlc.close_experiment(MLCWorkspaceTest.ORIGINAL_EXPERIMENT)

        # check configuration structure
        self.assertIsInstance(configuration, dict)
        self.assertTrue(configuration.has_key("BEHAVIOUR"))
        self.assertIsInstance(configuration["BEHAVIOUR"], dict)
        self.assertTrue(configuration["BEHAVIOUR"].has_key("showeveryitbest"))
        self.assertEqual(configuration["BEHAVIOUR"]["showeveryitbest"], "true")
示例#5
0
    def test_create_experiment_and_obtain_configuration(self):
        mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR)
        mlc.new_experiment(MLCWorkspaceTest.NEW_EXPERIMENT,
                           MLCWorkspaceTest.NEW_CONFIGURATION)
        mlc.open_experiment(MLCWorkspaceTest.NEW_EXPERIMENT)
        configuration = mlc.get_experiment_configuration(MLCWorkspaceTest.NEW_EXPERIMENT)
        mlc.close_experiment(MLCWorkspaceTest.NEW_EXPERIMENT)
        mlc.delete_experiment(MLCWorkspaceTest.NEW_EXPERIMENT)

        # check configuration structure
        self.assertIsInstance(configuration, dict)
        self.assertTrue(configuration.has_key("PARAMS"))
        self.assertIsInstance(configuration["PARAMS"], dict)
        self.assertTrue(configuration["PARAMS"].has_key("test_param"))
        self.assertEqual(configuration["PARAMS"]["test_param"], "test_value")
示例#6
0
    def test_go_and_check_simulation_info(self):
        # load random values for the simulation
        self._load_random_values()

        # Execute a simulation
        mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR)
        mlc.new_experiment("test_go_and_check", MLCWorkspaceTest.ORIGINAL_CONFIGURATION)
        mlc.open_experiment("test_go_and_check")
        mlc.go("test_go_and_check", 2)

        # check simulation info
        info = mlc.get_experiment_info("test_go_and_check")
        self._assert_key_value(info, "name", "test_go_and_check")
        self._assert_key_value(info, "generations", 2)
        self._assert_key_value(info, "individuals", 11)
        self._assert_key_value(info, "individuals_per_generation", 10)

        mlc.close_experiment("test_go_and_check")
        mlc.delete_experiment("test_go_and_check")
示例#7
0
    def test_set_configuration(self):
        mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR)

        # check original configuration
        mlc.new_experiment(MLCWorkspaceTest.NEW_EXPERIMENT, MLCWorkspaceTest.NEW_CONFIGURATION)
        mlc.open_experiment(MLCWorkspaceTest.NEW_EXPERIMENT)
        original_config = mlc.get_experiment_configuration(MLCWorkspaceTest.NEW_EXPERIMENT)
        self.assertEqual(original_config["PARAMS"]["test_param"], "test_value")
        # chage paramenter value
        mlc.set_experiment_configuration(MLCWorkspaceTest.NEW_EXPERIMENT, {"PARAMS": {"test_param": "new_value"}})
        mlc.close_experiment(MLCWorkspaceTest.NEW_EXPERIMENT)

        # reload mlc_workspace
        mlc_reloaded = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR)
        mlc_reloaded.open_experiment(MLCWorkspaceTest.NEW_EXPERIMENT)
        original_config = mlc_reloaded.get_experiment_configuration(MLCWorkspaceTest.NEW_EXPERIMENT)
        self.assertEqual(original_config["PARAMS"]["test_param"], "new_value")
        mlc_reloaded.close_experiment(MLCWorkspaceTest.NEW_EXPERIMENT)

        # set specific parameter
        mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR)
        mlc.open_experiment(MLCWorkspaceTest.NEW_EXPERIMENT)
        mlc.set_experiment_configuration_parameter(MLCWorkspaceTest.NEW_EXPERIMENT,
                                                   "another_section", "another_param",
                                                   "another_value")
        mlc.close_experiment(MLCWorkspaceTest.NEW_EXPERIMENT)

        # reload mlc_workspace
        mlc_reloaded = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR)
        mlc_reloaded.open_experiment(MLCWorkspaceTest.NEW_EXPERIMENT)
        config = mlc_reloaded.get_experiment_configuration(MLCWorkspaceTest.NEW_EXPERIMENT)
        mlc_reloaded.close_experiment(MLCWorkspaceTest.NEW_EXPERIMENT)
        mlc.delete_experiment(MLCWorkspaceTest.NEW_EXPERIMENT)

        self.assertEqual(config["PARAMS"]["test_param"], "new_value")
        self.assertIn("another_section", config)
        self.assertIn("another_param", config["another_section"])
        self.assertEqual(config["another_section"]["another_param"], "another_value")