diff --git a/test/problems/mpc_bug b/test/problems/mpc_bug new file mode 100644 index 00000000..989fbb3e Binary files /dev/null and b/test/problems/mpc_bug differ diff --git a/test/problems/mpc_bug.h b/test/problems/mpc_bug.h new file mode 100644 index 00000000..4782404f --- /dev/null +++ b/test/problems/mpc_bug.h @@ -0,0 +1,8 @@ +#include "glbopts.h" +#include "problems/test_prob_from_data_file.h" +#include "scs.h" + +static const char *mpc_bug(void) { + scs_float OPT = -0.473957794500; /* from scs */ + return _test_prob_from_data("test/problems/mpc_bug", OPT); +} diff --git a/test/problems/test_prob_from_data_file.h b/test/problems/test_prob_from_data_file.h index 5e972bdb..d4ffbae1 100644 --- a/test/problems/test_prob_from_data_file.h +++ b/test/problems/test_prob_from_data_file.h @@ -19,8 +19,11 @@ static const char *_test_prob_from_data(const char *file, scs_float OPT) { scs_float perr, derr; scs_int success; const char *fail; + scs_float xt_p_x; + scs_float *px; read_status = SCS(read_data)(file, &d, &k, &stgs); + px = (scs_float *)scs_calloc(d->n, sizeof(scs_float)); if (read_status < 0) { return "Data read failure, exit.\n"; @@ -28,12 +31,22 @@ static const char *_test_prob_from_data(const char *file, scs_float OPT) { stgs->eps_abs = 1e-6; stgs->eps_rel = 1e-6; + /* Force verbosity for the test */ + stgs->verbose = 1; sol = (ScsSolution *)scs_calloc(1, sizeof(ScsSolution)); exitflag = scs(d, k, stgs, sol, &info); - perr = SCS(dot)(d->c, sol->x, d->n) - OPT; - derr = -SCS(dot)(d->b, sol->y, d->m) - OPT; + if (d->P) { + /* px = Px */ + SCS(accum_by_p)(d->P, sol->x, px); + xt_p_x = SCS(dot)(px, sol->x, n); + } else { + xt_p_x = 0.; + } + + perr = 0.5 * xt_p_x + SCS(dot)(d->c, sol->x, d->n) - OPT; + derr = -0.5 * xt_p_x - SCS(dot)(d->b, sol->y, d->m) - OPT; scs_printf("primal obj error %4e\n", perr); scs_printf("dual obj error %4e\n", derr); @@ -47,6 +60,7 @@ static const char *_test_prob_from_data(const char *file, scs_float OPT) { SCS(free_cone)(k); SCS(free_sol)(sol); scs_free(stgs); + scs_free(px); if (fail) { scs_printf("%s: FAILED\n", file); diff --git a/test/run_tests.c b/test/run_tests.c index 337b5d7a..15094ce7 100644 --- a/test/run_tests.c +++ b/test/run_tests.c @@ -43,9 +43,11 @@ _SKIP(random_prob) #if NO_READ_WRITE == 0 /* reads / writes */ #include "problems/hs21_tiny_qp_rw.h" #include "problems/max_ent.h" +#include "problems/mpc_bug.h" #else _SKIP(hs21_tiny_qp_rw) _SKIP(max_ent) +_SKIP(mpc_bug) #endif static const char *all_tests(void) { @@ -61,6 +63,7 @@ static const char *all_tests(void) { mu_run_test(unbounded_tiny_qp); mu_run_test(random_prob); mu_run_test(max_ent); + mu_run_test(mpc_bug); mu_run_test(test_exp_cone); return 0; }