diff --git a/c/examples/bobyqa/bobyqa_example.c b/c/examples/bobyqa/bobyqa_example.c index 2879785af8..d871944961 100644 --- a/c/examples/bobyqa/bobyqa_example.c +++ b/c/examples/bobyqa/bobyqa_example.c @@ -18,16 +18,16 @@ int main(int argc, char * argv[]) (void)argv; const int n = 2; double x0[2] = {0.0, 0.0}; - prima_problem problem; + prima_problem_t problem; prima_init_problem(&problem, n); problem.x0 = x0; problem.calfun = &fun; - prima_options options; + prima_options_t options; prima_init_options(&options); options.iprint = PRIMA_MSG_EXIT; options.rhoend= 1e-3; options.maxfun = 200*n; - prima_result result; + prima_result_t result; const int rc = prima_minimize(PRIMA_BOBYQA, &problem, &options, &result); printf("x*={%g, %g} rc=%d msg='%s' evals=%d\n", result.x[0], result.x[1], rc, result.message, result.nf); prima_free_problem(&problem); diff --git a/c/examples/cobyla/cobyla_example.c b/c/examples/cobyla/cobyla_example.c index 11ff544ff9..8053eabc2b 100644 --- a/c/examples/cobyla/cobyla_example.c +++ b/c/examples/cobyla/cobyla_example.c @@ -22,11 +22,11 @@ int main(int argc, char * argv[]) (void)argv; const int n = 2; double x0[2] = {0.0, 0.0}; - prima_problem problem; + prima_problem_t problem; prima_init_problem(&problem, n); problem.calcfc = &fun; problem.x0 = x0; - prima_options options; + prima_options_t options; prima_init_options(&options); options.iprint = PRIMA_MSG_EXIT; options.rhoend= 1e-3; @@ -46,7 +46,7 @@ int main(int argc, char * argv[]) double xu[2] = {6.0, 6.0}; problem.xl = xl; problem.xu = xu; - prima_result result; + prima_result_t result; const int rc = prima_minimize(PRIMA_COBYLA, &problem, &options, &result); printf("x*={%g, %g} f*=%g cstrv=%g nlconstr=%g rc=%d msg='%s' evals=%d\n", result.x[0], result.x[1], result.f, result.cstrv, result.nlconstr[0], rc, result.message, result.nf); prima_free_problem(&problem); diff --git a/c/examples/lincoa/lincoa_example.c b/c/examples/lincoa/lincoa_example.c index 55ed4861ce..e5aa89d05e 100644 --- a/c/examples/lincoa/lincoa_example.c +++ b/c/examples/lincoa/lincoa_example.c @@ -18,11 +18,11 @@ int main(int argc, char * argv[]) (void)argv; const int n = 2; double x0[2] = {0.0, 0.0}; - prima_problem problem; + prima_problem_t problem; prima_init_problem(&problem, n); problem.calfun = &fun; problem.x0 = x0; - prima_options options; + prima_options_t options; prima_init_options(&options); options.iprint = PRIMA_MSG_EXIT; options.rhoend= 1e-3; @@ -41,7 +41,7 @@ int main(int argc, char * argv[]) double xu[2] = {6.0, 6.0}; problem.xl = xl; problem.xu = xu; - prima_result result; + prima_result_t result; const int rc = prima_minimize(PRIMA_LINCOA, &problem, &options, &result); printf("x*={%g, %g} f*=%g cstrv=%g rc=%d msg='%s' evals=%d\n", result.x[0], result.x[1], result.f, result.cstrv, rc, result.message, result.nf); prima_free_problem(&problem); diff --git a/c/examples/newuoa/newuoa_example.c b/c/examples/newuoa/newuoa_example.c index 66c80d560e..00c4aa709b 100644 --- a/c/examples/newuoa/newuoa_example.c +++ b/c/examples/newuoa/newuoa_example.c @@ -18,16 +18,16 @@ int main(int argc, char * argv[]) (void)argv; const int n = 2; double x0[2] = {0.0, 0.0}; - prima_problem problem; + prima_problem_t problem; prima_init_problem(&problem, n); problem.calfun = &fun; problem.x0 = x0; - prima_options options; + prima_options_t options; prima_init_options(&options); options.iprint = PRIMA_MSG_EXIT; options.rhoend= 1e-3; options.maxfun = 200*n; - prima_result result; + prima_result_t result; const int rc = prima_minimize(PRIMA_NEWUOA, &problem, &options, &result); printf("x*={%g, %g} rc=%d msg='%s' evals=%d\n", result.x[0], result.x[1], rc, result.message, result.nf); prima_free_problem(&problem); diff --git a/c/examples/uobyqa/uobyqa_example.c b/c/examples/uobyqa/uobyqa_example.c index 6e70afbc19..be53e87c21 100644 --- a/c/examples/uobyqa/uobyqa_example.c +++ b/c/examples/uobyqa/uobyqa_example.c @@ -18,16 +18,16 @@ int main(int argc, char * argv[]) (void)argv; const int n = 2; double x0[2] = {0.0, 0.0}; - prima_problem problem; + prima_problem_t problem; prima_init_problem(&problem, n); problem.calfun = &fun; problem.x0 = x0; - prima_options options; + prima_options_t options; prima_init_options(&options); options.iprint = PRIMA_MSG_EXIT; options.rhoend= 1e-3; options.maxfun = 200*n; - prima_result result; + prima_result_t result; const int rc = prima_minimize(PRIMA_UOBYQA, &problem, &options, &result); printf("x*={%g, %g} rc=%d msg='%s' evals=%d\n", result.x[0], result.x[1], rc, result.message, result.nf); prima_free_problem(&problem); diff --git a/c/include/prima/prima.h b/c/include/prima/prima.h index 108cc82f5b..bb38c17961 100644 --- a/c/include/prima/prima.h +++ b/c/include/prima/prima.h @@ -31,7 +31,7 @@ typedef enum { PRIMA_MSG_EXIT = 1, /* Exit reasons */ PRIMA_MSG_RHO = 2, /* Rho changes */ PRIMA_MSG_FEVL = 3, /* The object/constraint functions get evaluated */ -} prima_message; +} prima_message_t; /* * Possible return values @@ -58,13 +58,13 @@ typedef enum PRIMA_NULL_X0 = 112, PRIMA_NULL_RESULT = 113, PRIMA_NULL_FUNCTION = 114, -} prima_rc; +} prima_rc_t; /* * Return code string */ PRIMAC_API -const char *prima_get_rc_string(int rc); +const char *prima_get_rc_string(const prima_rc_t rc); /* * A function as required by solvers @@ -77,8 +77,8 @@ const char *prima_get_rc_string(int rc); * NaN values can be passed to signal evaluation errors * only for cobyla */ -typedef void (*prima_obj)(const double x[], double *f, const void *data); -typedef void (*prima_objcon)(const double x[], double *f, double constr[], const void *data); +typedef void (*prima_obj_t)(const double x[], double *f, const void *data); +typedef void (*prima_objcon_t)(const double x[], double *f, double constr[], const void *data); typedef struct { @@ -92,7 +92,7 @@ typedef struct { // maximum number of function evaluations (default=-1 interpreted as 500*n) int maxfun; - // verbosity level, see the prima_message enum (default=PRIMA_MSG_NONE) + // verbosity level, see the prima_message_t enum (default=PRIMA_MSG_NONE) int iprint; // target function value; optimization stops when f <= ftarget for a feasible point (default=-inf) @@ -105,11 +105,11 @@ typedef struct { // user-data, will be passed through the objective function callback void *data; -} prima_options; +} prima_options_t; /* Initialize problem */ PRIMAC_API -int prima_init_options(prima_options *options); +int prima_init_options(prima_options_t *options); typedef struct { @@ -117,10 +117,10 @@ typedef struct { int n; // objective function to minimize (not cobyla) - prima_obj calfun; + prima_obj_t calfun; // objective function to minimize with constraints (cobyla) - prima_objcon calcfc; + prima_objcon_t calcfc; // starting point double *x0; @@ -157,15 +157,15 @@ typedef struct { // whether prima had to allocate nlconstr0 (private, do not use) int _allocated_nlconstr0; -} prima_problem; +} prima_problem_t; /* Initialize/free problem */ PRIMAC_API -int prima_init_problem(prima_problem *problem, int n); +int prima_init_problem(prima_problem_t *problem, int n); PRIMAC_API -int prima_free_problem(prima_problem *problem); +int prima_free_problem(prima_problem_t *problem); typedef struct { @@ -194,12 +194,12 @@ typedef struct { // error message const char *message; -} prima_result; +} prima_result_t; /* Free result after optimization */ PRIMAC_API -int prima_free_result(prima_result * result); +int prima_free_result(prima_result_t * result); /* * Algorithm @@ -211,7 +211,7 @@ typedef enum PRIMA_LINCOA, PRIMA_NEWUOA, PRIMA_UOBYQA -} prima_algorithm; +} prima_algorithm_t; /* @@ -219,11 +219,11 @@ typedef enum * problem : optimization problem (see prima_problem) * options : optimization options (see prima_options) * result : optimization result (see prima_result) - * return : see prima_rc enum for return codes + * return : see prima_rc_t enum for return codes */ PRIMAC_API -int prima_minimize(prima_algorithm algorithm, prima_problem *problem, prima_options *options, prima_result *result); +int prima_minimize(const prima_algorithm_t algorithm, prima_problem_t *problem, prima_options_t *options, prima_result_t *result); #ifdef __cplusplus } diff --git a/c/prima.c b/c/prima.c index 019e2ea64e..38d2d96127 100644 --- a/c/prima.c +++ b/c/prima.c @@ -8,11 +8,11 @@ #define MAXFUN_DIM_DFT 500 -int prima_init_options(prima_options *options) +int prima_init_options(prima_options_t *options) { if (options) { - memset(options, 0, sizeof(prima_options)); + memset(options, 0, sizeof(prima_options_t)); options->maxfun = -1;// interpreted as MAXFUN_DIM_DFT*n options->rhobeg = 1.0; options->rhoend = 1e-6; @@ -25,11 +25,11 @@ int prima_init_options(prima_options *options) return PRIMA_NULL_OPTIONS; } -int prima_init_problem(prima_problem *problem, int n) +int prima_init_problem(prima_problem_t *problem, int n) { if (problem) { - memset(problem, 0, sizeof(prima_problem)); + memset(problem, 0, sizeof(prima_problem_t)); problem->n = n; problem->f0 = NAN; return 0; @@ -39,26 +39,26 @@ int prima_init_problem(prima_problem *problem, int n) } /* implemented in fortran (*_c.f90) */ -int cobyla_c(const int m_nlcon, const prima_objcon calcfc, const void *data, const int n, double x[], double *f, double *cstrv, double nlconstr[], +int cobyla_c(const int m_nlcon, const prima_objcon_t calcfc, const void *data, const int n, double x[], double *f, double *cstrv, double nlconstr[], const int m_ineq, const double Aineq[], const double bineq[], const int m_eq, const double Aeq[], const double beq[], const double xl[], const double xu[], double f0, const double nlconstr0[], int *nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int iprint, int *info); -int bobyqa_c(prima_obj calfun, const void *data, const int n, double x[], double *f, const double xl[], const double xu[], +int bobyqa_c(prima_obj_t calfun, const void *data, const int n, double x[], double *f, const double xl[], const double xu[], int *nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int npt, const int iprint, int *info); -int newuoa_c(prima_obj calfun, const void *data, const int n, double x[], double *f, +int newuoa_c(prima_obj_t calfun, const void *data, const int n, double x[], double *f, int *nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int npt, const int iprint, int *info); -int uobyqa_c(prima_obj calfun, const void *data, const int n, double x[], double *f, +int uobyqa_c(prima_obj_t calfun, const void *data, const int n, double x[], double *f, int *nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int iprint, int *info); -int lincoa_c(prima_obj calfun, const void *data, const int n, double x[], double *f, +int lincoa_c(prima_obj_t calfun, const void *data, const int n, double x[], double *f, double *cstrv, const int m_ineq, const double Aineq[], const double bineq[], const int m_eq, const double Aeq[], const double beq[], const double xl[], const double xu[], int *nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int npt, const int iprint, int *info); -int prima_check_problem(prima_problem *problem, prima_options *options, int alloc_bounds, int use_constr) +int prima_check_problem(prima_problem_t *problem, prima_options_t *options, int alloc_bounds, int use_constr) { if (!problem) return PRIMA_NULL_PROBLEM; @@ -93,7 +93,7 @@ int prima_check_problem(prima_problem *problem, prima_options *options, int allo return 0; } -int prima_free_problem(prima_problem *problem) +int prima_free_problem(prima_problem_t *problem) { if (problem) { @@ -121,11 +121,11 @@ int prima_free_problem(prima_problem *problem) return PRIMA_NULL_PROBLEM; } -int prima_init_result(prima_result *result, prima_problem *problem) +int prima_init_result(prima_result_t *result, prima_problem_t *problem) { if (result) { - memset(result, 0, sizeof(prima_result)); + memset(result, 0, sizeof(prima_result_t)); result->f = 0.0; result->cstrv = 0.0; if (!problem) @@ -142,7 +142,7 @@ int prima_init_result(prima_result *result, prima_problem *problem) return PRIMA_NULL_RESULT; } -int prima_free_result(prima_result *result) +int prima_free_result(prima_result_t *result) { if (result) { @@ -159,7 +159,7 @@ int prima_free_result(prima_result *result) } /* these functions just call the fortran compatibility layer and return the status code */ -int prima_minimize(prima_algorithm algorithm, prima_problem *problem, prima_options *options, prima_result *result) +int prima_minimize(const prima_algorithm_t algorithm, prima_problem_t *problem, prima_options_t *options, prima_result_t *result) { int alloc_bounds = (algorithm == PRIMA_COBYLA) || (algorithm == PRIMA_BOBYQA) || (algorithm == PRIMA_LINCOA); int use_constr = (algorithm == PRIMA_COBYLA); @@ -235,7 +235,7 @@ int prima_minimize(prima_algorithm algorithm, prima_problem *problem, prima_opti return info; } -const char *prima_get_rc_string(const int rc) +const char *prima_get_rc_string(const prima_rc_t rc) { switch (rc) { diff --git a/c/tests/data.c b/c/tests/data.c index a806f23fcc..f72c7cfe6c 100644 --- a/c/tests/data.c +++ b/c/tests/data.c @@ -69,12 +69,12 @@ int main(int argc, char * argv[]) double x0[] = {0, 0}; double xl[] = {-6.0, -6.0}; double xu[] = {6.0, 6.0}; - prima_problem problem; + prima_problem_t problem; prima_init_problem(&problem, n); problem.calcfc = &fun_con; problem.calfun = &fun; problem.x0 = x0; - prima_options options; + prima_options_t options; prima_init_options(&options); options.iprint = PRIMA_MSG_RHO; options.maxfun = 500*n; @@ -90,8 +90,8 @@ int main(int argc, char * argv[]) problem.bineq = bineq; problem.xl = xl; problem.xu = xu; - prima_result result; - int algorithm = 0; + prima_result_t result; + prima_algorithm_t algorithm = 0; if(strcmp(algo, "bobyqa") == 0) { algorithm = PRIMA_BOBYQA; diff --git a/c/tests/stress.c b/c/tests/stress.c index 65b02df3f4..cf25b9f201 100644 --- a/c/tests/stress.c +++ b/c/tests/stress.c @@ -83,12 +83,12 @@ int main(int argc, char * argv[]) double x0[N_MAX]; double xl[N_MAX]; double xu[N_MAX]; - prima_problem problem; + prima_problem_t problem; prima_init_problem(&problem, N_MAX); problem.x0 = x0; problem.calcfc = &fun_con; problem.calfun = &fun; - prima_options options; + prima_options_t options; prima_init_options(&options); options.iprint = PRIMA_MSG_RHO; options.maxfun = 500*N_MAX; @@ -109,8 +109,8 @@ int main(int argc, char * argv[]) xl[i] = -1.0; xu[i] = 1.0; } - int algorithm = 0; - prima_result result; + prima_algorithm_t algorithm = 0; + prima_result_t result; if(strcmp(algo, "bobyqa") == 0) { algorithm = PRIMA_BOBYQA;