SuperSCS  1.3.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
normalize.h
Go to the documentation of this file.
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2017 Pantelis Sopasakis (https://alphaville.github.io),
5  * Krina Menounou (https://www.linkedin.com/in/krinamenounou),
6  * Panagiotis Patrinos (http://homes.esat.kuleuven.be/~ppatrino)
7  * Copyright (c) 2012 Brendan O'Donoghue (bodonoghue85@gmail.com)
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this software and associated documentation files (the "Software"), to deal
11  * in the Software without restriction, including without limitation the rights
12  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  * copies of the Software, and to permit persons to whom the Software is
14  * furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included in all
17  * copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25  * SOFTWARE.
26  *
27  */
28 #ifndef SCS_NORMALIZE_H_GUARD
29 #define SCS_NORMALIZE_H_GUARD
30 
31 #include "scs.h"
32 
33 
34 #define MIN_SCALE (1e-3)
35 #define MAX_SCALE (1e3)
36 
38  scs_int i;
39  scs_float nm, *D = w->scal->D, *E = w->scal->E, *b = w->b, *c = w->c;
40  /* scale b */
41  for (i = 0; i < w->m; ++i) {
42  b[i] /= D[i];
43  }
44  nm = scs_norm(b, w->m);
45  w->sc_b = w->scal->meanNormColA / MAX(nm, MIN_SCALE);
46  /* scale c */
47  for (i = 0; i < w->n; ++i) {
48  c[i] /= E[i];
49  }
50  nm = scs_norm(c, w->n);
51  w->sc_c = w->scal->meanNormRowA / MAX(nm, MIN_SCALE);
52  scs_scale_array(b, w->sc_b * w->stgs->scale, w->m);
53  scs_scale_array(c, w->sc_c * w->stgs->scale, w->n);
54 }
55 
56 /* TENTATIVELY REMOVE THIS FUNCTION
57 void scs_calculate_scaled_residuals(ScsWork *w, struct scs_residuals *r) {
58  scs_float *D = w->scal->D;
59  scs_float *E = w->scal->E;
60  scs_float *u = w->u;
61  scs_float *u_t = w->u_t;
62  scs_float *u_prev = w->u_prev;
63  scs_float tmp;
64  scs_int i, n = w->n, m = w->m;
65 
66  r->res_pri = 0;
67  for (i = 0; i < n; ++i) {
68  tmp = (u[i] - u_t[i]) / (E[i] * w->sc_b);
69  r->res_pri += tmp * tmp;
70  }
71  for (i = 0; i < m; ++i) {
72  tmp = (u[i + n] - u_t[i + n]) / (D[i] * w->sc_c);
73  r->res_pri += tmp * tmp;
74  }
75  tmp = u[n + m] - u_t[n + m];
76  r->res_pri += tmp * tmp;
77  r->res_pri = sqrt(r->res_pri);
78 
79  r->res_dual = 0;
80  for (i = 0; i < n; ++i) {
81  tmp = (u[i] - u_prev[i]) * E[i] / w->sc_b;
82  r->res_dual += tmp * tmp;
83  }
84  for (i = 0; i < m; ++i) {
85  tmp = (u[i + n] - u_prev[i + n]) * D[i] / w->sc_c;
86  r->res_dual += tmp * tmp;
87  }
88  tmp = u[n + m] - u_t[n + m];
89  r->res_dual += tmp * tmp;
90  r->res_dual = sqrt(r->res_dual);
91 }
92 */
93 
95  scs_int i;
96  scs_float *D;
97  scs_float *E;
98  scs_float *x;
99  scs_float *y;
100 
101  D = w->scal->D;
102  E = w->scal->E;
103  if (!w->stgs->do_super_scs) {
104  scs_float *s;
105  x = w->u;
106  y = &(w->u[w->n]);
107  s = &(w->u[w->n]);
108  for (i = 0; i < w->m; ++i) {
109  s[i] /= (D[i] / (w->sc_b * w->stgs->scale));
110  }
111  } else {
112  x = w->u_t;
113  y = &(w->u_t[w->n]);
114  }
115  for (i = 0; i < w->n; ++i) {
116  x[i] *= (E[i] * w->sc_b);
117  }
118  for (i = 0; i < w->m; ++i) {
119  y[i] *= (D[i] * w->sc_c);
120  }
121 }
122 
124  scs_int i;
125  scs_float *D = w->scal->D;
126  scs_float *E = w->scal->E;
127  for (i = 0; i < w->n; ++i) {
128  sol->x[i] /= (E[i] * w->sc_b);
129  }
130  for (i = 0; i < w->m; ++i) {
131  sol->y[i] /= (D[i] * w->sc_c);
132  }
133  for (i = 0; i < w->m; ++i) {
134  sol->s[i] *= D[i] / (w->sc_b * w->stgs->scale);
135  }
136 }
137 
138 #endif
#define MIN_SCALE
Definition: normalize.h:34
scs_int m
Row dimension of .
Definition: scs.h:79
scs_float *RESTRICT c
The (possibly normalized) vector .
Definition: scs.h:142
scs_float scale
Definition: scs.h:313
scs_int do_super_scs
Definition: scs.h:386
void scs_normalize_bc(ScsWork *w)
Definition: normalize.h:37
scs_float sc_c
Scaling factor corresponding to .
Definition: scs.h:212
scs_float *RESTRICT s
Definition: scs.h:530
scs_float *RESTRICT u_t
Vector .
Definition: scs.h:99
scs_float *RESTRICT x
Definition: scs.h:522
void scs_unnormalize_sol(ScsWork *w, ScsSolution *sol)
Definition: normalize.h:123
#define MAX(a, b)
Definition: glbopts.h:123
scs_float meanNormRowA
Definition: scs.h:573
scs_float *RESTRICT *RESTRICT E
Definition: scs.h:572
scs_float *RESTRICT b
The (possibly normalized) vector .
Definition: scs.h:138
int scs_int
Definition: glbopts.h:96
scs_float sc_b
Scaling factor corresponding to .
Definition: scs.h:208
void scs_normalize_warm_start(ScsWork *w)
Definition: normalize.h:94
scs_float meanNormColA
Definition: scs.h:573
double scs_float
Definition: glbopts.h:100
scs_float *RESTRICT u
Vector .
Definition: scs.h:91
Workspace for SCS.
Definition: scs.h:75
scs_float *RESTRICT D
Definition: scs.h:572
scs_float scs_norm(const scs_float *RESTRICT v, scs_int len)
scs_int n
Column dimension of .
Definition: scs.h:83
scs_float *RESTRICT y
Definition: scs.h:526
void scs_scale_array(scs_float *RESTRICT a, const scs_float b, scs_int len)
ScsScaling *RESTRICT scal
contains the re-scaling data
Definition: scs.h:240
Primal-dual solution arrays.
Definition: scs.h:518
ScsSettings *RESTRICT stgs
contains solver settings specified by user
Definition: scs.h:236