coco_problem.c File Reference

Definitions of functions regarding COCO problems. More...

#include <float.h>
#include "coco.h"
#include "coco_internal.h"
#include "coco_utilities.c"

Functions

void bbob_problem_best_parameter_print (const coco_problem_t *problem)
 
void bbob_biobj_problem_best_parameter_print (const coco_problem_t *problem)
 
Methods regarding the basic COCO problem
void coco_evaluate_function (coco_problem_t *problem, const double *x, double *y)
 Evaluates the problem function in point x and save the result in y. More...
 
void coco_evaluate_constraint (coco_problem_t *problem, const double *x, double *y)
 Evaluates the problem constraints in point x and save the result in y. More...
 
static void bbob_evaluate_gradient (coco_problem_t *problem, const double *x, double *y)
 
void coco_recommend_solution (coco_problem_t *problem, const double *x)
 Recommends a solution as the current best guesses to the problem. Not implemented yet. More...
 
static coco_problem_tcoco_problem_allocate (const size_t number_of_variables, const size_t number_of_objectives, const size_t number_of_constraints)
 Allocates a new coco_problem_t for the given number of variables, number of objectives and number of constraints. More...
 
static coco_problem_tcoco_problem_duplicate (const coco_problem_t *other)
 Creates a duplicate of the 'other' problem for all fields except for data, which points to NULL. More...
 
static coco_problem_tcoco_problem_allocate_from_scalars (const char *problem_name, coco_evaluate_function_t evaluate_function, coco_problem_free_function_t problem_free_function, const size_t number_of_variables, const double smallest_value_of_interest, const double largest_value_of_interest, const double best_parameter)
 Allocates a problem using scalar values for smallest_value_of_interest, largest_value_of_interest and best_parameter. Assumes all variables are continuous. More...
 
void coco_problem_free (coco_problem_t *problem)
 Frees the given problem. More...
 
static int coco_problem_id_is_fine (const char *id,...)
 Checks whether the given string is in the right format to be a problem_id. More...
 
static void coco_problem_set_id (coco_problem_t *problem, const char *id,...)
 Sets the problem_id using formatted printing (as in printf). More...
 
static void coco_problem_set_name (coco_problem_t *problem, const char *name,...)
 Sets the problem_name using formatted printing (as in printf). More...
 
static void coco_problem_set_type (coco_problem_t *problem, const char *type,...)
 Sets the problem_type using formatted printing (as in printf). More...
 
size_t coco_problem_get_evaluations (const coco_problem_t *problem)
 Returns the number of objective function evaluations done on the problem. More...
 
size_t coco_problem_get_evaluations_constraints (const coco_problem_t *problem)
 Returns the number of constraint function evaluations done on the problem. More...
 
static int coco_problem_best_parameter_not_zero (const coco_problem_t *problem)
 Returns 1 if the best parameter is not (close to) zero and 0 otherwise. More...
 
int coco_problem_final_target_hit (const coco_problem_t *problem)
 Returns 1 if the final target was hit, 0 otherwise. More...
 
double coco_problem_get_best_observed_fvalue1 (const coco_problem_t *problem)
 Returns the best observed value for the first objective. More...
 
double coco_problem_get_best_value (const coco_problem_t *problem)
 Returns the optimal function value of the problem. More...
 
double coco_problem_get_final_target_fvalue1 (const coco_problem_t *problem)
 
const char * coco_problem_get_name (const coco_problem_t *problem)
 Returns the name of the problem. More...
 
const char * coco_problem_get_id (const coco_problem_t *problem)
 Returns the ID of the problem. More...
 
const char * coco_problem_get_type (const coco_problem_t *problem)
 Returns the type of the problem. More...
 
size_t coco_problem_get_dimension (const coco_problem_t *problem)
 Returns the number of variables i.e. the dimension of the problem. More...
 
size_t coco_problem_get_number_of_objectives (const coco_problem_t *problem)
 Returns the number of objectives of the problem. More...
 
size_t coco_problem_get_number_of_constraints (const coco_problem_t *problem)
 Returns the number of constraints of the problem. More...
 
const double * coco_problem_get_smallest_values_of_interest (const coco_problem_t *problem)
 Returns a vector of size 'dimension' with lower bounds of the region of interest in the decision space. More...
 
const double * coco_problem_get_largest_values_of_interest (const coco_problem_t *problem)
 Returns a vector of size 'dimension' with upper bounds of the region of interest in the decision space. More...
 
size_t coco_problem_get_number_of_integer_variables (const coco_problem_t *problem)
 Returns the number of integer variables. If > 0, all integer variables come before any continuous ones. More...
 
