code-experiments/build/c/example_experiment.c
/**
 * A random search algorithm that can be used for single- as well as multi-objective optimization. The
 * problem's initial solution is evaluated first.
 *
 * @param evaluate_func The function used to evaluate the objective function.
 * @param evaluate_cons The function used to evaluate the constraints.
 * @param dimension The number of variables.
 * @param number_of_objectives The number of objectives.
 * @param number_of_constraints The number of constraints.
 * @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 number_of_integer_variables The number of integer variables (if > 0, all integer variables come
 * before any continuous ones).
 * @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.
 */
A random search algorithm that can be used for single- as well as multi-objective optimization. The
problem's initial solution is evaluated first.

@param evaluate_func The function used to evaluate the objective function.
@param evaluate_cons The function used to evaluate the constraints.
@param dimension The number of variables.
@param number_of_objectives The number of objectives.
@param number_of_constraints The number of constraints.
@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 number_of_integer_variables The number of integer variables (if > 0, all integer variables come
before any continuous ones).
@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.
A random search algorithm that can be used for single - as well as multi - objective optimization . The problem ' s initial solution is evaluated first . @param evaluate_func The function used to evaluate the objective function . @param evaluate_cons The function used to evaluate the constraints . @param dimension The number of variables . @param number_of_objectives The number of objectives . @param number_of_constraints The number of constraints . @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 number_of_integer_variables The number of integer variables ( if > 0 all integer variables come before any continuous ones ) . @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_func,
                      evaluate_function_t evaluate_cons,
                      const size_t dimension,
                      const size_t number_of_objectives,
                      const size_t number_of_constraints,
                      const double *lower_bounds,
                      const double *upper_bounds,
                      const size_t number_of_integer_variables,
                      const size_t max_budget,
                      coco_random_state_t *random_generator) {
  double *x = coco_allocate_vector(dimension);
  double *functions_values = coco_allocate_vector(number_of_objectives);
  double *constraints_values = NULL;
  double range;
  size_t i, j;
  if (number_of_constraints > 0 )
    constraints_values = coco_allocate_vector(number_of_constraints);
  coco_problem_get_initial_solution(PROBLEM, x);
  evaluate_func(x, functions_values);
  for (i = 1; i < max_budget; ++i) {
    for (j = 0; j < dimension; ++j) {
      range = upper_bounds[j] - lower_bounds[j];
      x[j] = lower_bounds[j] + coco_random_uniform(random_generator) * range;
      if (j < number_of_integer_variables)
        x[j] = floor(x[j] + 0.5);
    }
    if (number_of_constraints > 0 )
      evaluate_cons(x, constraints_values);
    evaluate_func(x, functions_values);
  }
  coco_free_memory(x);
  coco_free_memory(functions_values);
  if (number_of_constraints > 0 )
    coco_free_memory(constraints_values);
}
void my_random_search ( evaluate_function_t evaluate_func , evaluate_function_t evaluate_cons , const size_t dimension , const size_t number_of_objectives , const size_t number_of_constraints , const double * lower_bounds , const double * upper_bounds , const size_t number_of_integer_variables , const size_t max_budget , coco_random_state_t * random_generator ) { double * x = coco_allocate_vector ( dimension ) ; double * functions_values = coco_allocate_vector ( number_of_objectives ) ; double * constraints_values = NULL ; double range ; size_t i , j ; if ( number_of_constraints > 0 ) constraints_values = coco_allocate_vector ( number_of_constraints ) ; coco_problem_get_initial_solution ( PROBLEM , x ) ; evaluate_func ( x , functions_values ) ; for ( i = 1 ; i < max_budget ; ++ i ) { for ( j = 0 ; j < dimension ; ++ j ) { range = upper_bounds [ j ] - lower_bounds [ j ] ; x [ j ] = lower_bounds [ j ] + coco_random_uniform ( random_generator ) * range ; if ( j < number_of_integer_variables ) x [ j ] = floor ( x [ j ] + 0.5 ) ; } if ( number_of_constraints > 0 ) evaluate_cons ( x , constraints_values ) ; evaluate_func ( x , functions_values ) ; } coco_free_memory ( x ) ; coco_free_memory ( functions_values ) ; if ( number_of_constraints > 0 ) coco_free_memory ( constraints_values ) ; }
A random search algorithm that can be used for single- as well as multi-objective optimization.
A random search algorithm that can be used for single - as well as multi - objective optimization .
/* Construct x as a random point between the lower and upper bounds */ /* Round the variable if integer */ /* Evaluate COCO's constraints function if problem is constrained */ /* Call COCO's evaluate function where all the logging is performed */