Skip to content

Commit

Permalink
Added an additional string to the observer called settings that is ou…
Browse files Browse the repository at this point in the history
…put to *.info files and can be used by the post-processing.
  • Loading branch information
ttusar authored and nikohansen committed Dec 31, 2024
1 parent 6820fd2 commit 2f14c8a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/coco_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ struct coco_observer_s {
char *result_folder; /**< @brief Name of the result folder. */
char *algorithm_name; /**< @brief Name of the algorithm to be used in logger output. */
char *algorithm_info; /**< @brief Additional information on the algorithm to be used in logger output. */
char *settings; /**< @brief Additional settings to be used in logger output. */
size_t number_target_triggers;
/**< @brief The number of targets between each 10**i and 10**(i+1). */
double log_target_precision; /**< @brief The minimal precision used for logarithmic targets. */
Expand Down
18 changes: 15 additions & 3 deletions src/coco_observer.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ static void coco_observer_evaluations_free(coco_observer_evaluations_t *evaluati
* @brief Allocates memory for a coco_observer_t instance.
*/
static coco_observer_t *coco_observer_allocate(
const char *result_folder, const char *observer_name, const char *algorithm_name, const char *algorithm_info,
const char *result_folder, const char *observer_name, const char *algorithm_name, const char *algorithm_info, const char *settings,
const size_t number_target_triggers, const double log_target_precision, const double lin_target_precision,
const size_t number_evaluation_triggers, const char *base_evaluation_triggers, const int precision_x,
const int precision_f, const int precision_g, const int log_discrete_as_int) {
Expand All @@ -440,6 +440,7 @@ static coco_observer_t *coco_observer_allocate(
observer->observer_name = coco_strdup(observer_name);
observer->algorithm_name = coco_strdup(algorithm_name);
observer->algorithm_info = coco_strdup(algorithm_info);
observer->settings = coco_strdup(settings);
observer->number_target_triggers = number_target_triggers;
observer->log_target_precision = log_target_precision;
observer->lin_target_precision = lin_target_precision;
Expand Down Expand Up @@ -468,6 +469,8 @@ void coco_observer_free(coco_observer_t *observer) {
coco_free_memory(observer->result_folder);
if (observer->algorithm_name != NULL)
coco_free_memory(observer->algorithm_name);
if (observer->settings != NULL)
coco_free_memory(observer->settings);
if (observer->algorithm_info != NULL)
coco_free_memory(observer->algorithm_info);

Expand Down Expand Up @@ -530,6 +533,8 @@ void coco_observer_free(coco_observer_t *observer) {
* - "algorithm_info: STRING" stores the description of the algorithm. If it
* contains spaces, it must be surrounded by double quotes. The default value is
* "" (no description).
* - "settings: STRING" stores a string with settings to be used by the post-
* processing. The default value is "" (no settings).
* - "number_target_triggers: VALUE" defines the number of targets between each
* 10**i and 10**(i+1) (equally spaced in the logarithmic scale) that trigger
* logging. The default value is 10.
Expand Down Expand Up @@ -565,7 +570,7 @@ void coco_observer_free(coco_observer_t *observer) {
coco_observer_t *coco_observer(const char *observer_name, const char *observer_options) {

coco_observer_t *observer;
char *path, *outer_folder, *result_folder, *algorithm_name, *algorithm_info;
char *path, *outer_folder, *result_folder, *algorithm_name, *algorithm_info, *settings;
int precision_x, precision_f, precision_g, log_discrete_as_int;

size_t number_target_triggers;
Expand All @@ -582,6 +587,7 @@ coco_observer_t *coco_observer(const char *observer_name, const char *observer_o
"result_folder",
"algorithm_name",
"algorithm_info",
"settings",
"number_target_triggers",
"log_target_precision",
"lin_target_precision",
Expand All @@ -605,6 +611,7 @@ coco_observer_t *coco_observer(const char *observer_name, const char *observer_o
result_folder = coco_allocate_string(COCO_PATH_MAX + 1);
algorithm_name = coco_allocate_string(COCO_PATH_MAX + 1);
algorithm_info = coco_allocate_string(5 * COCO_PATH_MAX);
settings = coco_allocate_string(5 * COCO_PATH_MAX);

if (coco_options_read_string(observer_options, "outer_folder", outer_folder) == 0) {
strcpy(outer_folder, "exdata");
Expand All @@ -630,6 +637,10 @@ coco_observer_t *coco_observer(const char *observer_name, const char *observer_o
strcpy(algorithm_info, "");
}

if (coco_options_read_string(observer_options, "settings", settings) == 0) {
strcpy(settings, "");
}

number_target_triggers = 100;
if (coco_options_read_size_t(observer_options, "number_target_triggers", &number_target_triggers) != 0) {
if (number_target_triggers < 0) {
Expand Down Expand Up @@ -716,13 +727,14 @@ coco_observer_t *coco_observer(const char *observer_name, const char *observer_o
}

observer =
coco_observer_allocate(path, observer_name, algorithm_name, algorithm_info, number_target_triggers,
coco_observer_allocate(path, observer_name, algorithm_name, algorithm_info, settings, number_target_triggers,
log_target_precision, lin_target_precision, number_evaluation_triggers,
base_evaluation_triggers, precision_x, precision_f, precision_g, log_discrete_as_int);

coco_free_memory(path);
coco_free_memory(algorithm_name);
coco_free_memory(algorithm_info);
coco_free_memory(settings);
coco_free_memory(base_evaluation_triggers);

/* Here each observer must have an entry - a call to a specific function that
Expand Down
7 changes: 4 additions & 3 deletions src/logger_bbob.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,12 @@ static void logger_bbob_open_info_file(logger_bbob_data_t *logger, const char *f
fprintf(*info_file, "\n");

fprintf(*info_file,
"suite = '%s', funcId = %lu, DIM = %lu, Precision = %.3e, algId = '%s', coco_version = '%s', logger = "
"'%s', data_format = '%s'\n",
"suite = '%s', funcId = %lu, DIM = %lu, Precision = %.3e, "
"algId = '%s', coco_version = '%s', logger = '%s', "
"data_format = '%s', settings = '%s'\n",
suite_name, (unsigned long)logger->function, (unsigned long)logger->number_of_variables, pow(10, -8),
observer->algorithm_name, coco_version, observer->observer_name,
logger_bbob_data_format);
logger_bbob_data_format, observer->settings);
fprintf(*info_file, "%% %s\n", observer->algorithm_info);
/* data_file_path does not have the extension */
fprintf(*info_file, "%s.dat", data_file_path);
Expand Down
5 changes: 3 additions & 2 deletions src/logger_biobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,10 @@ static logger_biobj_indicator_t *logger_biobj_indicator(const logger_biobj_data_
/* Output algorithm name */
assert(problem->suite);
fprintf(indicator->info_file,
"suite = '%s', algorithm = '%s', indicator = '%s', folder = '%s', coco_version = '%s'\n%% %s",
"suite = '%s', algorithm = '%s', indicator = '%s', folder = '%s', coco_version = '%s', "
"settings = '%s' \n%% %s",
problem->suite->suite_name, observer->algorithm_name, indicator_name, problem->problem_type, coco_version,
observer->algorithm_info);
observer->settings, observer->algorithm_info);
if (logger->log_nondom_mode == LOG_NONDOM_READ)
fprintf(indicator->info_file, " (reconstructed)");
}
Expand Down

0 comments on commit 2f14c8a

Please sign in to comment.