code-experiments/build/c/example_experiment.c
/**
 * A simple example of benchmarking random search on a given suite with default instances
 * that can serve also as a timing experiment.
 *
 * @param suite_name Name of the suite (e.g. "bbob" or "bbob-biobj").
 * @param suite_options Options of the suite (e.g. "dimensions: 2,3,5,10,20 instance_indices: 1-5").
 * @param observer_name Name of the observer matching with the chosen suite (e.g. "bbob-biobj"
 * when using the "bbob-biobj-ext" suite).
 * @param observer_options Options of the observer (e.g. "result_folder: folder_name")
 * @param random_generator The random number generator.
 */
A simple example of benchmarking random search on a given suite with default instances
that can serve also as a timing experiment.

@param suite_name Name of the suite .
@param suite_options Options of the suite .
@param observer_name Name of the observer matching with the chosen suite .
@param observer_options Options of the observer
@param random_generator The random number generator.
A simple example of benchmarking random search on a given suite with default instances that can serve also as a timing experiment . @param suite_name Name of the suite . @param suite_options Options of the suite . @param observer_name Name of the observer matching with the chosen suite . @param observer_options Options of the observer @param random_generator The random number generator .
void example_experiment(const char *suite_name,
                        const char *suite_options,
                        const char *observer_name,
                        const char *observer_options,
                        coco_random_state_t *random_generator) {
  size_t run;
  coco_suite_t *suite;
  coco_observer_t *observer;
  timing_data_t *timing_data;
  suite = coco_suite(suite_name, "", suite_options);
  observer = coco_observer(observer_name, observer_options);
  timing_data = timing_data_initialize(suite);
  while ((PROBLEM = coco_suite_get_next_problem(suite, observer)) != NULL) {
    size_t dimension = coco_problem_get_dimension(PROBLEM);
    for (run = 1; run <= 1 + INDEPENDENT_RESTARTS; run++) {
      long evaluations_done = (long) (coco_problem_get_evaluations(PROBLEM) +
            coco_problem_get_evaluations_constraints(PROBLEM));
      long evaluations_remaining = (long) (dimension * BUDGET_MULTIPLIER) - evaluations_done;
      if ((coco_problem_final_target_hit(PROBLEM) &&
           coco_problem_get_number_of_constraints(PROBLEM) == 0)
           || (evaluations_remaining <= 0))
        break;
      my_random_search(evaluate_function,
                       evaluate_constraint,
                       dimension,
                       coco_problem_get_number_of_objectives(PROBLEM),
                       coco_problem_get_number_of_constraints(PROBLEM),
                       coco_problem_get_smallest_values_of_interest(PROBLEM),
                       coco_problem_get_largest_values_of_interest(PROBLEM),
                       coco_problem_get_number_of_integer_variables(PROBLEM),
                       (size_t) evaluations_remaining,
                       random_generator);
      if (coco_problem_get_evaluations(PROBLEM) == evaluations_done) {
        printf("WARNING: Budget has not been exhausted (%lu/%lu evaluations done)!\n",
        		(unsigned long) evaluations_done, (unsigned long) dimension * BUDGET_MULTIPLIER);
        break;
      }
      else if (coco_problem_get_evaluations(PROBLEM) < evaluations_done)
        coco_error("Something unexpected happened - function evaluations were decreased!");
    }
    timing_data_time_problem(timing_data, PROBLEM);
  }
  timing_data_finalize(timing_data);
  coco_observer_free(observer);
  coco_suite_free(suite);
}
void example_experiment ( const char * suite_name , const char * suite_options , const char * observer_name , const char * observer_options , coco_random_state_t * random_generator ) { size_t run ; coco_suite_t * suite ; coco_observer_t * observer ; timing_data_t * timing_data ; suite = coco_suite ( suite_name , " " , suite_options ) ; observer = coco_observer ( observer_name , observer_options ) ; timing_data = timing_data_initialize ( suite ) ; while ( ( PROBLEM = coco_suite_get_next_problem ( suite , observer ) ) != NULL ) { size_t dimension = coco_problem_get_dimension ( PROBLEM ) ; for ( run = 1 ; run <= 1 + INDEPENDENT_RESTARTS ; run ++ ) { long evaluations_done = ( long ) ( coco_problem_get_evaluations ( PROBLEM ) + coco_problem_get_evaluations_constraints ( PROBLEM ) ) ; long evaluations_remaining = ( long ) ( dimension * BUDGET_MULTIPLIER ) - evaluations_done ; if ( ( coco_problem_final_target_hit ( PROBLEM ) && coco_problem_get_number_of_constraints ( PROBLEM ) == 0 ) || ( evaluations_remaining <= 0 ) ) break ; my_random_search ( evaluate_function , evaluate_constraint , dimension , coco_problem_get_number_of_objectives ( PROBLEM ) , coco_problem_get_number_of_constraints ( PROBLEM ) , coco_problem_get_smallest_values_of_interest ( PROBLEM ) , coco_problem_get_largest_values_of_interest ( PROBLEM ) , coco_problem_get_number_of_integer_variables ( PROBLEM ) , ( size_t ) evaluations_remaining , random_generator ) ; if ( coco_problem_get_evaluations ( PROBLEM ) == evaluations_done ) { printf ( " \n " , ( unsigned long ) evaluations_done , ( unsigned long ) dimension * BUDGET_MULTIPLIER ) ; break ; } else if ( coco_problem_get_evaluations ( PROBLEM ) < evaluations_done ) coco_error ( " " ) ; } timing_data_time_problem ( timing_data , PROBLEM ) ; } timing_data_finalize ( timing_data ) ; coco_observer_free ( observer ) ; coco_suite_free ( suite ) ; }
A simple example of benchmarking random search on a given suite with default instances
 that can serve also as a timing experiment.
A simple example of benchmarking random search on a given suite with default instances that can serve also as a timing experiment .
/* Initialize the suite and observer. */ /* Initialize timing */ /* Iterate over all problems in the suite */ /* Run the algorithm at least once */ /* Break the loop if the target was hit or there are no more remaining evaluations */ /* Call the optimization algorithm for the remaining number of evaluations */ /* Break the loop if the algorithm performed no evaluations or an unexpected thing happened */ /* Keep track of time */ /* Output and finalize the timing data */