1 #include "glbopts.h"
2 #include "minunit.h"
3 #include "problem_utils.h"
4 #include "scs.h"
5 #include "util.h"
6 
small_lp(void)7 static const char *small_lp(void) {
8   ScsCone *k = (ScsCone *)scs_calloc(1, sizeof(ScsCone));
9   ScsData *d = (ScsData *)scs_calloc(1, sizeof(ScsData));
10   ScsSettings *stgs = (ScsSettings *)scs_calloc(1, sizeof(ScsSettings));
11   ScsSolution *sol = (ScsSolution *)scs_calloc(1, sizeof(ScsSolution));
12   ScsSolution *opt_sol = (ScsSolution *)scs_calloc(1, sizeof(ScsSolution));
13   ScsInfo info = {0};
14   scs_float p_f = 0.1;
15   int seed = 1234;
16   scs_int n = 100;
17   scs_int m = 300;
18   scs_int col_nnz = (scs_int)ceil(sqrt(n));
19   scs_int nnz = n * col_nnz;
20   scs_int exitflag;
21   scs_float perr, derr;
22   scs_int success;
23   const char *fail;
24 
25   k->z = (scs_int)floor(m * p_f);
26   k->l = m - k->z;
27 
28   d->m = m;
29   d->n = n;
30   gen_random_prob_data(nnz, col_nnz, d, k, opt_sol, seed);
31   SCS(set_default_settings)(stgs);
32   stgs->eps_abs = 1e-5;
33   stgs->eps_rel = 1e-5;
34 
35   exitflag = scs(d, k, stgs, sol, &info);
36 
37   perr = SCS(dot)(d->c, sol->x, d->n) - SCS(dot)(d->c, opt_sol->x, d->n);
38   derr = -SCS(dot)(d->b, sol->y, d->m) + SCS(dot)(d->b, opt_sol->y, d->m);
39   scs_printf("true obj %4e\n", SCS(dot)(d->c, opt_sol->x, d->n));
40   scs_printf("primal obj error %4e\n", perr);
41   scs_printf("dual obj error %4e\n", derr);
42 
43   success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
44 
45   mu_assert("small_lp: SCS failed to produce outputflag SCS_SOLVED", success);
46   fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
47   SCS(free_data)(d, k, stgs);
48   SCS(free_sol)(sol);
49   SCS(free_sol)(opt_sol);
50   return fail;
51 }
52