diff --git a/c/bobyqa_c.f90 b/c/bobyqa_c.f90 index 7aaf8c311a..befe1b4a4d 100644 --- a/c/bobyqa_c.f90 +++ b/c/bobyqa_c.f90 @@ -13,7 +13,7 @@ module bobyqa_c_mod contains -subroutine bobyqa_c(cobj_ptr, n, x, f, xl, xu, nf, rhobeg, rhoend, maxfun, iprint, info) bind(C) +subroutine bobyqa_c(cobj_ptr, n, x, f, xl, xu, nf, rhobeg, rhoend, ftarget, maxfun, iprint, info) bind(C) use, intrinsic :: iso_c_binding, only : C_DOUBLE, C_INT, C_FUNPTR use, non_intrinsic :: cintrf_mod, only : COBJ use, non_intrinsic :: consts_mod, only : RP, IK @@ -34,6 +34,7 @@ subroutine bobyqa_c(cobj_ptr, n, x, f, xl, xu, nf, rhobeg, rhoend, maxfun, iprin integer(C_INT), intent(out) :: nf real(C_DOUBLE), intent(in), value :: rhobeg real(C_DOUBLE), intent(in), value :: rhoend +real(C_DOUBLE), intent(in), value :: ftarget integer(C_INT), intent(in), value :: maxfun integer(C_INT), intent(in), value :: iprint integer(C_INT), intent(out) :: info @@ -46,6 +47,7 @@ subroutine bobyqa_c(cobj_ptr, n, x, f, xl, xu, nf, rhobeg, rhoend, maxfun, iprin real(RP) :: f_loc real(RP) :: rhobeg_loc real(RP) :: rhoend_loc +real(RP) :: ftarget_loc real(RP) :: x_loc(n) real(RP) :: xl_loc(n) real(RP) :: xu_loc(n) @@ -56,12 +58,13 @@ subroutine bobyqa_c(cobj_ptr, n, x, f, xl, xu, nf, rhobeg, rhoend, maxfun, iprin xu_loc = real(xu, kind(xu_loc)) rhobeg_loc = real(rhobeg, kind(rhobeg)) rhoend_loc = real(rhoend, kind(rhoend)) +ftarget_loc = real(ftarget, kind(ftarget)) maxfun_loc = int(maxfun, kind(maxfun_loc)) iprint_loc = int(iprint, kind(iprint_loc)) ! Call the Fortran code call bobyqa(calfun, x_loc, f_loc, xl=xl_loc, xu=xu_loc, nf=nf_loc, rhobeg=rhobeg_loc, rhoend=rhoend_loc, & - & maxfun=maxfun_loc, iprint=iprint_loc, info=info_loc) + & ftarget=ftarget_loc, maxfun=maxfun_loc, iprint=iprint_loc, info=info_loc) ! Write the outputs x = real(x_loc, kind(x)) diff --git a/c/cobyla_c.f90 b/c/cobyla_c.f90 index 9d823beb43..4f7466f055 100644 --- a/c/cobyla_c.f90 +++ b/c/cobyla_c.f90 @@ -13,7 +13,7 @@ module cobyla_c_mod subroutine cobyla_c(m_nlcon, cobjcon_ptr, n, x, f, cstrv, nlconstr, m_ineq, Aineq, bineq, m_eq, Aeq, beq, xl, xu, & - & nf, rhobeg, rhoend, maxfun, iprint, info) bind(C) + & nf, rhobeg, rhoend, ftarget, maxfun, iprint, info) bind(C) use, intrinsic :: iso_c_binding, only : C_DOUBLE, C_INT, C_FUNPTR use, non_intrinsic :: cintrf_mod, only : COBJCON use, non_intrinsic :: consts_mod, only : RP, IK @@ -43,6 +43,7 @@ subroutine cobyla_c(m_nlcon, cobjcon_ptr, n, x, f, cstrv, nlconstr, m_ineq, Aine integer(C_INT), intent(out) :: nf real(C_DOUBLE), intent(in), value :: rhobeg real(C_DOUBLE), intent(in), value :: rhoend +real(C_DOUBLE), intent(in), value :: ftarget integer(C_INT), intent(in), value :: maxfun integer(C_INT), intent(in), value :: iprint integer(C_INT), intent(out) :: info @@ -62,6 +63,7 @@ subroutine cobyla_c(m_nlcon, cobjcon_ptr, n, x, f, cstrv, nlconstr, m_ineq, Aine real(RP) :: f_loc real(RP) :: rhobeg_loc real(RP) :: rhoend_loc +real(RP) :: ftarget_loc real(RP) :: x_loc(n) real(RP) :: xl_loc(n) real(RP) :: xu_loc(n) @@ -78,6 +80,7 @@ subroutine cobyla_c(m_nlcon, cobjcon_ptr, n, x, f, cstrv, nlconstr, m_ineq, Aine xu_loc = real(xu, kind(xu_loc)) rhobeg_loc = real(rhobeg, kind(rhobeg)) rhoend_loc = real(rhoend, kind(rhoend)) +ftarget_loc = real(ftarget, kind(ftarget)) maxfun_loc = int(maxfun, kind(maxfun_loc)) iprint_loc = int(iprint, kind(iprint_loc)) m_nlcon_loc = int(m_nlcon, kind(m_nlcon_loc)) @@ -86,7 +89,8 @@ subroutine cobyla_c(m_nlcon, cobjcon_ptr, n, x, f, cstrv, nlconstr, m_ineq, Aine call cobyla(calcfc, m_nlcon_loc, x_loc, f_loc, cstrv=cstrv_loc, nlconstr=nlconstr_loc, & & Aineq=Aineq_loc, bineq=bineq_loc, Aeq=Aeq_loc, beq=beq_loc, & & xl=xl_loc, xu=xu_loc, nf=nf_loc, & - & rhobeg=rhobeg_loc, rhoend=rhoend_loc, maxfun=maxfun_loc, iprint=iprint_loc, info=info_loc) + & rhobeg=rhobeg_loc, rhoend=rhoend_loc, ftarget=ftarget_loc, maxfun=maxfun_loc, & + & iprint=iprint_loc, info=info_loc) ! Write the outputs x = real(x_loc, kind(x)) diff --git a/c/examples/bobyqa/bobyqa_example.c b/c/examples/bobyqa/bobyqa_example.c index cf89560a98..7ffb0b558e 100644 --- a/c/examples/bobyqa/bobyqa_example.c +++ b/c/examples/bobyqa/bobyqa_example.c @@ -20,10 +20,11 @@ int main(int argc, char * argv[]) double xu[2] = {6.0, 6.0}; const double rhobeg = 1.0; const double rhoend = 1e-3; + const double ftarget = -INFINITY; const int iprint = PRIMA_MSG_EXIT; const int maxfun = 1000; int nf = 0; - const int rc = prima_bobyqa(&fun, n, x, &f, xl, xu, &nf, rhobeg, rhoend, maxfun, iprint); + const int rc = prima_bobyqa(&fun, n, x, &f, xl, xu, &nf, rhobeg, rhoend, ftarget, maxfun, iprint); const char *msg = prima_get_rc_string(rc); printf("x*={%g, %g} rc=%d msg='%s' evals=%d\n", x[0], x[1], rc, msg, nf); return (fabs(x[0]-3)>2e-2 || fabs(x[1]-2)>2e-2); diff --git a/c/examples/cobyla/cobyla_example.c b/c/examples/cobyla/cobyla_example.c index 54f7a6bc63..7517a63070 100644 --- a/c/examples/cobyla/cobyla_example.c +++ b/c/examples/cobyla/cobyla_example.c @@ -35,10 +35,11 @@ int main(int argc, char * argv[]) double xu[2] = {6.0, 6.0}; const double rhobeg = 1.0; const double rhoend = 1e-3; + const double ftarget = -INFINITY; const int iprint = PRIMA_MSG_EXIT; const int maxfun = 1000; int nf = 0; - const int rc = prima_cobyla(m_nlcon, &fun, n, x, &f, &cstrv, nlconstr, m_ineq, Aineq, bineq, m_eq, Aeq, beq, xl, xu, &nf, rhobeg, rhoend, maxfun, iprint); + const int rc = prima_cobyla(m_nlcon, &fun, n, x, &f, &cstrv, nlconstr, m_ineq, Aineq, bineq, m_eq, Aeq, beq, xl, xu, &nf, rhobeg, rhoend, ftarget, maxfun, iprint); const char *msg = prima_get_rc_string(rc); printf("x*={%g, %g} f*=%g cstrv=%g nlconstr=%g rc=%d msg='%s' evals=%d\n", x[0], x[1], f, cstrv, nlconstr[0], rc, msg, nf); return (fabs(x[0]-3)>2e-2 || fabs(x[1]-2)>2e-2); diff --git a/c/examples/lincoa/lincoa_example.c b/c/examples/lincoa/lincoa_example.c index 0e5b2d5111..528ceddbfb 100644 --- a/c/examples/lincoa/lincoa_example.c +++ b/c/examples/lincoa/lincoa_example.c @@ -32,10 +32,11 @@ int main(int argc, char * argv[]) double xu[2] = {6.0, 6.0}; const double rhobeg = 1.0; const double rhoend = 1e-3; + const double ftarget = -INFINITY; const int iprint = PRIMA_MSG_EXIT; const int maxfun = 100000; int nf = 0; - const int rc = prima_lincoa(&fun, n, x, &f, &cstrv, m_ineq, Aineq, bineq, m_eq, Aeq, beq, xl, xu, &nf, rhobeg, rhoend, maxfun, iprint); + const int rc = prima_lincoa(&fun, n, x, &f, &cstrv, m_ineq, Aineq, bineq, m_eq, Aeq, beq, xl, xu, &nf, rhobeg, rhoend, ftarget, maxfun, iprint); const char *msg = prima_get_rc_string(rc); printf("x*={%g, %g} f*=%g cstrv=%g rc=%d msg='%s' evals=%d\n", x[0], x[1], f, cstrv, rc, msg, maxfun); return (fabs(x[0]-3)>2e-2 || fabs(x[1]-2)>2e-2); diff --git a/c/examples/newuoa/newuoa_example.c b/c/examples/newuoa/newuoa_example.c index 5510fe8d39..c9de4927e9 100644 --- a/c/examples/newuoa/newuoa_example.c +++ b/c/examples/newuoa/newuoa_example.c @@ -18,10 +18,11 @@ int main(int argc, char * argv[]) double f = 0.0; const double rhobeg = 1.0; const double rhoend = 1e-3; + const double ftarget = -INFINITY; const int iprint = PRIMA_MSG_EXIT; const int maxfun = 1000; int nf = 0; - const int rc = prima_newuoa(&fun, n, x, &f, &nf, rhobeg, rhoend, maxfun, iprint); + const int rc = prima_newuoa(&fun, n, x, &f, &nf, rhobeg, rhoend, ftarget, maxfun, iprint); const char *msg = prima_get_rc_string(rc); printf("x*={%g, %g} rc=%d msg='%s' evals=%d\n", x[0], x[1], rc, msg, nf); return (fabs(x[0]-3)>2e-2 || fabs(x[1]-2)>2e-2); diff --git a/c/examples/uobyqa/uobyqa_example.c b/c/examples/uobyqa/uobyqa_example.c index b339f3624a..53dbab343a 100644 --- a/c/examples/uobyqa/uobyqa_example.c +++ b/c/examples/uobyqa/uobyqa_example.c @@ -18,10 +18,11 @@ int main(int argc, char * argv[]) double f = 0.0; const double rhobeg = 1.0; const double rhoend = 1e-3; + const double ftarget = -INFINITY; const int iprint = PRIMA_MSG_EXIT; const int maxfun = 1000; int nf = 0; - const int rc = prima_uobyqa(&fun, n, x, &f, &nf, rhobeg, rhoend, maxfun, iprint); + const int rc = prima_uobyqa(&fun, n, x, &f, &nf, rhobeg, rhoend, ftarget, maxfun, iprint); const char *msg = prima_get_rc_string(rc); printf("x*={%g, %g} rc=%d msg='%s' evals=%d\n", x[0], x[1], rc, msg, nf); return (fabs(x[0]-3)>2e-2 || fabs(x[1]-2)>2e-2); diff --git a/c/include/prima/prima.h b/c/include/prima/prima.h index b15e43dd06..13d0415adf 100644 --- a/c/include/prima/prima.h +++ b/c/include/prima/prima.h @@ -81,6 +81,8 @@ typedef void (*prima_objcon)(const double x[], double *f, double constr[]); * nf : number of objective function calls (output) * rhobeg : a reasonable initial change to the variables * rhoend : required accuracy for the variables + * ftarget : target function value; optimization stops when the value <= ftarget + * can be set to -INFINITY to disable * maxfun : maximum number of function evaluations * iprint : verbosity level, see the prima_message enum * m_nlcon : number of non-linear constraints (>=0) @@ -101,15 +103,15 @@ typedef void (*prima_objcon)(const double x[], double *f, double constr[]); PRIMAC_API int prima_bobyqa(const prima_obj calfun, const int n, double x[n], double *f, const double xl[n], const double xu[n], - int *nf, const double rhobeg, const double rhoend, const int maxfun, const int iprint); + int *nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int iprint); PRIMAC_API int prima_newuoa(const prima_obj calfun, const int n, double x[n], double *f, - int *nf, const double rhobeg, const double rhoend, const int maxfun, const int iprint); + int *nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int iprint); PRIMAC_API int prima_uobyqa(const prima_obj calfun, const int n, double x[n], double *f, - int *nf, const double rhobeg, const double rhoend, const int maxfun, const int iprint); + int *nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int iprint); PRIMAC_API int prima_cobyla(const int m_nlcon, const prima_objcon calcfc, const int n, double x[n], double *f, @@ -117,7 +119,7 @@ int prima_cobyla(const int m_nlcon, const prima_objcon calcfc, const int n, doub const int m_ineq, const double Aineq[m_ineq*n], const double bineq[m_ineq], const int m_eq, const double Aeq[m_eq*n], const double beq[m_eq], const double xl[n], const double xu[n], - int *nf, const double rhobeg, const double rhoend, const int maxfun, const int iprint); + int *nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int iprint); PRIMAC_API int prima_lincoa(const prima_obj calfun, const int n, double x[n], double *f, @@ -125,7 +127,7 @@ int prima_lincoa(const prima_obj calfun, const int n, double x[n], double *f, const int m_ineq, const double Aineq[m_ineq*n], const double bineq[m_ineq], const int m_eq, const double Aeq[m_eq*n], const double beq[m_eq], const double xl[n], const double xu[n], - int *nf, const double rhobeg, const double rhoend, const int maxfun, const int iprint); + int *nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int iprint); #ifdef __cplusplus } diff --git a/c/lincoa_c.f90 b/c/lincoa_c.f90 index 7dfa0773e5..8df4cef801 100644 --- a/c/lincoa_c.f90 +++ b/c/lincoa_c.f90 @@ -14,7 +14,7 @@ module lincoa_c_mod subroutine lincoa_c(cobj_ptr, n, x, f, cstrv, m_ineq, Aineq, bineq, m_eq, Aeq, beq, xl, xu, & - & nf, rhobeg, rhoend, maxfun, iprint, info) bind(C) + & nf, rhobeg, rhoend, ftarget, maxfun, iprint, info) bind(C) use, intrinsic :: iso_c_binding, only : C_DOUBLE, C_INT, C_FUNPTR use, non_intrinsic :: cintrf_mod, only : COBJ use, non_intrinsic :: consts_mod, only : RP, IK @@ -42,6 +42,7 @@ subroutine lincoa_c(cobj_ptr, n, x, f, cstrv, m_ineq, Aineq, bineq, m_eq, Aeq, b integer(C_INT), intent(out) :: nf real(C_DOUBLE), intent(in), value :: rhobeg real(C_DOUBLE), intent(in), value :: rhoend +real(C_DOUBLE), intent(in), value :: ftarget integer(C_INT), intent(in), value :: maxfun integer(C_INT), intent(in), value :: iprint integer(C_INT), intent(out) :: info @@ -59,6 +60,7 @@ subroutine lincoa_c(cobj_ptr, n, x, f, cstrv, m_ineq, Aineq, bineq, m_eq, Aeq, b real(RP) :: f_loc real(RP) :: rhobeg_loc real(RP) :: rhoend_loc +real(RP) :: ftarget_loc real(RP) :: x_loc(n) real(RP) :: xl_loc(n) real(RP) :: xu_loc(n) @@ -75,6 +77,7 @@ subroutine lincoa_c(cobj_ptr, n, x, f, cstrv, m_ineq, Aineq, bineq, m_eq, Aeq, b xu_loc = real(xu, kind(xu_loc)) rhobeg_loc = real(rhobeg, kind(rhobeg)) rhoend_loc = real(rhoend, kind(rhoend)) +ftarget_loc = real(ftarget, kind(ftarget)) maxfun_loc = int(maxfun, kind(maxfun_loc)) iprint_loc = int(iprint, kind(iprint_loc)) @@ -82,7 +85,8 @@ subroutine lincoa_c(cobj_ptr, n, x, f, cstrv, m_ineq, Aineq, bineq, m_eq, Aeq, b call lincoa(calfun, x_loc, f_loc, cstrv=cstrv_loc, & & Aineq=Aineq_loc, bineq=bineq_loc, Aeq=Aeq_loc, beq=beq_loc, & & xl=xl_loc, xu=xu_loc, nf=nf_loc, & - & rhobeg=rhobeg_loc, rhoend=rhoend_loc, maxfun=maxfun_loc, iprint=iprint_loc, info=info_loc) + & rhobeg=rhobeg_loc, rhoend=rhoend_loc, & + & ftarget=ftarget_loc, maxfun=maxfun_loc, iprint=iprint_loc, info=info_loc) ! Write the outputs x = real(x_loc, kind(x)) diff --git a/c/newuoa_c.f90 b/c/newuoa_c.f90 index 6c2d9636fa..6a0aa51609 100644 --- a/c/newuoa_c.f90 +++ b/c/newuoa_c.f90 @@ -12,7 +12,7 @@ module newuoa_c_mod contains -subroutine newuoa_c(cobj_ptr, n, x, f, nf, rhobeg, rhoend, maxfun, iprint, info) bind(C) +subroutine newuoa_c(cobj_ptr, n, x, f, nf, rhobeg, rhoend, ftarget, maxfun, iprint, info) bind(C) use, intrinsic :: iso_c_binding, only : C_DOUBLE, C_INT, C_FUNPTR use, non_intrinsic :: cintrf_mod, only : COBJ use, non_intrinsic :: consts_mod, only : RP, IK @@ -31,6 +31,7 @@ subroutine newuoa_c(cobj_ptr, n, x, f, nf, rhobeg, rhoend, maxfun, iprint, info) integer(C_INT), intent(out) :: nf real(C_DOUBLE), intent(in), value :: rhobeg real(C_DOUBLE), intent(in), value :: rhoend +real(C_DOUBLE), intent(in), value :: ftarget integer(C_INT), intent(in), value :: maxfun integer(C_INT), intent(in), value :: iprint integer(C_INT), intent(out) :: info @@ -43,17 +44,19 @@ subroutine newuoa_c(cobj_ptr, n, x, f, nf, rhobeg, rhoend, maxfun, iprint, info) real(RP) :: f_loc real(RP) :: rhobeg_loc real(RP) :: rhoend_loc +real(RP) :: ftarget_loc real(RP) :: x_loc(n) ! Read the inputs and convert them to the Fortran side types x_loc = real(x, kind(x_loc)) rhobeg_loc = real(rhobeg, kind(rhobeg)) rhoend_loc = real(rhoend, kind(rhoend)) +ftarget_loc = real(ftarget, kind(ftarget)) maxfun_loc = int(maxfun, kind(maxfun_loc)) iprint_loc = int(iprint, kind(iprint_loc)) ! Call the Fortran code -call newuoa(calfun, x_loc, f_loc, nf=nf_loc, rhobeg=rhobeg_loc, rhoend=rhoend_loc, & +call newuoa(calfun, x_loc, f_loc, nf=nf_loc, rhobeg=rhobeg_loc, rhoend=rhoend_loc, ftarget=ftarget_loc, & & maxfun=maxfun_loc, iprint=iprint_loc, info=info_loc) ! Write the outputs diff --git a/c/prima.c b/c/prima.c index 9e7b671091..ea394c16b7 100644 --- a/c/prima.c +++ b/c/prima.c @@ -7,53 +7,53 @@ int cobyla_c(const int m_nlcon, const prima_objcon calcfc, const int n, double x const int m_ineq, const double Aineq[m_ineq*n], const double bineq[m_ineq], const int m_eq, const double Aeq[m_eq*n], const double beq[m_eq], const double xl[n], const double xu[n], - int *nf, const double rhobeg, const double rhoend, const int maxfun, const int iprint, int *info); + 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 int n, double x[n], double *f, const double xl[n], const double xu[n], - int *nf, const double rhobeg, const double rhoend, const int maxfun, const int iprint, int *info); + int *nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int iprint, int *info); int newuoa_c(prima_obj calfun, const int n, double x[n], double *f, - int *nf, const double rhobeg, const double rhoend, const int maxfun, const int iprint, int *info); + int *nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int iprint, int *info); int uobyqa_c(prima_obj calfun, const int n, double x[n], double *f, - int *nf, const double rhobeg, const double rhoend, const int maxfun, const int iprint, int *info); + 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 int n, double x[n], double *f, double *cstrv, const int m_ineq, const double Aineq[m_ineq*n], const double bineq[m_ineq], const int m_eq, const double Aeq[m_eq*n], const double beq[m_eq], const double xl[n], const double xu[n], - int *nf, const double rhobeg, const double rhoend, const int maxfun, const int iprint, int *info); + int *nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int iprint, int *info); /* these functions just call the fortran compatibility layer and return the status code */ int prima_cobyla(const int m_nlcon, const prima_objcon calcfc, const int n, double x[n], double *f, double *cstrv, double nlconstr[m_nlcon], const int m_ineq, const double Aineq[m_ineq*n], const double bineq[m_ineq], const int m_eq, const double Aeq[m_eq*n], const double beq[m_eq], const double xl[n], const double xu[n], - int *nf, const double rhobeg, const double rhoend, const int maxfun, const int iprint) + int *nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int iprint) { int info = 0; - cobyla_c(m_nlcon, calcfc, n, x, f, cstrv, nlconstr, m_ineq, Aineq, bineq, m_eq, Aeq, beq, xl, xu, nf, rhobeg, rhoend, maxfun, iprint, &info); + cobyla_c(m_nlcon, calcfc, n, x, f, cstrv, nlconstr, m_ineq, Aineq, bineq, m_eq, Aeq, beq, xl, xu, nf, rhobeg, rhoend, ftarget, maxfun, iprint, &info); return info; } int prima_bobyqa(const prima_obj calfun, const int n, double x[n], double *f, const double xl[n], const double xu[n], - int *nf, const double rhobeg, const double rhoend, const int maxfun, const int iprint) + int *nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int iprint) { int info = 0; - bobyqa_c(calfun, n, x, f, xl, xu, nf, rhobeg, rhoend, maxfun, iprint, &info); + bobyqa_c(calfun, n, x, f, xl, xu, nf, rhobeg, rhoend, ftarget, maxfun, iprint, &info); return info; } int prima_newuoa(const prima_obj calfun, const int n, double x[n], double *f, - int *nf, const double rhobeg, const double rhoend, const int maxfun, const int iprint) + int *nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int iprint) { int info = 0; - newuoa_c(calfun, n, x, f, nf, rhobeg, rhoend, maxfun, iprint, &info); + newuoa_c(calfun, n, x, f, nf, rhobeg, rhoend, ftarget, maxfun, iprint, &info); return info; } int prima_uobyqa(const prima_obj calfun, const int n, double x[n], double *f, - int *nf, const double rhobeg, const double rhoend, const int maxfun, const int iprint) + int *nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int iprint) { int info = 0; - uobyqa_c(calfun, n, x, f, nf, rhobeg, rhoend, maxfun, iprint, &info); + uobyqa_c(calfun, n, x, f, nf, rhobeg, rhoend, ftarget, maxfun, iprint, &info); return info; } @@ -61,10 +61,10 @@ int prima_lincoa(const prima_obj calfun, const int n, double x[n], double *f, do const int m_ineq, const double Aineq[m_ineq*n], const double bineq[m_ineq], const int m_eq, const double Aeq[m_eq*n], const double beq[m_eq], const double xl[n], const double xu[n], - int *nf, const double rhobeg, const double rhoend, const int maxfun, const int iprint) + int *nf, const double rhobeg, const double rhoend, const double ftarget, const int maxfun, const int iprint) { int info = 0; - lincoa_c(calfun, n, x, f, cstrv, m_ineq, Aineq, bineq, m_eq, Aeq, beq, xl, xu, nf, rhobeg, rhoend, maxfun, iprint, &info); + lincoa_c(calfun, n, x, f, cstrv, m_ineq, Aineq, bineq, m_eq, Aeq, beq, xl, xu, nf, rhobeg, rhoend, ftarget, maxfun, iprint, &info); return info; } diff --git a/c/tests/t_large.c b/c/tests/t_large.c index 52504cf4a1..240f1f446e 100644 --- a/c/tests/t_large.c +++ b/c/tests/t_large.c @@ -85,6 +85,7 @@ int main(int argc, char * argv[]) double *beq = NULL; const double rhobeg = 1.0; const double rhoend = 1e-7; + const double ftarget = -INFINITY; const int iprint = PRIMA_MSG_RHO; const int maxfun = 500*n_max; @@ -105,29 +106,29 @@ int main(int argc, char * argv[]) if(strcmp(algo, "bobyqa") == 0) { n = 1600; - rc = prima_bobyqa(&fun, n, x, &f, xl, xu, &nf, rhobeg, rhoend, maxfun, iprint); + rc = prima_bobyqa(&fun, n, x, &f, xl, xu, &nf, rhobeg, rhoend, ftarget, maxfun, iprint); } else if(strcmp(algo, "cobyla") == 0) { n = 800; m_ineq = 800; - rc = prima_cobyla(m_nlcon, &fun_con, n, x, &f, &cstrv, nlconstr, m_ineq, Aineq, bineq, m_eq, Aeq, beq, xl, xu, &nf, rhobeg, rhoend, 8000, iprint); + rc = prima_cobyla(m_nlcon, &fun_con, n, x, &f, &cstrv, nlconstr, m_ineq, Aineq, bineq, m_eq, Aeq, beq, xl, xu, &nf, rhobeg, rhoend, ftarget, 8000, iprint); } else if(strcmp(algo, "lincoa") == 0) { n = 1000; m_ineq = 1000; - rc = prima_lincoa(&fun, n, x, &f, &cstrv, m_ineq, Aineq, bineq, m_eq, Aeq, beq, xl, xu, &nf, rhobeg, rhoend, maxfun, iprint); + rc = prima_lincoa(&fun, n, x, &f, &cstrv, m_ineq, Aineq, bineq, m_eq, Aeq, beq, xl, xu, &nf, rhobeg, rhoend, ftarget, maxfun, iprint); } else if(strcmp(algo, "newuoa") == 0) { n = 1600; - rc = prima_newuoa(&fun, n, x, &f, &nf, rhobeg, rhoend, maxfun, iprint); + rc = prima_newuoa(&fun, n, x, &f, &nf, rhobeg, rhoend, ftarget, maxfun, iprint); } else if(strcmp(algo, "uobyqa") == 0) { n = 160; - rc = prima_uobyqa(&fun, n, x, &f, &nf, rhobeg, rhoend, maxfun, iprint); + rc = prima_uobyqa(&fun, n, x, &f, &nf, rhobeg, rhoend, ftarget, maxfun, iprint); } else { diff --git a/c/uobyqa_c.f90 b/c/uobyqa_c.f90 index 11edee4ca4..5ac90585ba 100644 --- a/c/uobyqa_c.f90 +++ b/c/uobyqa_c.f90 @@ -12,7 +12,7 @@ module uobyqa_c_mod contains -subroutine uobyqa_c(cobj_ptr, n, x, f, nf, rhobeg, rhoend, maxfun, iprint, info) bind(C) +subroutine uobyqa_c(cobj_ptr, n, x, f, nf, rhobeg, rhoend, ftarget, maxfun, iprint, info) bind(C) use, intrinsic :: iso_c_binding, only : C_DOUBLE, C_INT, C_FUNPTR use, non_intrinsic :: cintrf_mod, only : COBJ use, non_intrinsic :: consts_mod, only : RP, IK @@ -31,6 +31,7 @@ subroutine uobyqa_c(cobj_ptr, n, x, f, nf, rhobeg, rhoend, maxfun, iprint, info) integer(C_INT), intent(out) :: nf real(C_DOUBLE), intent(in), value :: rhobeg real(C_DOUBLE), intent(in), value :: rhoend +real(C_DOUBLE), intent(in), value :: ftarget integer(C_INT), intent(in), value :: maxfun integer(C_INT), intent(in), value :: iprint integer(C_INT), intent(out) :: info @@ -43,17 +44,19 @@ subroutine uobyqa_c(cobj_ptr, n, x, f, nf, rhobeg, rhoend, maxfun, iprint, info) real(RP) :: f_loc real(RP) :: rhobeg_loc real(RP) :: rhoend_loc +real(RP) :: ftarget_loc real(RP) :: x_loc(n) ! Read the inputs and convert them to the Fortran side types x_loc = real(x, kind(x_loc)) rhobeg_loc = real(rhobeg, kind(rhobeg)) rhoend_loc = real(rhoend, kind(rhoend)) +ftarget_loc = real(ftarget, kind(ftarget)) maxfun_loc = int(maxfun, kind(maxfun_loc)) iprint_loc = int(iprint, kind(iprint_loc)) ! Call the Fortran code -call uobyqa(calfun, x_loc, f_loc, nf=nf_loc, rhobeg=rhobeg_loc, rhoend=rhoend_loc, & +call uobyqa(calfun, x_loc, f_loc, nf=nf_loc, rhobeg=rhobeg_loc, rhoend=rhoend_loc, ftarget=ftarget_loc, & & maxfun=maxfun_loc, iprint=iprint_loc, info=info_loc) ! Write the outputs