Skip to content

Commit

Permalink
mpc bug test
Browse files Browse the repository at this point in the history
  • Loading branch information
bodono committed Jun 28, 2024
1 parent 91a982e commit 6913906
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
Binary file added test/problems/mpc_bug
Binary file not shown.
8 changes: 8 additions & 0 deletions test/problems/mpc_bug.h
Original file line number Diff line number Diff line change
@@ -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);
}
18 changes: 16 additions & 2 deletions test/problems/test_prob_from_data_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,34 @@ 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";
}

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);

Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions test/run_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down

0 comments on commit 6913906

Please sign in to comment.