-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de4d164
commit 4faef39
Showing
9 changed files
with
55 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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_obj_tcon_t)(const double x[], double *f, double constr[], const void *data); | ||
Check failure Code scanning / check-spelling Unrecognized Spelling Error
tcon is not a recognized word. (unrecognized-spelling)
|
||
|
||
|
||
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,22 +105,22 @@ 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 { | ||
|
||
// dimension of the problem | ||
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_obj_tcon_t calcfc; | ||
Check failure Code scanning / check-spelling Unrecognized Spelling Error
tcon is not a recognized word. (unrecognized-spelling)
|
||
|
||
// 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,19 +211,19 @@ typedef enum | |
PRIMA_LINCOA, | ||
PRIMA_NEWUOA, | ||
PRIMA_UOBYQA | ||
} prima_algorithm; | ||
} prima_algorithm_t; | ||
|
||
|
||
/* | ||
* algorithm : optimization algorithm (see prima_algorithm) | ||
* 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 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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_obj_tcon_t calcfc, const void *data, const int n, double x[], double *f, double *cstrv, double nlconstr[], | ||
Check failure Code scanning / check-spelling Unrecognized Spelling Error
tcon is not a recognized word. (unrecognized-spelling)
|
||
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) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters