Skip to content

Commit

Permalink
230916.003039.HKT modify the c examples: set maxfun=200*n, remove t…
Browse files Browse the repository at this point in the history
…he initialization of `nf`, correct the printing of `eval` in lincoa, rename `t_large.c` to `stress.c`, revise `maxfun` for cobyla in the stress test
  • Loading branch information
zaikunzhang committed Sep 15, 2023
1 parent 888e185 commit eb5707c
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 23 deletions.
5 changes: 3 additions & 2 deletions c/examples/bobyqa/bobyqa_example.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// An example to illustrate the use of BOBYQA.

#include "prima/prima.h"
#include <stdio.h>
#include <math.h>
Expand All @@ -22,9 +24,8 @@ int main(int argc, char * argv[])
const double rhoend = 1e-3;
const double ftarget = -INFINITY;
const int iprint = PRIMA_MSG_EXIT;
const int maxfun = 1000;
const int maxfun = 200*n;
const int npt = 2*n+1;
int nf = 0;
const int rc = prima_bobyqa(&fun, n, x, &f, xl, xu, &nf, rhobeg, rhoend, ftarget, maxfun, npt, 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);
Expand Down
5 changes: 3 additions & 2 deletions c/examples/cobyla/cobyla_example.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// An example to illustrate the use of COBYLA.

#include "prima/prima.h"
#include <stdio.h>
#include <math.h>
Expand Down Expand Up @@ -37,8 +39,7 @@ int main(int argc, char * argv[])
const double rhoend = 1e-3;
const double ftarget = -INFINITY;
const int iprint = PRIMA_MSG_EXIT;
const int maxfun = 1000;
int nf = 0;
const int maxfun = 200*n;
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);
Expand Down
7 changes: 4 additions & 3 deletions c/examples/lincoa/lincoa_example.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// An example to illustrate the use of LINCOA.

#include "prima/prima.h"
#include <stdio.h>
#include <math.h>
Expand Down Expand Up @@ -34,11 +36,10 @@ int main(int argc, char * argv[])
const double rhoend = 1e-3;
const double ftarget = -INFINITY;
const int iprint = PRIMA_MSG_EXIT;
const int maxfun = 100000;
const int maxfun = 200*n;
const int npt = 2*n+1;
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, ftarget, maxfun, npt, 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);
printf("x*={%g, %g} f*=%g cstrv=%g rc=%d msg='%s' evals=%d\n", x[0], x[1], f, cstrv, rc, msg, nf);
return (fabs(x[0]-3)>2e-2 || fabs(x[1]-2)>2e-2);
}
5 changes: 3 additions & 2 deletions c/examples/newuoa/newuoa_example.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// An example to illustrate the use of NEWUOA.

#include "prima/prima.h"
#include <stdio.h>
#include <math.h>
Expand All @@ -20,9 +22,8 @@ int main(int argc, char * argv[])
const double rhoend = 1e-3;
const double ftarget = -INFINITY;
const int iprint = PRIMA_MSG_EXIT;
const int maxfun = 1000;
const int maxfun = 200*n;
const int npt = 2*n+1;
int nf = 0;
const int rc = prima_newuoa(&fun, n, x, &f, &nf, rhobeg, rhoend, ftarget, maxfun, npt, 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);
Expand Down
5 changes: 3 additions & 2 deletions c/examples/uobyqa/uobyqa_example.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// An example to illustrate the use of UOBYQA.

#include "prima/prima.h"
#include <stdio.h>
#include <math.h>
Expand All @@ -20,8 +22,7 @@ int main(int argc, char * argv[])
const double rhoend = 1e-3;
const double ftarget = -INFINITY;
const int iprint = PRIMA_MSG_EXIT;
const int maxfun = 1000;
int nf = 0;
const int maxfun = 200*n;
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);
Expand Down
20 changes: 10 additions & 10 deletions c/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
add_executable(t_large EXCLUDE_FROM_ALL t_large.c)
add_executable(stress EXCLUDE_FROM_ALL stress.c)
if (PRIMA_ENABLE_TESTING)
set_target_properties (t_large PROPERTIES EXCLUDE_FROM_ALL FALSE)
set_target_properties (stress PROPERTIES EXCLUDE_FROM_ALL FALSE)
endif ()
if (WIN32)
set_target_properties(t_large PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set_target_properties(stress PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
endif()
add_dependencies(tests t_large)
add_dependencies(tests stress)

add_test(NAME bobyqa_large_c COMMAND t_large bobyqa)
add_test(NAME cobyla_large_c COMMAND t_large cobyla)
add_test(NAME lincoa_large_c COMMAND t_large lincoa)
add_test(NAME newuoa_large_c COMMAND t_large newuoa)
add_test(NAME uobyqa_large_c COMMAND t_large uobyqa)
target_link_libraries(t_large PRIVATE primac)
add_test(NAME bobyqa_large_c COMMAND stress bobyqa)
add_test(NAME cobyla_large_c COMMAND stress cobyla)
add_test(NAME lincoa_large_c COMMAND stress lincoa)
add_test(NAME newuoa_large_c COMMAND stress newuoa)
add_test(NAME uobyqa_large_c COMMAND stress uobyqa)
target_link_libraries(stress PRIVATE primac)
6 changes: 4 additions & 2 deletions c/tests/t_large.c → c/tests/stress.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// A stress test on excessively large problems.

#include "prima/prima.h"
#include <stdio.h>
#include <math.h>
Expand Down Expand Up @@ -60,7 +62,7 @@ int main(int argc, char * argv[])
if (argc > 2)
debug = (strcmp(argv[2], "debug") == 0);
printf("debug=%d\n", debug);

// set seed to year/week
char buf[10] = {0};
time_t t = time(NULL);
Expand Down Expand Up @@ -112,7 +114,7 @@ int main(int argc, char * argv[])
{
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, ftarget, 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, maxfun, iprint);
}
else if(strcmp(algo, "lincoa") == 0)
{
Expand Down

0 comments on commit eb5707c

Please sign in to comment.