const double * coco_problem_get_largest_fvalues_of_interest (const coco_problem_t *problem)
 For multi-objective problems, returns a vector of largest values of interest in each objective. Currently, this equals the nadir point. For single-objective problems it raises an error. More...
 
void coco_problem_get_initial_solution (const coco_problem_t *problem, double *initial_solution)
 Returns an initial solution, i.e. a feasible variable setting, to the problem. More...
 
static coco_suite_tcoco_problem_get_suite (const coco_problem_t *problem)
 Evaluates the problem function in point x and save the result in y. More...
 
static void coco_problem_set_suite (coco_problem_t *problem, coco_suite_t *suite)
 Evaluates the problem function in point x and save the result in y. More...
 
size_t coco_problem_get_suite_dep_index (const coco_problem_t *problem)
 Returns the problem_index of the problem in its current suite. More...
 
static size_t coco_problem_get_suite_dep_function (const coco_problem_t *problem)
 Evaluates the problem function in point x and save the result in y. More...
 
static size_t coco_problem_get_suite_dep_instance (const coco_problem_t *problem)
 Evaluates the problem function in point x and save the result in y. More...
 
Methods regarding the transformed COCO problem
static void * coco_problem_transformed_get_data (const coco_problem_t *problem)
 Returns the data of the transformed problem. More...
 
static coco_problem_tcoco_problem_transformed_get_inner_problem (const coco_problem_t *problem)
 Returns the inner problem of the transformed problem. More...
 
static void coco_problem_transformed_evaluate_function (coco_problem_t *problem, const double *x, double *y)
 Calls the coco_evaluate_function function on the inner problem. More...
 
static void coco_problem_transformed_evaluate_constraint (coco_problem_t *problem, const double *x, double *y)
 Calls the coco_evaluate_constraint function on the inner problem. More...
 
static void bbob_problem_transformed_evaluate_gradient (coco_problem_t *problem, const double *x, double *y)
 Returns the data of the transformed problem. More...
 
static void coco_problem_transformed_recommend_solution (coco_problem_t *problem, const double *x)
 Calls the coco_recommend_solution function on the inner problem. More...
 
static void coco_problem_transformed_free_data (coco_problem_t *problem)
 Frees only the data of the transformed problem leaving the inner problem intact. More...
 
static void coco_problem_transformed_free (coco_problem_t *problem)
 Frees the transformed problem. More...
 
static coco_problem_tcoco_problem_transformed_allocate (coco_problem_t *inner_problem, void *user_data, coco_data_free_function_t data_free_function, const char *name_prefix)
 Allocates a transformed problem that wraps the inner_problem. More...
 
Methods regarding the stacked COCO problem
static void coco_problem_stacked_evaluate_function (coco_problem_t *problem, const double *x, double *y)
 Calls the coco_evaluate_function function on the underlying problems. More...
 
static void coco_problem_stacked_evaluate_constraint (coco_problem_t *problem, const double *x, double *y)
 Calls the coco_evaluate_constraint function on the underlying problems. More...
 
static void coco_problem_stacked_free (coco_problem_t *problem)
 Frees the stacked problem. More...
 
static coco_problem_tcoco_problem_stacked_allocate (coco_problem_t *problem1, coco_problem_t *problem2, const double *smallest_values_of_interest, const double *largest_values_of_interest)
 Allocates a problem constructed by stacking two COCO problems. More...
 

Detailed Description

Definitions of functions regarding COCO problems.

Function Documentation

void bbob_biobj_problem_best_parameter_print ( const coco_problem_t problem)
static void bbob_evaluate_gradient ( coco_problem_t problem,
const double *  x,
double *  y 
)
static
Note
Both x and y must point to correctly sized allocated memory regions.
Parameters
problemThe given COCO problem.
xThe decision vector.
yThe gradient of the function evaluated at the point x.
void bbob_problem_best_parameter_print ( const coco_problem_t problem)
static void bbob_problem_transformed_evaluate_gradient ( coco_problem_t problem,
const double *  x,
double *  y 
)
static

Returns the data of the transformed problem.

void coco_evaluate_constraint ( coco_problem_t problem,
const double *  x,
double *  y 
)

Evaluates the problem constraints in point x and save the result in y.

Evaluates the problem constraint.

Note
Both x and y must point to correctly sized allocated memory regions.
Parameters
problemThe given COCO problem.
xThe decision vector.
yThe vector of constraints that is the result of the evaluation.
void coco_evaluate_function ( coco_problem_t problem,
const double *  x,
double *  y 
)

Evaluates the problem function in point x and save the result in y.

Evaluates the problem function, increases the number of evaluations and updates the best observed value and the best observed evaluation number.

