/** * @brief Creates the transformation. */ static coco_problem_t *transform_vars_affine(coco_problem_t *inner_problem, const double *M, const double *b, const size_t number_of_variables) { /* * TODO: * - Calculate new smallest/largest values of interest? * - Resize bounds vectors if input and output dimensions do not match */ coco_problem_t *problem; transform_vars_affine_data_t *data; size_t entries_in_M; entries_in_M = inner_problem->number_of_variables * number_of_variables; data = (transform_vars_affine_data_t *) coco_allocate_memory(sizeof(*data)); data->M = coco_duplicate_vector(M, entries_in_M); data->b = coco_duplicate_vector(b, inner_problem->number_of_variables); data->x = coco_allocate_vector(inner_problem->number_of_variables); problem = coco_problem_transformed_allocate(inner_problem, data, transform_vars_affine_free, "transform_vars_affine"); problem->evaluate_function = transform_vars_affine_evaluate; if (coco_problem_best_parameter_not_zero(inner_problem)) { coco_debug("transform_vars_affine(): 'best_parameter' not updated, set to NAN"); coco_vector_set_to_nan(inner_problem->best_parameter, inner_problem->number_of_variables); } return problem; }
/** * The archive always contains the two extreme solutions */ coco_archive_t *coco_archive(const char *suite_name, const size_t function, const size_t dimension, const size_t instance) { coco_archive_t *archive = coco_archive_allocate(); int output_precision = 15; coco_suite_t *suite; char *suite_instance = coco_strdupf("instances: %lu", (unsigned long) instance); char *suite_options = coco_strdupf("dimensions: %lu function_indices: %lu", (unsigned long) dimension, (unsigned long) function); coco_problem_t *problem; char *text; int update; suite = coco_suite(suite_name, suite_instance, suite_options); if (suite == NULL) { coco_error("coco_archive(): cannot create suite '%s'", suite_name); return NULL; /* Never reached */ } problem = coco_suite_get_next_problem(suite, NULL); if (problem == NULL) { coco_error("coco_archive(): cannot create problem f%02lu_i%02lu_d%02lu in suite '%s'", (unsigned long) function, (unsigned long) instance, (unsigned long) dimension, suite_name); return NULL; /* Never reached */ } /* Store the ideal and nadir points */ archive->ideal = coco_duplicate_vector(problem->best_value, 2); archive->nadir = coco_duplicate_vector(problem->nadir_value, 2); /* Add the extreme points to the archive */ text = coco_strdupf("0\t%.*e\t%.*e\n", output_precision, archive->nadir[0], output_precision, archive->ideal[1]); update = coco_archive_add_solution(archive, archive->nadir[0], archive->ideal[1], text); coco_free_memory(text); assert(update == 1); text = coco_strdupf("0\t%.*e\t%.*e\n", output_precision, archive->ideal[0], output_precision, archive->nadir[1]); update = coco_archive_add_solution(archive, archive->ideal[0], archive->nadir[1], text); coco_free_memory(text); assert(update == 1); archive->extreme1 = archive->tree->head; archive->extreme2 = archive->tree->tail; assert(archive->extreme1 != archive->extreme2); coco_free_memory(suite_instance); coco_free_memory(suite_options); coco_suite_free(suite); return archive; }
/* * Perform an affine transformation of the variable vector: * * x |-> Mx + b * * The matrix M is stored in row-major format. */ static coco_problem_t *f_transform_vars_affine(coco_problem_t *inner_problem, const double *M, const double *b, const size_t number_of_variables) { coco_problem_t *self; transform_vars_affine_data_t *data; size_t entries_in_M; entries_in_M = inner_problem->number_of_variables * number_of_variables; data = coco_allocate_memory(sizeof(*data)); data->M = coco_duplicate_vector(M, entries_in_M); data->b = coco_duplicate_vector(b, inner_problem->number_of_variables); data->x = coco_allocate_vector(inner_problem->number_of_variables); self = coco_transformed_allocate(inner_problem, data, transform_vars_affine_free); self->evaluate_function = transform_vars_affine_evaluate; return self; }
/** * @brief Creates the transformation. */ static coco_problem_t *transform_vars_z_hat(coco_problem_t *inner_problem, const double *xopt) { transform_vars_z_hat_data_t *data; coco_problem_t *problem; data = (transform_vars_z_hat_data_t *) coco_allocate_memory(sizeof(*data)); data->xopt = coco_duplicate_vector(xopt, inner_problem->number_of_variables); data->z = coco_allocate_vector(inner_problem->number_of_variables); problem = coco_problem_transformed_allocate(inner_problem, data, transform_vars_z_hat_free, "transform_vars_z_hat"); problem->evaluate_function = transform_vars_z_hat_evaluate; return problem; }
/** * @brief Creates the transformation. */ static coco_problem_t *transform_vars_z_hat(coco_problem_t *inner_problem, const double *xopt) { transform_vars_z_hat_data_t *data; coco_problem_t *problem; data = (transform_vars_z_hat_data_t *) coco_allocate_memory(sizeof(*data)); data->xopt = coco_duplicate_vector(xopt, inner_problem->number_of_variables); data->z = coco_allocate_vector(inner_problem->number_of_variables); problem = coco_problem_transformed_allocate(inner_problem, data, transform_vars_z_hat_free, "transform_vars_z_hat"); problem->evaluate_function = transform_vars_z_hat_evaluate; /* TODO: When should this warning be output? coco_warning("transform_vars_z_hat(): 'best_parameter' not updated"); */ return problem; }
/* * Shift all variables of ${inner_problem} by ${offset}. */ static coco_problem_t *f_transform_vars_shift(coco_problem_t *inner_problem, const double *offset, const int shift_bounds) { transform_vars_shift_data_t *data; coco_problem_t *self; if (shift_bounds) coco_error("shift_bounds not implemented."); data = coco_allocate_memory(sizeof(*data)); data->offset = coco_duplicate_vector(offset, inner_problem->number_of_variables); data->shifted_x = coco_allocate_vector(inner_problem->number_of_variables); self = coco_transformed_allocate(inner_problem, data, transform_vars_shift_free); self->evaluate_function = transform_vars_shift_evaluate; return self; }
/** * @brief Creates the transformation. */ static coco_problem_t *transform_vars_shift(coco_problem_t *inner_problem, const double *offset, const int shift_bounds) { transform_vars_shift_data_t *data; coco_problem_t *problem; size_t i; if (shift_bounds) coco_error("shift_bounds not implemented."); data = (transform_vars_shift_data_t *) coco_allocate_memory(sizeof(*data)); data->offset = coco_duplicate_vector(offset, inner_problem->number_of_variables); data->shifted_x = coco_allocate_vector(inner_problem->number_of_variables); problem = coco_problem_transformed_allocate(inner_problem, data, transform_vars_shift_free, "transform_vars_shift"); problem->evaluate_function = transform_vars_shift_evaluate; /* Compute best parameter */ for (i = 0; i < problem->number_of_variables; i++) { problem->best_parameter[i] += data->offset[i]; } return problem; }