/* TODO: * * o here needs to go the docstring for this function * * o parse options that look like "folder:foo; verbose:bar" (use coco_strfind and/or sscanf and/or ??) * Ideally, valid options should be * "my_folder_name verbose : 3", * "folder: my_folder_name", * "verbose : 4 folder:another_folder" * "folder:yet_another verbose: -2 " * This could be done with a coco_get_option(options, name, format, pointer) * function with code snippets like (approximately) logger->folder = coco_allocate_memory(sizeof(char) * (strlen(options) + 1)); if (!coco_options_read(options, "folder", " %s", logger->folder)) sscanf(options, " %s", logger->folder); coco_options_read(options, "verbose", " %i", &(logger->verbose)); with # caveat: "folder: name; " might fail, use spaces for separations int coco_options_read(const char *options, const char *name, const char *format, void *pointer) { long i1 = coco_strfind(options, name); long i2; if (i1 < 0) return 0; i2 = i1 + coco_strfind(&options[i1], ":") + 1; if (i2 <= i1) return 0; return sscanf(&options[i2], format, pointer); } * */ static coco_problem_t *bbob2009_observer(coco_problem_t *problem, const char *options) { if (problem == NULL) return problem; /* TODO: " */ coco_create_path(options); problem = bbob2009_logger(problem, options); return problem; }
/** * Generates the different files and folder needed by the logger to store the * data if theses don't already exist */ static void logger_bbob2009_initialize(logger_bbob2009_t *data, coco_problem_t *inner_problem) { /* Creates/opens the data and index files */ char dataFile_path[COCO_PATH_MAX] = { 0 }; /* relative path to the .dat file from where the .info file is */ char folder_path[COCO_PATH_MAX] = { 0 }; char tmpc_funId[3]; /* serves to extract the function id as a char *. There should be a better way of doing this! */ char tmpc_dim[3]; /* serves to extract the dimension as a char *. There should be a better way of doing this! */ char indexFile_prefix[10] = "bbobexp"; /* TODO (minor): make the prefix bbobexp a parameter that the user can modify */ assert(data != NULL); assert(inner_problem != NULL); assert(inner_problem->problem_id != NULL); sprintf(tmpc_funId, "%d", coco_problem_get_suite_dep_function_id(inner_problem)); sprintf(tmpc_dim, "%lu", (unsigned long) inner_problem->number_of_variables); /* prepare paths and names */ strncpy(dataFile_path, "data_f", COCO_PATH_MAX); strncat(dataFile_path, tmpc_funId, COCO_PATH_MAX - strlen(dataFile_path) - 1); coco_join_path(folder_path, sizeof(folder_path), data->path, dataFile_path, NULL); coco_create_path(folder_path); strncat(dataFile_path, "/bbobexp_f", COCO_PATH_MAX - strlen(dataFile_path) - 1); strncat(dataFile_path, tmpc_funId, COCO_PATH_MAX - strlen(dataFile_path) - 1); strncat(dataFile_path, "_DIM", COCO_PATH_MAX - strlen(dataFile_path) - 1); strncat(dataFile_path, tmpc_dim, COCO_PATH_MAX - strlen(dataFile_path) - 1); /* index/info file */ logger_bbob2009_openIndexFile(data, data->path, indexFile_prefix, tmpc_funId, dataFile_path); fprintf(data->index_file, ", %ld", coco_problem_get_suite_dep_instance_id(inner_problem)); /* data files */ /* TODO: definitely improvable but works for now */ strncat(dataFile_path, "_i", COCO_PATH_MAX - strlen(dataFile_path) - 1); strncat(dataFile_path, bbob2009_infoFile_firstInstance_char, COCO_PATH_MAX - strlen(dataFile_path) - 1); logger_bbob2009_open_dataFile(&(data->fdata_file), data->path, dataFile_path, ".dat"); fprintf(data->fdata_file, bbob2009_file_header_str, data->optimal_fvalue); logger_bbob2009_open_dataFile(&(data->tdata_file), data->path, dataFile_path, ".tdat"); fprintf(data->tdata_file, bbob2009_file_header_str, data->optimal_fvalue); logger_bbob2009_open_dataFile(&(data->rdata_file), data->path, dataFile_path, ".rdat"); fprintf(data->rdata_file, bbob2009_file_header_str, data->optimal_fvalue); /* TODO: manage duplicate filenames by either using numbers or raising an error */ /* The coco_create_unique_path() function is available now! */ data->is_initialized = 1; }