Note
Both x and y must point to correctly sized allocated memory regions.
Parameters
problemThe given COCO problem.
xThe decision vector.
yThe objective vector that is the result of the evaluation (in single-objective problems only the first vector item is being set).
static coco_problem_t* coco_problem_allocate ( const size_t  number_of_variables,
const size_t  number_of_objectives,
const size_t  number_of_constraints 
)
static

Allocates a new coco_problem_t for the given number of variables, number of objectives and number of constraints.

static coco_problem_t* coco_problem_allocate_from_scalars ( const char *  problem_name,
coco_evaluate_function_t  evaluate_function,
coco_problem_free_function_t  problem_free_function,
const size_t  number_of_variables,
const double  smallest_value_of_interest,
const double  largest_value_of_interest,
const double  best_parameter 
)
static

Allocates a problem using scalar values for smallest_value_of_interest, largest_value_of_interest and best_parameter. Assumes all variables are continuous.

static int coco_problem_best_parameter_not_zero ( const coco_problem_t problem)
static

Returns 1 if the best parameter is not (close to) zero and 0 otherwise.

static coco_problem_t* coco_problem_duplicate ( const coco_problem_t other)
static

Creates a duplicate of the 'other' problem for all fields except for data, which points to NULL.

int coco_problem_final_target_hit ( const coco_problem_t problem)

Returns 1 if the final target was hit, 0 otherwise.

Note
Can be used to prevent unnecessary burning of CPU time.
void coco_problem_free ( coco_problem_t problem)

Frees the given problem.

double coco_problem_get_best_observed_fvalue1 ( const coco_problem_t problem)

Returns the best observed value for the first objective.

Note
Tentative...
double coco_problem_get_best_value ( const coco_problem_t problem)

Returns the optimal function value of the problem.

size_t coco_problem_get_dimension ( const coco_problem_t problem)

Returns the number of variables i.e. the dimension of the problem.

size_t coco_problem_get_evaluations ( const coco_problem_t problem)

Returns the number of objective function evaluations done on the problem.

size_t coco_problem_get_evaluations_constraints ( const coco_problem_t problem)

Returns the number of constraint function evaluations done on the problem.

double coco_problem_get_final_target_fvalue1 ( const coco_problem_t problem)
Note
This function breaks the black-box property: the returned value is not meant to be used by the optimization algorithm.
const char* coco_problem_get_id ( const coco_problem_t problem)

Returns the ID of the problem.

The ID is guaranteed to contain only characters in the set [a-z0-9_-]. It should therefore be safe to use it to construct filenames or other identifiers.

Each problem ID should be unique within each benchmark suite.

Note
Do not modify the returned string! If you free the problem, the returned pointer becomes invalid. When in doubt, use coco_strdup() on the returned value.
void coco_problem_get_initial_solution ( const coco_problem_t problem,
double *  initial_solution 
)

Returns an initial solution, i.e. a feasible variable setting, to the problem.

Copies problem->initial_solution into initial_solution if not null, otherwise the center of the problem's region of interest is the initial solution. Takes care of rounding the solution in case of integer variables.

Parameters
problemThe given COCO problem.
initial_solutionThe pointer to the initial solution being set by this method.
const double* coco_problem_get_largest_fvalues_of_interest ( const coco_problem_t problem)

For multi-objective problems, returns a vector of largest values of interest in each objective. Currently, this equals the nadir point. For single-objective problems it raises an error.

const double* coco_problem_get_largest_values_of_interest ( const coco_problem_t problem)

Returns a vector of size 'dimension' with upper bounds of the region of interest in the decision space.

const char* coco_problem_get_name ( const coco_problem_t problem)

Returns the name of the problem.

Note
Do not modify the returned string! If you free the problem, the returned pointer becomes invalid. When in doubt, use coco_strdup() on the returned value.
size_t coco_problem_get_number_of_constraints ( const coco_problem_t problem)

Returns the number of constraints of the problem.

size_t coco_problem_get_number_of_integer_variables ( const coco_problem_t problem)

Returns the number of integer variables. If > 0, all integer variables come before any continuous ones.

size_t coco_problem_get_number_of_objectives ( const coco_problem_t problem)

Returns the number of objectives of the problem.

const double* coco_problem_get_smallest_values_of_interest ( const coco_problem_t problem)

Returns a vector of size 'dimension' with lower bounds of the region of interest in the decision space.

static coco_suite_t* coco_problem_get_suite ( const coco_problem_t problem)
static

Evaluates the problem function in point x and save the result in y.

Evaluates the problem function, increases the number of evaluations and updates the best observed value and the best observed evaluation number.

