Skip to content

Commit

Permalink
Merge 7bed3c6 into 429e140
Browse files Browse the repository at this point in the history
  • Loading branch information
bodono committed Oct 1, 2021
2 parents 429e140 + 7bed3c6 commit 620ef6d
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 16 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<img src="https://github.com/cvxgrp/scs/blob/master/docs/src/_static/scs_logo.png" alt="Intersection of a cone and a polyhedron" width="450">
</h1>

![Build Status](https://github.com/cvxgrp/scs/actions/workflows/build.yml/badge.svg)
[![Build Status](https://github.com/cvxgrp/scs/actions/workflows/build.yml/badge.svg)](https://github.com/cvxgrp/scs/actions/workflows/build.yml)
[![Code coverage](https://coveralls.io/repos/github/cvxgrp/scs/badge.svg?branch=master)](https://coveralls.io/github/cvxgrp/scs?branch=master)


SCS (`splitting conic solver`) is a numerical optimization package for solving
large-scale convex cone problems. The current version is `3.0.0`.
Expand Down
17 changes: 9 additions & 8 deletions src/cones.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,11 @@ static scs_int is_simple_semi_definite_cone(scs_int *s, scs_int ssize) {

static scs_float exp_newton_one_d(scs_float rho, scs_float y_hat,
scs_float z_hat, scs_float w) {
scs_float t = MAX(w - z_hat, MAX(-z_hat, 1e-9));
scs_float f, fp;
scs_float t_prev, t = MAX(w - z_hat, MAX(-z_hat, 1e-9));
scs_float f = 1., fp = 1.;
scs_int i;
for (i = 0; i < EXP_CONE_MAX_ITERS; ++i) {
t_prev = t;
f = t * (t + z_hat) / rho / rho - y_hat / rho + log(t / rho) + 1;
fp = (2 * t + z_hat) / rho / rho + 1 / t;

Expand All @@ -308,17 +309,18 @@ static scs_float exp_newton_one_d(scs_float rho, scs_float y_hat,
} else if (t <= 0) {
t = 0;
break;
} else if (ABS(t - t_prev) < CONE_TOL) {
break;
} else if (SQRTF(f * f / fp) < CONE_TOL) {
break;
}
}
/* #if VERBOSITY > 1 */
if (i == EXP_CONE_MAX_ITERS) {
scs_printf("warning: exp cone newton step hit maximum %i iters\n", (int)i);
scs_printf("rho=%1.5e; y_hat=%1.5e; z_hat=%1.5e; w=%1.5e\n", rho, y_hat,
z_hat, w);
scs_printf("rho=%1.5e; y_hat=%1.5e; z_hat=%1.5e; w=%1.5e; f=%1.5e, "
"fp=%1.5e, t=%1.5e, t_prev= %1.5e\n",
rho, y_hat, z_hat, w, f, fp, t, t_prev);
}
/* #endif */
return t + z_hat;
}

Expand Down Expand Up @@ -353,7 +355,6 @@ static scs_int proj_exp_cone(scs_float *v) {
scs_int i;
scs_float ub, lb, rho, g, x[3];
scs_float r = v[0], s = v[1], t = v[2];
scs_float tol = CONE_TOL;

/* v in cl(Kexp) */
if ((s * exp(r / s) - t <= CONE_THRESH && s > 0) ||
Expand Down Expand Up @@ -385,7 +386,7 @@ static scs_int proj_exp_cone(scs_float *v) {
} else {
ub = rho;
}
if (ub - lb < tol) {
if (ub - lb < CONE_TOL) {
break;
}
}
Expand Down
14 changes: 7 additions & 7 deletions test/problem_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ const char *verify_solution_correct(ScsData *d, ScsCone *k, ScsSettings *stgs,
/**************** ASSERTS *****************/
if (status == SCS_SOLVED) {
mu_assert_less("Primal residual ERROR", ABS(res_pri - info->res_pri),
1e-14);
1e-12);
mu_assert_less("Dual residual ERROR", ABS(res_dual - info->res_dual),
1e-14);
mu_assert_less("Gap ERROR", ABS(gap - info->gap), 1e-14);
mu_assert_less("Primal obj ERROR", ABS(pobj - info->pobj), 1e-14);
mu_assert_less("Dual obj ERROR", ABS(dobj - info->dobj), 1e-14);
1e-12);
mu_assert_less("Gap ERROR", ABS(gap - info->gap), 1e-12);
mu_assert_less("Primal obj ERROR", ABS(pobj - info->pobj), 1e-12);
mu_assert_less("Dual obj ERROR", ABS(dobj - info->dobj), 1e-12);
/* slightly looser tol */
mu_assert_less("Complementary slackness ERROR", ABS(sty), 1e-6);
mu_assert_less("s cone dist ERROR", ABS(sdist), 1e-6);
Expand All @@ -234,14 +234,14 @@ const char *verify_solution_correct(ScsData *d, ScsCone *k, ScsSettings *stgs,

} else if (status == SCS_INFEASIBLE) {
mu_assert_less("Infeas ERROR", ABS(res_infeas - info->res_infeas), 1e-8);
mu_assert_less("bty ERROR", ABS(bty + 1), 1e-14);
mu_assert_less("bty ERROR", ABS(bty + 1), 1e-12);
mu_assert_less("y cone dist ERROR", ABS(ydist), 1e-6);
mu_assert_less("Infeas invalid ERROR", res_infeas, stgs->eps_infeas);

} else if (status == SCS_UNBOUNDED) {
mu_assert_less("Unbdd_a ERROR", ABS(res_unbdd_a - info->res_unbdd_a), 1e-8);
mu_assert_less("Unbdd_p ERROR", ABS(res_unbdd_p - info->res_unbdd_p), 1e-8);
mu_assert_less("ctx ERROR", ABS(ctx + 1), 1e-14);
mu_assert_less("ctx ERROR", ABS(ctx + 1), 1e-12);
mu_assert_less("s cone dist ERROR", ABS(sdist), 1e-6);
mu_assert_less("Unbounded P invalid ERROR", res_unbdd_p, stgs->eps_infeas);
mu_assert_less("Unbounded A invalid ERROR", res_unbdd_a, stgs->eps_infeas);
Expand Down
Binary file added test/problems/random_prob
Binary file not shown.
45 changes: 45 additions & 0 deletions test/problems/random_prob.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "glbopts.h"
#include "minunit.h"
#include "problem_utils.h"
#include "scs.h"
#include "util.h"

static const char *random_prob(void) {
scs_int read_status;
ScsData *d;
ScsCone *k;
ScsSettings *stgs;
ScsSolution *sol;
ScsInfo info = {0};
scs_int exitflag;
scs_float perr, derr;
scs_int success;
const char *fail;

scs_float OPT = 5.751458006385587;

read_status = SCS(read_data)("test/problems/random_prob", &d, &k, &stgs);

if (read_status < 0) {
return "Data read failure, exit.\n";
}

stgs->eps_abs = 1e-6;
stgs->eps_rel = 1e-6;

sol = 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;
scs_printf("primal obj error %4e\n", perr);
scs_printf("dual obj error %4e\n", derr);

success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;

mu_assert("random_prob: SCS failed to produce SCS_SOLVED", success);
fail = verify_solution_correct(d, k, stgs, &info, sol, exitflag);
SCS(free_data)(d, k, stgs);
SCS(free_sol)(sol);
return fail;
}
3 changes: 3 additions & 0 deletions test/run_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "problems/hs21_tiny_qp_rw.h"
#include "problems/infeasible_tiny_qp.h"
#include "problems/qafiro_tiny_qp.h"
#include "problems/random_prob.h"
#include "problems/rob_gauss_cov_est.h"
#include "problems/small_lp.h"
#include "problems/unbounded_tiny_qp.h"
Expand All @@ -34,6 +35,8 @@ static const char *all_tests(void) {
mu_run_test(infeasible_tiny_qp);
scs_printf("unbounded_tiny_qp\n");
mu_run_test(unbounded_tiny_qp);
scs_printf("random_prob\n");
mu_run_test(random_prob);
return 0;
}

Expand Down

0 comments on commit 620ef6d

Please sign in to comment.