vendor/scs/src/rw.c in scs-0.3.2 vs vendor/scs/src/rw.c in scs-0.4.0
- old
+ new
@@ -31,25 +31,33 @@
static ScsCone *read_scs_cone(FILE *fin) {
ScsCone *k = (ScsCone *)scs_calloc(1, sizeof(ScsCone));
fread(&(k->z), sizeof(scs_int), 1, fin);
fread(&(k->l), sizeof(scs_int), 1, fin);
fread(&(k->bsize), sizeof(scs_int), 1, fin);
- k->bl = (scs_float *)scs_calloc(MAX(k->bsize - 1, 0), sizeof(scs_float));
- k->bu = (scs_float *)scs_calloc(MAX(k->bsize - 1, 0), sizeof(scs_float));
- fread(k->bl, sizeof(scs_float), MAX(k->bsize - 1, 0), fin);
- fread(k->bu, sizeof(scs_float), MAX(k->bsize - 1, 0), fin);
+ if (k->bsize > 1) {
+ k->bl = (scs_float *)scs_calloc(MAX(k->bsize - 1, 0), sizeof(scs_float));
+ k->bu = (scs_float *)scs_calloc(MAX(k->bsize - 1, 0), sizeof(scs_float));
+ fread(k->bl, sizeof(scs_float), MAX(k->bsize - 1, 0), fin);
+ fread(k->bu, sizeof(scs_float), MAX(k->bsize - 1, 0), fin);
+ }
fread(&(k->qsize), sizeof(scs_int), 1, fin);
- k->q = (scs_int *)scs_calloc(k->qsize, sizeof(scs_int));
- fread(k->q, sizeof(scs_int), k->qsize, fin);
+ if (k->qsize) {
+ k->q = (scs_int *)scs_calloc(k->qsize, sizeof(scs_int));
+ fread(k->q, sizeof(scs_int), k->qsize, fin);
+ }
fread(&(k->ssize), sizeof(scs_int), 1, fin);
- k->s = (scs_int *)scs_calloc(k->ssize, sizeof(scs_int));
- fread(k->s, sizeof(scs_int), k->ssize, fin);
+ if (k->ssize) {
+ k->s = (scs_int *)scs_calloc(k->ssize, sizeof(scs_int));
+ fread(k->s, sizeof(scs_int), k->ssize, fin);
+ }
fread(&(k->ep), sizeof(scs_int), 1, fin);
fread(&(k->ed), sizeof(scs_int), 1, fin);
fread(&(k->psize), sizeof(scs_int), 1, fin);
- k->p = (scs_float *)scs_calloc(k->psize, sizeof(scs_float));
- fread(k->p, sizeof(scs_float), k->psize, fin);
+ if (k->psize) {
+ k->p = (scs_float *)scs_calloc(k->psize, sizeof(scs_float));
+ fread(k->p, sizeof(scs_float), k->psize, fin);
+ }
return k;
}
static void write_scs_stgs(const ScsSettings *s, FILE *fout) {
/* Warm start to false for now */
@@ -206,13 +214,13 @@
*stgs = read_scs_stgs(fin);
fclose(fin);
return 0;
}
-void SCS(log_data_to_csv)(const ScsData *d, const ScsCone *k,
- const ScsSettings *stgs, const ScsWork *w,
- scs_int iter, SCS(timer) * solve_timer) {
+void SCS(log_data_to_csv)(const ScsCone *k, const ScsSettings *stgs,
+ const ScsWork *w, scs_int iter,
+ SCS(timer) * solve_timer) {
ScsResiduals *r = w->r_orig;
ScsResiduals *r_n = w->r_normalized;
ScsSolution *sol = w->xys_orig;
ScsSolution *sol_n = w->xys_normalized;
/* if iter 0 open to write, else open to append */
@@ -220,11 +228,11 @@
if (!fout) {
scs_printf("Error: Could not open %s for writing\n",
stgs->log_csv_filename);
return;
}
- scs_int l = w->m + w->n + 1;
+ scs_int l = w->d->m + w->d->n + 1;
if (iter == 0) {
/* need to end in comma so that csv parsing is correct */
fprintf(fout, "iter,"
"res_pri,"
"res_dual,"
@@ -284,52 +292,52 @@
}
fprintf(fout, "%li,", (long)iter);
fprintf(fout, "%.16e,", r->res_pri);
fprintf(fout, "%.16e,", r->res_dual);
fprintf(fout, "%.16e,", r->gap);
- fprintf(fout, "%.16e,", SCS(norm_inf)(sol->x, w->n));
- fprintf(fout, "%.16e,", SCS(norm_inf)(sol->y, w->m));
- fprintf(fout, "%.16e,", SCS(norm_inf)(sol->s, w->m));
- fprintf(fout, "%.16e,", SCS(norm_2)(sol->x, w->n));
- fprintf(fout, "%.16e,", SCS(norm_2)(sol->y, w->m));
- fprintf(fout, "%.16e,", SCS(norm_2)(sol->s, w->m));
- fprintf(fout, "%.16e,", SCS(norm_inf)(sol_n->x, w->n));
- fprintf(fout, "%.16e,", SCS(norm_inf)(sol_n->y, w->m));
- fprintf(fout, "%.16e,", SCS(norm_inf)(sol_n->s, w->m));
- fprintf(fout, "%.16e,", SCS(norm_2)(sol_n->x, w->n));
- fprintf(fout, "%.16e,", SCS(norm_2)(sol_n->y, w->m));
- fprintf(fout, "%.16e,", SCS(norm_2)(sol_n->s, w->m));
- fprintf(fout, "%.16e,", SCS(norm_inf)(r->ax_s_btau, w->m));
- fprintf(fout, "%.16e,", SCS(norm_inf)(r->px_aty_ctau, w->n));
- fprintf(fout, "%.16e,", SCS(norm_2)(r->ax_s_btau, w->m));
- fprintf(fout, "%.16e,", SCS(norm_2)(r->px_aty_ctau, w->n));
+ fprintf(fout, "%.16e,", SCS(norm_inf)(sol->x, w->d->n));
+ fprintf(fout, "%.16e,", SCS(norm_inf)(sol->y, w->d->m));
+ fprintf(fout, "%.16e,", SCS(norm_inf)(sol->s, w->d->m));
+ fprintf(fout, "%.16e,", SCS(norm_2)(sol->x, w->d->n));
+ fprintf(fout, "%.16e,", SCS(norm_2)(sol->y, w->d->m));
+ fprintf(fout, "%.16e,", SCS(norm_2)(sol->s, w->d->m));
+ fprintf(fout, "%.16e,", SCS(norm_inf)(sol_n->x, w->d->n));
+ fprintf(fout, "%.16e,", SCS(norm_inf)(sol_n->y, w->d->m));
+ fprintf(fout, "%.16e,", SCS(norm_inf)(sol_n->s, w->d->m));
+ fprintf(fout, "%.16e,", SCS(norm_2)(sol_n->x, w->d->n));
+ fprintf(fout, "%.16e,", SCS(norm_2)(sol_n->y, w->d->m));
+ fprintf(fout, "%.16e,", SCS(norm_2)(sol_n->s, w->d->m));
+ fprintf(fout, "%.16e,", SCS(norm_inf)(r->ax_s_btau, w->d->m));
+ fprintf(fout, "%.16e,", SCS(norm_inf)(r->px_aty_ctau, w->d->n));
+ fprintf(fout, "%.16e,", SCS(norm_2)(r->ax_s_btau, w->d->m));
+ fprintf(fout, "%.16e,", SCS(norm_2)(r->px_aty_ctau, w->d->n));
fprintf(fout, "%.16e,", r->res_infeas);
fprintf(fout, "%.16e,", r->res_unbdd_a);
fprintf(fout, "%.16e,", r->res_unbdd_p);
fprintf(fout, "%.16e,", r->pobj);
fprintf(fout, "%.16e,", r->dobj);
fprintf(fout, "%.16e,", r->tau);
fprintf(fout, "%.16e,", r->kap);
fprintf(fout, "%.16e,", r_n->res_pri);
fprintf(fout, "%.16e,", r_n->res_dual);
fprintf(fout, "%.16e,", r_n->gap);
- fprintf(fout, "%.16e,", SCS(norm_inf)(r_n->ax_s_btau, w->m));
- fprintf(fout, "%.16e,", SCS(norm_inf)(r_n->px_aty_ctau, w->n));
- fprintf(fout, "%.16e,", SCS(norm_2)(r_n->ax_s_btau, w->m));
- fprintf(fout, "%.16e,", SCS(norm_2)(r_n->px_aty_ctau, w->n));
+ fprintf(fout, "%.16e,", SCS(norm_inf)(r_n->ax_s_btau, w->d->m));
+ fprintf(fout, "%.16e,", SCS(norm_inf)(r_n->px_aty_ctau, w->d->n));
+ fprintf(fout, "%.16e,", SCS(norm_2)(r_n->ax_s_btau, w->d->m));
+ fprintf(fout, "%.16e,", SCS(norm_2)(r_n->px_aty_ctau, w->d->n));
fprintf(fout, "%.16e,", r_n->res_infeas);
fprintf(fout, "%.16e,", r_n->res_unbdd_a);
fprintf(fout, "%.16e,", r_n->res_unbdd_p);
fprintf(fout, "%.16e,", r_n->pobj);
fprintf(fout, "%.16e,", r_n->dobj);
fprintf(fout, "%.16e,", r_n->tau);
fprintf(fout, "%.16e,", r_n->kap);
- fprintf(fout, "%.16e,", SCS(norm_inf)(r->ax, w->m));
- fprintf(fout, "%.16e,", SCS(norm_inf)(r->px, w->n));
- fprintf(fout, "%.16e,", SCS(norm_inf)(r->aty, w->n));
- fprintf(fout, "%.16e,", SCS(norm_inf)(w->b_orig, w->m));
- fprintf(fout, "%.16e,", SCS(norm_inf)(w->c_orig, w->n));
- fprintf(fout, "%.16e,", w->scale);
+ fprintf(fout, "%.16e,", SCS(norm_inf)(r->ax, w->d->m));
+ fprintf(fout, "%.16e,", SCS(norm_inf)(r->px, w->d->n));
+ fprintf(fout, "%.16e,", SCS(norm_inf)(r->aty, w->d->n));
+ fprintf(fout, "%.16e,", SCS(norm_inf)(w->b_orig, w->d->m));
+ fprintf(fout, "%.16e,", SCS(norm_inf)(w->c_orig, w->d->n));
+ fprintf(fout, "%.16e,", w->stgs->scale);
fprintf(fout, "%.16e,", SCS(norm_diff)(w->u, w->u_t, l));
fprintf(fout, "%.16e,", SCS(norm_diff)(w->v, w->v_prev, l));
fprintf(fout, "%.16e,", SCS(norm_inf_diff)(w->u, w->u_t, l));
fprintf(fout, "%.16e,", SCS(norm_inf_diff)(w->v, w->v_prev, l));
fprintf(fout, "%.16e,", w->aa_norm);