Note
Both x and y must point to correctly sized allocated memory regions.
Parameters
problemThe given COCO problem.
xThe decision vector.
yThe objective vector that is the result of the evaluation (in single-objective problems only the first vector item is being set).
static size_t coco_problem_get_suite_dep_function ( const coco_problem_t problem)
static

Evaluates the problem function in point x and save the result in y.

Evaluates the problem function, increases the number of evaluations and updates the best observed value and the best observed evaluation number.

Note
Both x and y must point to correctly sized allocated memory regions.
Parameters
problemThe given COCO problem.
xThe decision vector.
yThe objective vector that is the result of the evaluation (in single-objective problems only the first vector item is being set).
size_t coco_problem_get_suite_dep_index ( const coco_problem_t problem)

Returns the problem_index of the problem in its current suite.

static size_t coco_problem_get_suite_dep_instance ( const coco_problem_t problem)
static

Evaluates the problem function in point x and save the result in y.

Evaluates the problem function, increases the number of evaluations and updates the best observed value and the best observed evaluation number.

Note
Both x and y must point to correctly sized allocated memory regions.
Parameters
problemThe given COCO problem.
xThe decision vector.
yThe objective vector that is the result of the evaluation (in single-objective problems only the first vector item is being set).
const char* coco_problem_get_type ( const coco_problem_t problem)

Returns the type of the problem.

static int coco_problem_id_is_fine ( const char *  id,
  ... 
)
static

Checks whether the given string is in the right format to be a problem_id.

No non-alphanumeric characters besides '-', '_' and '.' are allowed.

static void coco_problem_set_id ( coco_problem_t problem,
const char *  id,
  ... 
)
static

Sets the problem_id using formatted printing (as in printf).

Takes care of memory (de-)allocation and verifies that the problem_id is in the correct format.

static void coco_problem_set_name ( coco_problem_t problem,
const char *  name,
  ... 
)
static

Sets the problem_name using formatted printing (as in printf).

Takes care of memory (de-)allocation.

static void coco_problem_set_suite ( coco_problem_t problem,
coco_suite_t suite 
)
static

Evaluates the problem function in point x and save the result in y.

Evaluates the problem function, increases the number of evaluations and updates the best observed value and the best observed evaluation number.

Note
Both x and y must point to correctly sized allocated memory regions.
Parameters
problemThe given COCO problem.
xThe decision vector.
yThe objective vector that is the result of the evaluation (in single-objective problems only the first vector item is being set).
static void coco_problem_set_type ( coco_problem_t problem,
const char *  type,
  ... 
)
static

Sets the problem_type using formatted printing (as in printf).

Takes care of memory (de-)allocation.

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 
)
static

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.

Note
Regions of interest in the decision space must either agree or at least one of them must be NULL.
Best parameter becomes somewhat meaningless, but the nadir value make sense now.
static void coco_problem_stacked_evaluate_constraint ( coco_problem_t problem,
const double *  x,
double *  y 
)
static

Calls the coco_evaluate_constraint function on the underlying problems.

static void coco_problem_stacked_evaluate_function ( coco_problem_t problem,
const double *  x,
double *  y 
)
static

Calls the coco_evaluate_function function on the underlying problems.

static void coco_problem_stacked_free ( coco_problem_t problem)
static

Frees the stacked problem.

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 
)
static

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 void coco_problem_transformed_evaluate_constraint ( coco_problem_t problem,
const double *  x,
double *  y 
)
static

Calls the coco_evaluate_constraint function on the inner problem.

static void coco_problem_transformed_evaluate_function ( coco_problem_t problem,
const double *  x,
double *  y 
)
static

Calls the coco_evaluate_function function on the inner problem.

static void coco_problem_transformed_free ( coco_problem_t problem)
static

Frees the transformed problem.

static void coco_problem_transformed_free_data ( coco_problem_t problem)
static

Frees only the data of the transformed problem leaving the inner problem intact.

Note
If there is no other pointer to the inner problem, access to it will be lost.
static void* coco_problem_transformed_get_data ( const coco_problem_t problem)
static

Returns the data of the transformed problem.

static coco_problem_t* coco_problem_transformed_get_inner_problem ( const coco_problem_t problem)
static

Returns the inner problem of the transformed problem.

static void coco_problem_transformed_recommend_solution ( coco_problem_t problem,
const double *  x 
)
static

Calls the coco_recommend_solution function on the inner problem.

void coco_recommend_solution ( coco_problem_t problem,
const double *  x 
)

Recommends a solution as the current best guesses to the problem. Not implemented yet.

Evaluates and logs the given solution (as the coco_evaluate_function), but does not return the evaluated value.

Note
None of the observers implements this function yet!
x must point to a correctly sized allocated memory region.
Parameters
problemThe given COCO problem.
xThe decision vector.