Skip to content
Extraits de code Groupes Projets
Valider 7967ec5f rédigé par Jonathan CROUZET's avatar Jonathan CROUZET
Parcourir les fichiers

Removed useless functions in experiment. Right parameters are set for debug.

parent f0a14ab4
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -10,14 +10,13 @@ ...@@ -10,14 +10,13 @@
#include <time.h> #include <time.h>
#include "coco/coco.h" #include "coco/coco.h"
/* #include "ibea/population.h" */
#include "ibea/ibea.h" #include "ibea/ibea.h"
/** /**
* The maximal budget for evaluations done by an optimization algorithm equals dimension * BUDGET_MULTIPLIER. * 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. * 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. * The maximal number of independent restarts allowed for an algorithm that restarts itself.
...@@ -50,25 +49,10 @@ static void evaluate_function(const double *x, double *y) { ...@@ -50,25 +49,10 @@ static void evaluate_function(const double *x, double *y) {
} }
/* Declarations of all functions implemented in this file (so that their order is not important): */ /* Declarations of all functions implemented in this file (so that their order is not important): */
void example_experiment(const char *suite_name, void experiment(const char *suite_name,
const char *observer_name, const char *observer_name,
coco_random_state_t *random_generator); 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);
/* Structure and functions needed for timing the experiment */ /* Structure and functions needed for timing the experiment */
typedef struct { typedef struct {
size_t number_of_dimensions; size_t number_of_dimensions;
...@@ -97,7 +81,7 @@ int main(void) { ...@@ -97,7 +81,7 @@ int main(void) {
printf("Running the example experiment... (might take time, be patient)\n"); printf("Running the example experiment... (might take time, be patient)\n");
fflush(stdout); 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 /* Uncomment the line below to run the same example experiment on the bbob suite
example_experiment("bbob", "bbob", random_generator); */ example_experiment("bbob", "bbob", random_generator); */
...@@ -120,7 +104,7 @@ int main(void) { ...@@ -120,7 +104,7 @@ int main(void) {
* bi-objective observer). * bi-objective observer).
* @param random_generator The random number generator. * @param random_generator The random number generator.
*/ */
void example_experiment(const char *suite_name, void experiment(const char *suite_name,
const char *observer_name, const char *observer_name,
coco_random_state_t *random_generator) { coco_random_state_t *random_generator) {
...@@ -159,7 +143,7 @@ void example_experiment(const char *suite_name, ...@@ -159,7 +143,7 @@ void example_experiment(const char *suite_name,
break; break;
/* Call the optimization algorithm for the remaining number of evaluations */ /* Call the optimization algorithm for the remaining number of evaluations */
my_random_search(evaluate_function, ibea(evaluate_function,
dimension, dimension,
coco_problem_get_number_of_objectives(PROBLEM), coco_problem_get_number_of_objectives(PROBLEM),
coco_problem_get_smallest_values_of_interest(PROBLEM), coco_problem_get_smallest_values_of_interest(PROBLEM),
...@@ -189,126 +173,6 @@ void example_experiment(const char *suite_name, ...@@ -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. * Allocates memory for the timing_data_t object and initializes it.
*/ */
......
...@@ -15,7 +15,7 @@ void ibea(evaluate_function_t evaluate, ...@@ -15,7 +15,7 @@ void ibea(evaluate_function_t evaluate,
{ {
/* Parameters */ /* Parameters */
int n_individus = 20; /* number of individus per generations */ 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 */ int mu = 10; /* number of tournament */
double eta = 20; /* polynomiale mutation degree */ double eta = 20; /* polynomiale mutation degree */
double p_combination = 1; double p_combination = 1;
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter