Пример #1
0
        public MEL__Algorithm(
            MEL__Operator_Settings <T> operator_settings,
            MEL__Evaluation_Settings <T> evaluation_settings,
            MEL__Parent_Selection_Method <T> parent_selection_method
            )
        {
            this.operator_settings       = operator_settings;
            this.evaluation_settings     = evaluation_settings;
            this.parent_selection_method = parent_selection_method;

            this.state = new MEL__State <T>(
                evaluation_settings.feature_1_subdivisions,
                evaluation_settings.feature_2_subdivisions
                );
        }
Пример #2
0
        public static void Run_Experiment <T>(
            string experiment_name,
            List <int> random_seeds, // implies number of repetitions...
            MEL__Operator_Settings <T> operator_settings,
            MEL__Evaluation_Settings <T> eval_settings,
            MEL__Parent_Selection_Method <T> selection_method,
            int initial_population,
            int total_num_iterations,
            List <int> iterations_for_feature_tables_csv,
            List <int> iterations_for_feature_tables_png,
            List <int> iterations_for_data_logging,
            List <int> iterations_for_console_logging
            )
            where T : MEL__Individual
        {
            // prepare paths etc...
            string general_output_folder = Path.Combine(
                Directory.GetCurrentDirectory(),
                "output"
                );

            if (IO_Utilities.Folder_Exists(general_output_folder) == false)
            {
                // create the general output folder
                IO_Utilities.CreateFolder(general_output_folder);
            }
            string this_experiment__output_folder = Path.Combine(
                general_output_folder,
                experiment_name + "___" + DateTime.UtcNow.Ticks.ToString()
                );

            if (IO_Utilities.Folder_Exists(this_experiment__output_folder) == false)
            {
                // create this experiment's folder
                IO_Utilities.CreateFolder(this_experiment__output_folder);
            }

            string data_logging_file_path = Path.Combine(
                this_experiment__output_folder,
                experiment_name + "_data.csv"
                );

            if (IO_Utilities.File_Exists(data_logging_file_path) == false)
            {
                IO_Utilities.Create_File(data_logging_file_path, false, false);
            }

            // create and save the data header...
            string data_header = Map_Elites__Data_Header();

            IO_Utilities.Append_To_File(data_logging_file_path, data_header);

            MEL__Algorithm <T> map_elites = new MEL__Algorithm <T>(
                operator_settings,
                eval_settings,
                selection_method
                );

            Save_Experiment_Settings(
                this_experiment__output_folder,
                experiment_name,
                map_elites
                );

            foreach (var random_seed in random_seeds)
            {
                // initialize the random numbers generator...
                Random randomness_provider = new Random(random_seed);

                map_elites = new MEL__Algorithm <T>(
                    operator_settings,
                    eval_settings,
                    selection_method
                    );

                // generate the initial population
                map_elites.Generate_Initial_Population(randomness_provider, initial_population);

                // save the data at this stage, before any operation...
                Save_Feature_Tables_CSV(
                    this_experiment__output_folder,
                    random_seed,
                    0,
                    map_elites
                    );
                Save_Feature_Tables_PNG(
                    this_experiment__output_folder: this_experiment__output_folder,
                    random_seed: random_seed,
                    current_iteration: 0,
                    map_elites: map_elites,
                    min_fitness: 0.0,
                    max_fitness: 1.0
                    );
                string data_row = Map_Elites__Data_Row(random_seed, 0, map_elites);
                IO_Utilities.Append_To_File(data_logging_file_path, data_row);

                Console_Log(experiment_name, random_seed, 0);

                for (int current_iteration = 1; current_iteration <= total_num_iterations; current_iteration++)
                {
                    // advance algorithm
                    map_elites.Select_And_Mutate_Individual(randomness_provider);

                    // perhaps, save data
                    if (iterations_for_feature_tables_csv.Contains(current_iteration))
                    {
                        Save_Feature_Tables_CSV(
                            this_experiment__output_folder,
                            random_seed,
                            current_iteration,
                            map_elites
                            );
                    }
                    if (iterations_for_feature_tables_png.Contains(current_iteration))
                    {
                        Save_Feature_Tables_PNG(
                            this_experiment__output_folder: this_experiment__output_folder,
                            random_seed: random_seed,
                            current_iteration: current_iteration,
                            map_elites: map_elites,
                            min_fitness: 0.0,
                            max_fitness: 1.0
                            );
                    }
                    if (iterations_for_data_logging.Contains(current_iteration))
                    {
                        data_row = Map_Elites__Data_Row(random_seed, current_iteration, map_elites);
                        IO_Utilities.Append_To_File(data_logging_file_path, data_row);
                    }
                    if (iterations_for_console_logging.Contains(current_iteration))
                    {
                        Console_Log(experiment_name, random_seed, current_iteration);
                    }
                }
            }
        }