diff --git a/c/cobyla_c.f90 b/c/cobyla_c.f90 index e0ac273e01..36db0414e0 100644 --- a/c/cobyla_c.f90 +++ b/c/cobyla_c.f90 @@ -71,6 +71,7 @@ subroutine cobyla_c(m_nlcon, cobjcon_ptr, data_ptr, n, x, f, cstrv, nlconstr, m_ real(RP) :: beq_loc(m_eq) real(RP) :: bineq_loc(m_ineq) real(RP) :: cstrv_loc +real(RP) :: ctol_loc real(RP) :: f_loc real(RP) :: ftarget_loc real(RP) :: nlconstr_loc(m_nlcon) @@ -79,7 +80,6 @@ subroutine cobyla_c(m_nlcon, cobjcon_ptr, data_ptr, n, x, f, cstrv, nlconstr, m_ real(RP), allocatable :: nlconstr0_loc(:) real(RP), allocatable :: rhobeg_loc real(RP), allocatable :: rhoend_loc -real(RP), allocatable :: ctol_loc real(RP), allocatable :: xl_loc(:) real(RP), allocatable :: xu_loc(:) @@ -131,9 +131,7 @@ subroutine cobyla_c(m_nlcon, cobjcon_ptr, data_ptr, n, x, f, cstrv, nlconstr, m_ maxfun_loc = int(maxfun, kind(maxfun_loc)) end if iprint_loc = int(iprint, kind(iprint_loc)) -if (.not. is_nan(ctol)) then - ctol_loc = real(ctol, kind(ctol_loc)) -end if +ctol_loc = real(ctol, kind(ctol_loc)) ! Call the Fortran code if (c_associated(callback_ptr)) then diff --git a/c/include/prima/prima.h b/c/include/prima/prima.h index 9893108747..6755765729 100644 --- a/c/include/prima/prima.h +++ b/c/include/prima/prima.h @@ -73,11 +73,6 @@ typedef enum { } prima_rc_t; -// Function to get the message string corresponding to a return code -PRIMAC_API -const char *prima_get_rc_string(const prima_rc_t rc); - - /* * Objective function required by UOBYQA, NEWUOA, BOBYQA, and LINCOA * x : on input, the vector of variables (should not be modified) @@ -272,6 +267,9 @@ typedef struct { // status: return code prima_rc_t status; + // success: whether the solver returned normally or ran into abnormal conditions + bool success; + // message: exit message const char *message; @@ -298,10 +296,6 @@ PRIMAC_API prima_rc_t prima_minimize(const prima_algorithm_t algorithm, const prima_problem_t problem, const prima_options_t options, prima_result_t *const result); -// Function to check if PRIMA returned normally or ran into abnormal conditions -PRIMAC_API -bool prima_is_success(const prima_result_t result); - #ifdef __cplusplus } #endif diff --git a/c/lincoa_c.f90 b/c/lincoa_c.f90 index cb399bfef2..40864846d4 100644 --- a/c/lincoa_c.f90 +++ b/c/lincoa_c.f90 @@ -68,12 +68,12 @@ subroutine lincoa_c(cobj_ptr, data_ptr, n, x, f, cstrv, m_ineq, Aineq, bineq, m_ real(RP) :: beq_loc(m_eq) real(RP) :: bineq_loc(m_ineq) real(RP) :: cstrv_loc +real(RP) :: ctol_loc real(RP) :: f_loc real(RP) :: ftarget_loc real(RP) :: x_loc(n) real(RP), allocatable :: rhobeg_loc real(RP), allocatable :: rhoend_loc -real(RP), allocatable :: ctol_loc real(RP), allocatable :: xl_loc(:) real(RP), allocatable :: xu_loc(:) @@ -120,9 +120,7 @@ subroutine lincoa_c(cobj_ptr, data_ptr, n, x, f, cstrv, m_ineq, Aineq, bineq, m_ npt_loc = int(npt, kind(npt_loc)) end if iprint_loc = int(iprint, kind(iprint_loc)) -if (.not. is_nan(ctol)) then - ctol_loc = real(ctol, kind(ctol_loc)) -end if +ctol_loc = real(ctol, kind(ctol_loc)) ! Call the Fortran code if (c_associated(callback_ptr)) then diff --git a/c/prima.c b/c/prima.c index 5d380971c1..7499216e6c 100644 --- a/c/prima.c +++ b/c/prima.c @@ -57,7 +57,7 @@ prima_rc_t prima_init_options(prima_options_t *const options) options->rhoend = NAN; // Will be interpreted by Fortran as not present options->iprint = PRIMA_MSG_NONE; options->ftarget = -INFINITY; - options->ctol = NAN; // Will be interpreted by Fortran as not present + options->ctol = sqrt(DBL_EPSILON); return PRIMA_RC_DFT; } @@ -263,13 +263,9 @@ prima_rc_t prima_minimize(const prima_algorithm_t algorithm, const prima_problem } result->status = info; + result->success = ((result->status == PRIMA_SMALL_TR_RADIUS && result->cstrv <= options.ctol) || + (result->status == PRIMA_FTARGET_ACHIEVED)); result->message = prima_get_rc_string(info); return info; } - -bool prima_is_success(const prima_result_t result) -{ - return (result.status == PRIMA_SMALL_TR_RADIUS || - result.status == PRIMA_FTARGET_ACHIEVED) && (result.cstrv <= sqrt(DBL_EPSILON)); -} diff --git a/python/_prima.cpp b/python/_prima.cpp index 98794b453d..f28d90bd71 100644 --- a/python/_prima.cpp +++ b/python/_prima.cpp @@ -32,7 +32,7 @@ struct PRIMAResult { // Construct PRIMAResult from prima_result_t PRIMAResult(const prima_result_t& result, const int num_vars, const int num_constraints, const std::string method) : x(num_vars, result.x), - success(prima_is_success(result)), + success(result.success), status(result.status), message(result.message), fun(result.f),