QPALM 1.0.0
Proximal Augmented Lagrangian method for Quadratic Programs
scaling.c
Go to the documentation of this file.
1/**
2 * @file scaling.c
3 * @author Ben Hermans
4 * @brief Problem data scaling during setup.
5 * @details This file includes the routine that is called during setup to scale the problem data,
6 * and initial guesses if the problem is warm-started. Scaling the problem is useful to prevent
7 * large changes in the active set and to guard against ill-conditioning in the objective function.
8 *
9 */
10
11
12# ifdef __cplusplus
13extern "C" {
14# endif // ifdef __cplusplus
15
16#include <stdio.h>
17#include "scaling.h"
18#include "lin_alg.h"
19#include "ladel.h"
20
21// Set values lower than threshold MIN_SCALING to 1
22void limit_scaling(c_float *D, size_t n)
23{
24 size_t i;
25
26 for (i = 0; i < n; i++) {
27 D[i] = D[i] < MIN_SCALING ? 1.0 : D[i];
28 }
29}
30
32{
33 size_t n = work->data->n;
34 size_t m = work->data->m;
35 vec_set_scalar(work->scaling->D, 1, n);
36 vec_set_scalar(work->scaling->E, 1, m);
37
38 c_int i;
39 //Ruiz on constraint matrix A
40 for (i = 0; i < work->settings->scaling; i++) {
41
42 // Set D_temp = vecnorm(A,inf,1) (cols) and E_temp = vecnorm(A,inf,2) (rows)
43 mat_inf_norm_cols(work->data->A, work->D_temp);
44 mat_inf_norm_rows(work->data->A, work->E_temp);
45
46 // Set to 1 values with 0 norms (avoid crazy scaling)
47 limit_scaling(work->D_temp, n);
48 limit_scaling(work->E_temp, m);
49
50 // Take square root of norms
51 vec_ew_sqrt(work->D_temp, work->D_temp, n);
52 vec_ew_sqrt(work->E_temp, work->E_temp, m);
53
54 // 1./D and 1./E
55 vec_ew_recipr(work->D_temp, work->D_temp, n);
56 vec_ew_recipr(work->E_temp, work->E_temp, m);
57
58 // Equilibrate matrix A
59 // A <- EAD
60
61 ladel_scale_rows(work->data->A, work->solver->E_temp);
62 ladel_scale_columns(work->data->A, work->solver->D_temp);
63 // Update equilibration matrices D and E
64 vec_ew_prod(work->scaling->D, work->D_temp, work->scaling->D, n);
65 vec_ew_prod(work->scaling->E, work->E_temp, work->scaling->E, m);
66 }
67
68 // Equilibrate matrix Q and vector q
69 // Q <- cDQD, q <- cDq
70 vec_ew_prod(work->scaling->D, work->data->q, work->data->q, n);
71 vec_ew_prod(work->scaling->D, work->Qx, work->Qx, n);
72 prea_vec_copy(work->scaling->D, work->D_temp, n);
73 // vec_add_scaled(work->Qx, work->data->q, work->dphi, 1, n);
74 // work->scaling->c = 1/c_max(1.0, vec_norm_inf(work->dphi, n));
75 work->scaling->c = 1/c_max(1.0, vec_norm_inf(work->data->q, n));
76 vec_self_mult_scalar(work->data->q, work->scaling->c, n);
77 vec_self_mult_scalar(work->Qx, work->scaling->c, n);
78
79 ladel_scale_columns(work->data->Q, work->solver->D_temp);
80 ladel_scale_rows(work->data->Q, work->solver->D_temp);
81 ladel_scale_scalar(work->data->Q, work->scaling->c);
82
83 // Store cinv, Dinv, Einv
84 vec_ew_recipr(work->scaling->D, work->scaling->Dinv, n);
85 vec_ew_recipr(work->scaling->E, work->scaling->Einv, m);
86 work->scaling->cinv = (c_float) 1.0/work->scaling->c;
87
88 // Scale problem vectors l, u
89 vec_ew_prod(work->scaling->E, work->data->bmin, work->data->bmin, m);
90 vec_ew_prod(work->scaling->E, work->data->bmax, work->data->bmax, m);
91
92 // Scale initial vectors x, Ax and y (Qx already scaled)
93 vec_ew_prod(work->x, work->scaling->Dinv, work->x, n);
94 vec_ew_prod(work->Ax, work->scaling->E, work->Ax, m);
95 vec_ew_prod(work->y, work->scaling->E, work->y, m);
96 vec_self_mult_scalar(work->y, work->scaling->cinv, m);
97}
98
100{
101 size_t n = work->data->n;
102 size_t m = work->data->m;
103 if (work->settings->scaling)
104 {
105 // A (was scaled to EAD)
106 ladel_scale_rows(work->data->A, work->scaling->Einv);
107 ladel_scale_columns(work->data->A, work->scaling->Dinv);
108
109 // Q (was scaled to cDQD)
110 ladel_scale_columns(work->data->Q, work->scaling->Dinv);
111 ladel_scale_rows(work->data->Q, work->scaling->Dinv);
112 ladel_scale_scalar(work->data->Q, work->scaling->cinv);
113
114 // q (was scaled to cDq)
115 vec_ew_prod(work->scaling->Dinv, work->data->q, work->data->q, n);
116 vec_self_mult_scalar(work->data->q, work->scaling->cinv, n);
117
118 // bmin/bmax (was scaled to Ebmin/Ebmax)
119 vec_ew_prod(work->scaling->Einv, work->data->bmin, work->data->bmin, m);
120 vec_ew_prod(work->scaling->Einv, work->data->bmax, work->data->bmax, m);
121 }
122}
123
124
125# ifdef __cplusplus
126}
127# endif // ifdef __cplusplus
#define MIN_SCALING
Minimum scaling value/‍**< minimum scaling value *‍/.
Definition: constants.h:84
ladel_int c_int
type for integer numbers
Definition: global_opts.h:42
ladel_double c_float
type for floating point numbers
Definition: global_opts.h:41
#define c_max(a, b)
maximum of two values
Definition: global_opts.h:92
Linear algebra with vectors.
void vec_set_scalar(c_float *a, c_float sc, size_t n)
Fill float vector with a scalar value.
Definition: lin_alg.c:40
void vec_self_mult_scalar(c_float *a, c_float sc, size_t n)
Mulitply vector with a constant scale factor.
Definition: lin_alg.c:56
void vec_ew_prod(const c_float *a, const c_float *b, c_float *c, size_t n)
Elementwise product, .
Definition: lin_alg.c:92
void prea_vec_copy(const c_float *a, c_float *b, size_t n)
Copy vector a into preallocated vector b.
Definition: lin_alg.c:24
c_float vec_norm_inf(const c_float *a, size_t n)
Infinity norm of a vector, .
Definition: lin_alg.c:126
void vec_ew_recipr(const c_float *a, c_float *b, size_t n)
Elementwise reciprocal .
Definition: lin_alg.c:176
void vec_ew_sqrt(const c_float *a, c_float *b, size_t n)
Elementwise square root, .
Definition: lin_alg.c:208
void scale_data(QPALMWorkspace *work)
Scale problem matrices.
Definition: scaling.c:31
void limit_scaling(c_float *D, size_t n)
Definition: scaling.c:22
void unscale_data(QPALMWorkspace *work)
Unscale the problem data.
Definition: scaling.c:99
Problem data scaling during setup.
#define mat_inf_norm_rows
#define mat_inf_norm_cols
size_t m
number of constraints m
Definition: types.h:104
c_float * bmin
dense array for lower bounds (size m)
Definition: types.h:109
size_t n
number of variables n
Definition: types.h:103
c_float * q
dense array for linear part of cost function (size n)
Definition: types.h:107
solver_sparse * A
sparse linear constraints matrix A (size m x n)
Definition: types.h:106
c_float * bmax
dense array for upper bounds (size m)
Definition: types.h:110
solver_sparse * Q
sparse quadratic part of the cost Q (size n x n)
Definition: types.h:105
c_float * Dinv
primal variable rescaling
Definition: types.h:63
c_float c
objective scaling
Definition: types.h:66
c_float * E
dual variable scaling
Definition: types.h:64
c_float * Einv
dual variable rescaling
Definition: types.h:65
c_float cinv
objective rescaling
Definition: types.h:67
c_float * D
primal variable scaling
Definition: types.h:62
c_int scaling
scaling iterations, if 0 then scaling is disabled
Definition: types.h:135
solver_dense * E_temp
temporary constraints scaling vectors
Definition: types.h:166
solver_dense * D_temp
temporary primal variable scaling vectors
Definition: types.h:167
QPALM Workspace.
Definition: types.h:197
c_float * x
primal iterate
Definition: types.h:204
c_float * y
dual iterate
Definition: types.h:205
QPALMScaling * scaling
scaling vectors
Definition: types.h:306
c_float * D_temp
temporary primal variable scaling vectors
Definition: types.h:299
c_float * Ax
scaled A * x
Definition: types.h:206
c_float * Qx
scaled Q * x
Definition: types.h:207
QPALMSettings * settings
problem settings
Definition: types.h:305
c_float * E_temp
temporary constraints scaling vectors
Definition: types.h:300
QPALMSolver * solver
linsys variables
Definition: types.h:304
QPALMData * data
problem data to work on (possibly scaled)
Definition: types.h:198