本文整理汇总了C++中coco_free_memory函数的典型用法代码示例。如果您正苦于以下问题:C++ coco_free_memory函数的具体用法?C++ coco_free_memory怎么用?C++ coco_free_memory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了coco_free_memory函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: suite_biobj_get_best_value
/**
* @brief Returns the best known value for indicator_name matching the given key if the key is found, and
* throws a coco_error otherwise.
*/
static double suite_biobj_get_best_value(const char *indicator_name, const char *key) {
size_t i, count;
double best_value = 0;
char *curr_key;
if (strcmp(indicator_name, "hyp") == 0) {
curr_key = coco_allocate_string(COCO_PATH_MAX);
count = sizeof(suite_biobj_best_values_hyp) / sizeof(char *);
for (i = 0; i < count; i++) {
sscanf(suite_biobj_best_values_hyp[i], "%s %lf", curr_key, &best_value);
if (strcmp(curr_key, key) == 0) {
coco_free_memory(curr_key);
return best_value;
}
}
coco_free_memory(curr_key);
coco_warning("suite_biobj_get_best_value(): best value of %s could not be found; set to 1.0", key);
return 1.0;
} else {
coco_error("suite_biobj_get_best_value(): indicator %s not supported", indicator_name);
return 0; /* Never reached */
}
coco_error("suite_biobj_get_best_value(): unexpected exception");
return 0; /* Never reached */
}
开发者ID:Ulfgard,项目名称:coco,代码行数:34,代码来源:suite_biobj.c
示例2: my_optimizer
/**
* A random search optimizer.
*/
void my_optimizer(coco_problem_t *problem) {
const size_t budget = 2;
coco_random_state_t *rng = coco_random_new(0xdeadbeef);
const double *lbounds = coco_problem_get_smallest_values_of_interest(problem);
const double *ubounds = coco_problem_get_largest_values_of_interest(problem);
size_t dimension = coco_problem_get_dimension(problem);
size_t number_of_objectives = coco_problem_get_number_of_objectives(problem);
double *x = coco_allocate_vector(dimension);
double *y = coco_allocate_vector(number_of_objectives);
double range;
size_t i, j;
for (i = 0; i < budget; ++i) {
for (j = 0; j < dimension; ++j) {
range = ubounds[j] - lbounds[j];
x[j] = lbounds[j] + coco_random_uniform(rng) * range;
}
coco_evaluate_function(problem, x, y);
}
coco_random_free(rng);
coco_free_memory(x);
coco_free_memory(y);
}
开发者ID:ShaulSalomon,项目名称:coco,代码行数:31,代码来源:test_biobj.c
示例3: logger_biobj_indicator_free
/**
* @brief Frees the memory of the given indicator.
*/
static void logger_biobj_indicator_free(void *stuff) {
logger_biobj_indicator_t *indicator;
assert(stuff != NULL);
indicator = (logger_biobj_indicator_t *) stuff;
if (indicator->name != NULL) {
coco_free_memory(indicator->name);
indicator->name = NULL;
}
if (indicator->dat_file != NULL) {
fclose(indicator->dat_file);
indicator->dat_file = NULL;
}
if (indicator->tdat_file != NULL) {
fclose(indicator->tdat_file);
indicator->tdat_file = NULL;
}
if (indicator->info_file != NULL) {
fclose(indicator->info_file);
indicator->info_file = NULL;
}
coco_free_memory(stuff);
}
开发者ID:asmaatamna,项目名称:coco,代码行数:33,代码来源:logger_biobj.c
示例4: coco_problem_free
void coco_problem_free(coco_problem_t *problem) {
assert(problem != NULL);
if (problem->problem_free_function != NULL) {
problem->problem_free_function(problem);
} else {
/* Best guess at freeing all relevant structures */
if (problem->smallest_values_of_interest != NULL)
coco_free_memory(problem->smallest_values_of_interest);
if (problem->largest_values_of_interest != NULL)
coco_free_memory(problem->largest_values_of_interest);
if (problem->best_parameter != NULL)
coco_free_memory(problem->best_parameter);
if (problem->best_value != NULL)
coco_free_memory(problem->best_value);
if (problem->nadir_value != NULL)
coco_free_memory(problem->nadir_value);
if (problem->problem_name != NULL)
coco_free_memory(problem->problem_name);
if (problem->problem_id != NULL)
coco_free_memory(problem->problem_id);
if (problem->problem_type != NULL)
coco_free_memory(problem->problem_type);
if (problem->data != NULL)
coco_free_memory(problem->data);
problem->smallest_values_of_interest = NULL;
problem->largest_values_of_interest = NULL;
problem->best_parameter = NULL;
problem->best_value = NULL;
problem->nadir_value = NULL;
problem->suite = NULL;
problem->data = NULL;
coco_free_memory(problem);
}
}
开发者ID:numbbo,项目名称:coco,代码行数:34,代码来源:coco_problem.c
示例5: coco_problem_free
void coco_problem_free(coco_problem_t *self) {
assert(self != NULL);
if (self->free_problem != NULL) {
self->free_problem(self);
} else {
/* Best guess at freeing all relevant structures */
if (self->smallest_values_of_interest != NULL)
coco_free_memory(self->smallest_values_of_interest);
if (self->largest_values_of_interest != NULL)
coco_free_memory(self->largest_values_of_interest);
if (self->best_parameter != NULL)
coco_free_memory(self->best_parameter);
if (self->best_value != NULL)
coco_free_memory(self->best_value);
if (self->nadir_value != NULL)
coco_free_memory(self->nadir_value);
if (self->problem_name != NULL)
coco_free_memory(self->problem_name);
if (self->problem_id != NULL)
coco_free_memory(self->problem_id);
if (self->problem_type != NULL)
coco_free_memory(self->problem_type);
if (self->data != NULL)
coco_free_memory(self->data);
self->smallest_values_of_interest = NULL;
self->largest_values_of_interest = NULL;
self->best_parameter = NULL;
self->best_value = NULL;
self->nadir_value = NULL;
self->data = NULL;
coco_free_memory(self);
}
}
开发者ID:anneauger,项目名称:coco,代码行数:33,代码来源:coco_problem.c
示例6: logger_biobj_node_free
/**
* @brief Frees the data of the given logger_biobj_avl_item_t.
*/
static void logger_biobj_node_free(logger_biobj_avl_item_t *item, void *userdata) {
coco_free_memory(item->x);
coco_free_memory(item->y);
coco_free_memory(item);
(void) userdata; /* To silence the compiler */
}
开发者ID:asmaatamna,项目名称:coco,代码行数:10,代码来源:logger_biobj.c
示例7: coco_problem_get_dimension
/**
* @brief Allocates a problem constructed by stacking two COCO problems.
*
* This is particularly useful for generating multi-objective problems, e.g. a bi-objective problem from two
* single-objective problems. The stacked problem must behave like a normal COCO problem accepting the same
* input. The region of interest in the decision space is defined by parameters smallest_values_of_interest
* and largest_values_of_interest, which are two arrays of size equal to the dimensionality of both problems.
*
* @note Regions of interest in the decision space must either agree or at least one of them must be NULL.
* @note Best parameter becomes somewhat meaningless, but the nadir value make sense now.
*/
static coco_problem_t *coco_problem_stacked_allocate(coco_problem_t *problem1,
coco_problem_t *problem2,
const double *smallest_values_of_interest,
const double *largest_values_of_interest) {
const size_t number_of_variables = coco_problem_get_dimension(problem1);
const size_t number_of_objectives = coco_problem_get_number_of_objectives(problem1)
+ coco_problem_get_number_of_objectives(problem2);
const size_t number_of_constraints = coco_problem_get_number_of_constraints(problem1)
+ coco_problem_get_number_of_constraints(problem2);
size_t i;
char *s;
coco_problem_stacked_data_t *data;
coco_problem_t *problem; /* the new coco problem */
assert(coco_problem_get_dimension(problem1) == coco_problem_get_dimension(problem2));
problem = coco_problem_allocate(number_of_variables, number_of_objectives, number_of_constraints);
s = coco_strconcat(coco_problem_get_id(problem1), "__");
problem->problem_id = coco_strconcat(s, coco_problem_get_id(problem2));
coco_free_memory(s);
s = coco_strconcat(coco_problem_get_name(problem1), " + ");
problem->problem_name = coco_strconcat(s, coco_problem_get_name(problem2));
coco_free_memory(s);
problem->evaluate_function = coco_problem_stacked_evaluate_function;
if (number_of_constraints > 0)
problem->evaluate_constraint = coco_problem_stacked_evaluate_constraint;
assert(smallest_values_of_interest);
assert(largest_values_of_interest);
for (i = 0; i < number_of_variables; ++i) {
problem->smallest_values_of_interest[i] = smallest_values_of_interest[i];
problem->largest_values_of_interest[i] = largest_values_of_interest[i];
}
if (problem->best_parameter) /* logger_bbob doesn't work then anymore */
coco_free_memory(problem->best_parameter);
problem->best_parameter = NULL;
/* Compute the ideal and nadir values */
assert(problem->best_value);
assert(problem->nadir_value);
problem->best_value[0] = problem1->best_value[0];
problem->best_value[1] = problem2->best_value[0];
coco_evaluate_function(problem1, problem2->best_parameter, &problem->nadir_value[0]);
coco_evaluate_function(problem2, problem1->best_parameter, &problem->nadir_value[1]);
/* setup data holder */
data = (coco_problem_stacked_data_t *) coco_allocate_memory(sizeof(*data));
data->problem1 = problem1;
data->problem2 = problem2;
problem->data = data;
problem->problem_free_function = coco_problem_stacked_free;
return problem;
}
开发者ID:numbbo,项目名称:coco,代码行数:70,代码来源:coco_problem.c
示例8: coco_allocate_vector
static coco_problem_t *f_weierstrass_bbob_problem_allocate(const size_t function,
const size_t dimension,
const size_t instance,
const long rseed,
const char *problem_id_template,
const char *problem_name_template) {
double *xopt, fopt;
coco_problem_t *problem = NULL;
size_t i, j, k;
double *M = coco_allocate_vector(dimension * dimension);
double *b = coco_allocate_vector(dimension);
double *current_row, **rot1, **rot2;
const double condition = 100.0;
const double penalty_factor = 10.0 / (double) dimension;
xopt = coco_allocate_vector(dimension);
fopt = bbob2009_compute_fopt(function, instance);
bbob2009_compute_xopt(xopt, rseed, dimension);
rot1 = bbob2009_allocate_matrix(dimension, dimension);
rot2 = bbob2009_allocate_matrix(dimension, dimension);
bbob2009_compute_rotation(rot1, rseed + 1000000, dimension);
bbob2009_compute_rotation(rot2, rseed, dimension);
for (i = 0; i < dimension; ++i) {
b[i] = 0.0;
current_row = M + i * dimension;
for (j = 0; j < dimension; ++j) {
current_row[j] = 0.0;
for (k = 0; k < dimension; ++k) {
const double base = 1.0 / sqrt(condition);
const double exponent = 1.0 * (int) k / ((double) (long) dimension - 1.0);
current_row[j] += rot1[i][k] * pow(base, exponent) * rot2[k][j];
}
}
}
problem = f_weierstrass_allocate(dimension);
problem = f_transform_obj_shift(problem, fopt);
problem = f_transform_vars_affine(problem, M, b, dimension);
problem = f_transform_vars_oscillate(problem);
bbob2009_copy_rotation_matrix(rot1, M, b, dimension);
problem = f_transform_vars_affine(problem, M, b, dimension);
problem = f_transform_vars_shift(problem, xopt, 0);
problem = f_transform_obj_penalize(problem, penalty_factor);
bbob2009_free_matrix(rot1, dimension);
bbob2009_free_matrix(rot2, dimension);
coco_problem_set_id(problem, problem_id_template, function, instance, dimension);
coco_problem_set_name(problem, problem_name_template, function, instance, dimension);
coco_problem_set_type(problem, "4-multi-modal");
coco_free_memory(M);
coco_free_memory(b);
coco_free_memory(xopt);
return problem;
}
开发者ID:anneauger,项目名称:coco,代码行数:58,代码来源:f_weierstrass.c
示例9: bbob2009_free_matrix
static void bbob2009_free_matrix(double **matrix, const size_t n) {
size_t i;
for (i = 0; i < n; ++i) {
if (matrix[i] != NULL) {
coco_free_memory(matrix[i]);
matrix[i] = NULL;
}
}
coco_free_memory(matrix);
}
开发者ID:belkhir-nacim,项目名称:numbbo,代码行数:10,代码来源:suite_bbob2009_legacy_code.c
示例10: coco_archive_free
void coco_archive_free(coco_archive_t *archive) {
assert(archive != NULL);
avl_tree_destruct(archive->tree);
coco_free_memory(archive->ideal);
coco_free_memory(archive->nadir);
coco_free_memory(archive);
}
开发者ID:brockho,项目名称:numbbo,代码行数:10,代码来源:coco_archive.c
示例11: logger_bbob2009_free
/**
* Also serves as a finalize run method so. Must be called at the end
* of Each run to correctly fill the index file
*
* TODO: make sure it is called at the end of each run or move the
* writing into files to another function
*/
static void logger_bbob2009_free(void *stuff) {
/* TODO: do all the "non simply freeing" stuff in another function
* that can have problem as input
*/
logger_bbob2009_t *data = stuff;
if (bbob2009_logger_verbosity > 2 && data && data->number_of_evaluations > 0) {
printf("best f=%e after %ld fevals (done observing)\n", data->best_fvalue, data->number_of_evaluations);
}
if (data->alg_name != NULL) {
coco_free_memory((void*) data->alg_name);
data->alg_name = NULL;
}
if (data->path != NULL) {
coco_free_memory(data->path);
data->path = NULL;
}
if (data->index_file != NULL) {
fprintf(data->index_file, ":%ld|%.1e", data->number_of_evaluations,
data->best_fvalue - data->optimal_fvalue);
fclose(data->index_file);
data->index_file = NULL;
}
if (data->fdata_file != NULL) {
fclose(data->fdata_file);
data->fdata_file = NULL;
}
if (data->tdata_file != NULL) {
/* TODO: make sure it handles restarts well. i.e., it writes
* at the end of a single run, not all the runs on a given
* instance. Maybe start with forcing it to generate a new
* "instance" of problem for each restart in the beginning
*/
if (!data->written_last_eval) {
logger_bbob2009_write_data(data->tdata_file, data->number_of_evaluations, data->last_fvalue,
data->best_fvalue, data->optimal_fvalue, data->best_solution, data->number_of_variables);
}
fclose(data->tdata_file);
data->tdata_file = NULL;
}
if (data->rdata_file != NULL) {
fclose(data->rdata_file);
data->rdata_file = NULL;
}
if (data->best_solution != NULL) {
coco_free_memory(data->best_solution);
data->best_solution = NULL;
}
bbob2009_logger_is_open = 0;
}
开发者ID:oaelhara,项目名称:numbbo,代码行数:60,代码来源:logger_bbob2009.c
示例12: coco_archive_allocate
/**
* 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;
}
开发者ID:numbbo,项目名称:coco,代码行数:55,代码来源:coco_archive.c
示例13: f_lunacek_bi_rastrigin_free
/**
* @brief Frees the Lunacek bi-Rastrigin data object.
*/
static void f_lunacek_bi_rastrigin_free(coco_problem_t *problem) {
f_lunacek_bi_rastrigin_data_t *data;
data = (f_lunacek_bi_rastrigin_data_t *) problem->data;
coco_free_memory(data->x_hat);
coco_free_memory(data->z);
coco_free_memory(data->xopt);
bbob2009_free_matrix(data->rot1, problem->number_of_variables);
bbob2009_free_matrix(data->rot2, problem->number_of_variables);
/* Let the generic free problem code deal with all of the
* coco_problem_t fields.
*/
problem->problem_free_function = NULL;
coco_problem_free(problem);
}
开发者ID:Ulfgard,项目名称:coco,代码行数:18,代码来源:f_lunacek_bi_rastrigin.c
示例14: coco_problem_allocate_from_scalars
static coco_problem_t *f_weierstrass_allocate(const size_t number_of_variables) {
f_weierstrass_data_t *data;
size_t i;
double *non_unique_best_value;
coco_problem_t *problem = coco_problem_allocate_from_scalars("Weierstrass function",
f_weierstrass_evaluate, NULL, number_of_variables, -5.0, 5.0, NAN);
coco_problem_set_id(problem, "%s_d%02lu", "weierstrass", number_of_variables);
data = coco_allocate_memory(sizeof(*data));
data->f0 = 0.0;
for (i = 0; i < WEIERSTRASS_SUMMANDS; ++i) {
data->ak[i] = pow(0.5, (double) i);
data->bk[i] = pow(3., (double) i);
data->f0 += data->ak[i] * cos(2 * coco_pi * data->bk[i] * 0.5);
}
problem->data = data;
/* Compute best solution */
non_unique_best_value = coco_allocate_vector(number_of_variables);
for (i = 0; i < number_of_variables; i++)
non_unique_best_value[i] = 0.0;
f_weierstrass_evaluate(problem, non_unique_best_value, problem->best_value);
coco_free_memory(non_unique_best_value);
return problem;
}
开发者ID:anneauger,项目名称:coco,代码行数:26,代码来源:f_weierstrass.c
示例15: coco_allocate_vector
/**
* @brief Creates the BBOB Rastrigin problem.
*/
static coco_problem_t *f_rastrigin_bbob_problem_allocate(const size_t function,
const size_t dimension,
const size_t instance,
const long rseed,
const char *problem_id_template,
const char *problem_name_template) {
double *xopt, fopt;
coco_problem_t *problem = NULL;
xopt = coco_allocate_vector(dimension);
fopt = bbob2009_compute_fopt(function, instance);
bbob2009_compute_xopt(xopt, rseed, dimension);
problem = f_rastrigin_allocate(dimension);
problem = transform_vars_conditioning(problem, 10.0);
problem = transform_vars_asymmetric(problem, 0.2);
problem = transform_vars_oscillate(problem);
problem = transform_vars_shift(problem, xopt, 0);
problem = transform_obj_shift(problem, fopt);
coco_problem_set_id(problem, problem_id_template, function, instance, dimension);
coco_problem_set_name(problem, problem_name_template, function, instance, dimension);
coco_problem_set_type(problem, "1-separable");
coco_free_memory(xopt);
return problem;
}
开发者ID:Ulfgard,项目名称:coco,代码行数:31,代码来源:f_rastrigin.c
示例16: transformed_free_problem
static void transformed_free_problem(coco_problem_t *self) {
coco_transformed_data_t *data;
assert(self != NULL);
assert(self->data != NULL);
data = self->data;
assert(data->inner_problem != NULL);
if (data->inner_problem != NULL) {
coco_problem_free(data->inner_problem);
data->inner_problem = NULL;
}
if (data->data != NULL) {
if (data->free_data != NULL) {
data->free_data(data->data);
data->free_data = NULL;
}
coco_free_memory(data->data);
data->data = NULL;
}
/* Let the generic free problem code deal with the rest of the
* fields. For this we clear the free_problem function pointer and
* recall the generic function.
*/
self->free_problem = NULL;
coco_problem_free(self);
}
开发者ID:belkhir-nacim,项目名称:numbbo,代码行数:27,代码来源:coco_problem.c
示例17: coco_stacked_problem_free
static void coco_stacked_problem_free(coco_problem_t *self) {
coco_stacked_problem_data_t *data;
assert(self != NULL);
assert(self->data != NULL);
data = self->data;
if (data->problem1 != NULL) {
coco_problem_free(data->problem1);
data->problem1 = NULL;
}
if (data->problem2 != NULL) {
coco_problem_free(data->problem2);
data->problem2 = NULL;
}
if (data->data != NULL) {
if (data->free_data != NULL) {
data->free_data(data->data);
data->free_data = NULL;
}
coco_free_memory(data->data);
data->data = NULL;
}
/* Let the generic free problem code deal with the rest of the
* fields. For this we clear the free_problem function pointer and
* recall the generic function.
*/
self->free_problem = NULL;
coco_problem_free(self);
}
开发者ID:belkhir-nacim,项目名称:numbbo,代码行数:30,代码来源:coco_problem.c
示例18: coco_strdup
/**
* @brief Allocates a transformed problem that wraps the inner_problem.
*
* By default all methods will dispatch to the inner_problem. A prefix is prepended to the problem name
* in order to reflect the transformation somewhere.
*/
static coco_problem_t *coco_problem_transformed_allocate(coco_problem_t *inner_problem,
void *user_data,
coco_data_free_function_t data_free_function,
const char *name_prefix) {
coco_problem_transformed_data_t *problem;
coco_problem_t *inner_copy;
char *old_name = coco_strdup(inner_problem->problem_name);
problem = (coco_problem_transformed_data_t *) coco_allocate_memory(sizeof(*problem));
problem->inner_problem = inner_problem;
problem->data = user_data;
problem->data_free_function = data_free_function;
inner_copy = coco_problem_duplicate(inner_problem);
inner_copy->evaluate_function = coco_problem_transformed_evaluate_function;
inner_copy->evaluate_constraint = coco_problem_transformed_evaluate_constraint;
inner_copy->recommend_solution = coco_problem_transformed_recommend_solution;
inner_copy->problem_free_function = coco_problem_transformed_free;
inner_copy->data = problem;
coco_problem_set_name(inner_copy, "%s(%s)", name_prefix, old_name);
coco_free_memory(old_name);
return inner_copy;
}
开发者ID:numbbo,项目名称:coco,代码行数:31,代码来源:coco_problem.c
示例19: f_gallagher_free
static void f_gallagher_free(coco_problem_t *self) {
f_gallagher_data_t *data;
data = self->data;
coco_free_memory(data->xopt);
coco_free_memory(data->peak_values);
bbob2009_free_matrix(data->rotation, self->number_of_variables);
bbob2009_free_matrix(data->x_local, self->number_of_variables);
bbob2009_free_matrix(data->arr_scales, data->number_of_peaks);
self->free_problem = NULL;
coco_problem_free(self);
if (gallagher_peaks != NULL) {
coco_free_memory(gallagher_peaks);
gallagher_peaks = NULL;
}
}
开发者ID:tobiaswagner,项目名称:coco,代码行数:16,代码来源:f_gallagher.c
示例20: coco_problem_get_number_of_objectives
/*
* Class: CocoJNI
* Method: cocoEvaluateConstraint
* Signature: (J[D)[D
*/
JNIEXPORT jdoubleArray JNICALL Java_org_moeaframework_problem_BBOB2016_CocoJNI_cocoEvaluateConstraint
(JNIEnv *jenv, jclass interface_cls, jlong jproblem_pointer, jdoubleArray jx) {
coco_problem_t *problem = NULL;
double *y = NULL;
double *x = NULL;
int number_of_objectives;
jdoubleArray jy;
/* This test is both to prevent warning because interface_cls was not used and to check for exceptions */
if (interface_cls == NULL) {
jclass Exception = (*jenv)->FindClass(jenv, "java/lang/Exception");
(*jenv)->ThrowNew(jenv, Exception, "Exception in cocoEvaluateConstraint\n");
}
problem = (coco_problem_t *) jproblem_pointer;
number_of_objectives = (int) coco_problem_get_number_of_objectives(problem);
/* Call coco_evaluate_constraint */
x = (*jenv)->GetDoubleArrayElements(jenv, jx, NULL);
y = coco_allocate_vector(number_of_objectives);
coco_evaluate_constraint(problem, x, y);
/* Prepare the return value */
jy = (*jenv)->NewDoubleArray(jenv, number_of_objectives);
(*jenv)->SetDoubleArrayRegion(jenv, jy, 0, number_of_objectives, y);
/* Free resources */
coco_free_memory(y);
(*jenv)->ReleaseDoubleArrayElements(jenv, jx, x, JNI_ABORT);
return jy;
}
开发者ID:MOEAFramework,项目名称:MOEAFramework,代码行数:37,代码来源:org_moeaframework_problem_BBOB2016_CocoJNI.c
注:本文中的coco_free_memory函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论