diff --git a/src/experiment.c b/src/experiment.c index 3c7711b71590d41d36f6e1ec96a294d2f31bc40a..efa6e80b4ccaa1e31b1c7e96861b0dcc8ba40e5b 100644 --- a/src/experiment.c +++ b/src/experiment.c @@ -10,14 +10,13 @@ #include <time.h> #include "coco/coco.h" -/* #include "ibea/population.h" */ #include "ibea/ibea.h" /** * The maximal budget for evaluations done by an optimization algorithm equals dimension * BUDGET_MULTIPLIER. * Increase the budget multiplier value gradually to see how it affects the runtime. */ -static const size_t BUDGET_MULTIPLIER = 2; +static const size_t BUDGET_MULTIPLIER = 40; /** * The maximal number of independent restarts allowed for an algorithm that restarts itself. @@ -50,24 +49,9 @@ static void evaluate_function(const double *x, double *y) { } /* Declarations of all functions implemented in this file (so that their order is not important): */ -void example_experiment(const char *suite_name, - const char *observer_name, - coco_random_state_t *random_generator); - -void my_random_search(evaluate_function_t evaluate, - const size_t dimension, - const size_t number_of_objectives, - const double *lower_bounds, - const double *upper_bounds, - const size_t max_budget, - coco_random_state_t *random_generator); - -void my_grid_search(evaluate_function_t evaluate, - const size_t dimension, - const size_t number_of_objectives, - const double *lower_bounds, - const double *upper_bounds, - const size_t max_budget); +void experiment(const char *suite_name, + const char *observer_name, + coco_random_state_t *random_generator); /* Structure and functions needed for timing the experiment */ typedef struct { @@ -97,7 +81,7 @@ int main(void) { printf("Running the example experiment... (might take time, be patient)\n"); fflush(stdout); - example_experiment("bbob-biobj", "bbob-biobj", random_generator); + experiment("bbob-biobj", "bbob-biobj", random_generator); /* Uncomment the line below to run the same example experiment on the bbob suite example_experiment("bbob", "bbob", random_generator); */ @@ -120,9 +104,9 @@ int main(void) { * bi-objective observer). * @param random_generator The random number generator. */ -void example_experiment(const char *suite_name, - const char *observer_name, - coco_random_state_t *random_generator) { +void experiment(const char *suite_name, + const char *observer_name, + coco_random_state_t *random_generator) { size_t run; coco_suite_t *suite; @@ -159,13 +143,13 @@ void example_experiment(const char *suite_name, break; /* Call the optimization algorithm for the remaining number of evaluations */ - my_random_search(evaluate_function, - dimension, - coco_problem_get_number_of_objectives(PROBLEM), - coco_problem_get_smallest_values_of_interest(PROBLEM), - coco_problem_get_largest_values_of_interest(PROBLEM), - (size_t) evaluations_remaining, - random_generator); + ibea(evaluate_function, + dimension, + coco_problem_get_number_of_objectives(PROBLEM), + coco_problem_get_smallest_values_of_interest(PROBLEM), + coco_problem_get_largest_values_of_interest(PROBLEM), + (size_t) evaluations_remaining, + random_generator); /* Break the loop if the algorithm performed no evaluations or an unexpected thing happened */ if (coco_problem_get_evaluations(PROBLEM) == evaluations_done) { @@ -189,126 +173,6 @@ void example_experiment(const char *suite_name, } -/** - * A random search algorithm that can be used for single- as well as multi-objective optimization. - * - * @param evaluate The evaluation function used to evaluate the solutions. - * @param dimension The number of variables. - * @param number_of_objectives The number of objectives. - * @param lower_bounds The lower bounds of the region of interested (a vector containing dimension values). - * @param upper_bounds The upper bounds of the region of interested (a vector containing dimension values). - * @param max_budget The maximal number of evaluations. - * @param random_generator Pointer to a random number generator able to produce uniformly and normally - * distributed random numbers. - */ -void my_random_search(evaluate_function_t evaluate, - const size_t dimension, - const size_t number_of_objectives, - const double *lower_bounds, - const double *upper_bounds, - const size_t max_budget, - coco_random_state_t *random_generator) { - - double *x = coco_allocate_vector(dimension); - double *y = coco_allocate_vector(number_of_objectives); - double range; - size_t i, j; - - for (i = 0; i < max_budget; ++i) { - - /* Construct x as a random point between the lower and upper bounds */ - for (j = 0; j < dimension; ++j) { - range = upper_bounds[j] - lower_bounds[j]; - x[j] = lower_bounds[j] + coco_random_uniform(random_generator) * range; - } - - /* Call the evaluate function to evaluate x on the current problem (this is where all the COCO logging - * is performed) */ - evaluate(x, y); - - } - - coco_free_memory(x); - coco_free_memory(y); -} - -/** - * A grid search optimizer that can be used for single- as well as multi-objective optimization. - * - * @param evaluate The evaluation function used to evaluate the solutions. - * @param dimension The number of variables. - * @param number_of_objectives The number of objectives. - * @param lower_bounds The lower bounds of the region of interested (a vector containing dimension values). - * @param upper_bounds The upper bounds of the region of interested (a vector containing dimension values). - * @param max_budget The maximal number of evaluations. - * - * If max_budget is not enough to cover even the smallest possible grid, only the first max_budget - * nodes of the grid are evaluated. - */ -void my_grid_search(evaluate_function_t evaluate, - const size_t dimension, - const size_t number_of_objectives, - const double *lower_bounds, - const double *upper_bounds, - const size_t max_budget) { - - double *x = coco_allocate_vector(dimension); - double *y = coco_allocate_vector(number_of_objectives); - long *nodes = (long *) coco_allocate_memory(sizeof(long) * dimension); - double *grid_step = coco_allocate_vector(dimension); - size_t i, j; - size_t evaluations = 0; - long max_nodes = (long) floor(pow((double) max_budget, 1.0 / (double) dimension)) - 1; - - /* Take care of the borderline case */ - if (max_nodes < 1) max_nodes = 1; - - /* Initialization */ - for (j = 0; j < dimension; j++) { - nodes[j] = 0; - grid_step[j] = (upper_bounds[j] - lower_bounds[j]) / (double) max_nodes; - } - - while (evaluations < max_budget) { - - /* Construct x and evaluate it */ - for (j = 0; j < dimension; j++) { - x[j] = lower_bounds[j] + grid_step[j] * (double) nodes[j]; - } - - /* Call the evaluate function to evaluate x on the current problem (this is where all the COCO logging - * is performed) */ - evaluate(x, y); - evaluations++; - - /* Inside the grid, move to the next node */ - if (nodes[0] < max_nodes) { - nodes[0]++; - } - - /* At an outside node of the grid, move to the next level */ - else if (max_nodes > 0) { - for (j = 1; j < dimension; j++) { - if (nodes[j] < max_nodes) { - nodes[j]++; - for (i = 0; i < j; i++) - nodes[i] = 0; - break; - } - } - - /* At the end of the grid, exit */ - if ((j == dimension) && (nodes[j - 1] == max_nodes)) - break; - } - } - - coco_free_memory(x); - coco_free_memory(y); - coco_free_memory(nodes); - coco_free_memory(grid_step); -} - /** * Allocates memory for the timing_data_t object and initializes it. */ diff --git a/src/ibea/ibea.cpp b/src/ibea/ibea.cpp index b75f47d6e336023baf3576393f457b94aff20acc..3191a675ca8cf511a99be2695740a4228768a64b 100644 --- a/src/ibea/ibea.cpp +++ b/src/ibea/ibea.cpp @@ -15,7 +15,7 @@ void ibea(evaluate_function_t evaluate, { /* Parameters */ int n_individus = 20; /* number of individus per generations */ - int n_generations = (int) max_budget/n_individus; /* number of generations */ + int n_generations = 2; /* number of generations */ int mu = 10; /* number of tournament */ double eta = 20; /* polynomiale mutation degree */ double p_combination = 1;