Debian Codegraph @

external/gsl/gsl_multiroots__gnewton.c

raw symbols SCIP
1 /* multiroots/gnewton.c
2 *
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20 #include "gsl__config.h"cxx . . $ `<file>/external/gsl/gsl__config.h`/
21
22 #include <stddef.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <math.h>
26 #include <float.h>
27
28 #include "gsl_math.h"cxx . . $ `<file>/external/gsl/gsl_math.h`/
29 #include "gsl_errno.h"cxx . . $ `<file>/external/gsl/gsl_errno.h`/
30 #include "gsl_multiroots.h"cxx . . $ `<file>/external/gsl/gsl_multiroots.h`/
31 #include "gsl_linalg.h"cxx . . $ `<file>/external/gsl/gsl_linalg.h`/
32
33 #include "gsl_multiroots__enorm.c"cxx . . $ `<file>/external/gsl/gsl_multiroots__enorm.c`/
34
35 /* Simple globally convergent Newton method (rejects uphill steps) */
36
37 typedef structcxx . . $ $anonymous_type_4d022e410f63cd41_0#
38 {
39 double phicxx . . $ $anonymous_type_4d022e410f63cd41_0#phi.;
40 gsl_vectorcxx . . $ gsl_vector# * x_trialcxx . . $ $anonymous_type_4d022e410f63cd41_0#x_trial.;
41 gsl_vectorcxx . . $ gsl_vector# * dcxx . . $ $anonymous_type_4d022e410f63cd41_0#d.;
42 gsl_matrixcxx . . $ gsl_matrix# * lucxx . . $ $anonymous_type_4d022e410f63cd41_0#lu.;
43 gsl_permutationcxx . . $ gsl_permutation# * permutationcxx . . $ $anonymous_type_4d022e410f63cd41_0#permutation.;
44 }
45 gnewton_state_tcxx . . $ gnewton_state_t#;
46
47 static int gnewton_alloccxx . . $ gnewton_alloc(c0a5f96701d3f89). (void * vstate, size_t n);
48 static int gnewton_setcxx . . $ gnewton_set(36a4c1ecdfe5d338). (void * vstate, gsl_multiroot_function_fdfcxx . . $ gsl_multiroot_function_fdf# * fdf, gsl_vectorcxx . . $ gsl_vector# * x, gsl_vectorcxx . . $ gsl_vector# * f, gsl_matrixcxx . . $ gsl_matrix# * J, gsl_vectorcxx . . $ gsl_vector# * dx);
49 static int gnewton_iteratecxx . . $ gnewton_iterate(36a4c1ecdfe5d338). (void * vstate, gsl_multiroot_function_fdfcxx . . $ gsl_multiroot_function_fdf# * fdf, gsl_vectorcxx . . $ gsl_vector# * x, gsl_vectorcxx . . $ gsl_vector# * f, gsl_matrixcxx . . $ gsl_matrix# * J, gsl_vectorcxx . . $ gsl_vector# * dx);
50 static void gnewton_freecxx . . $ gnewton_free(5d22bdacc48458e8). (void * vstate);
51
52 static int
53 gnewton_alloccxx . . $ gnewton_alloc(c0a5f96701d3f89). (void * vstate, size_t n)
54 {
55 gnewton_state_tcxx . . $ gnewton_state_t# * state = (gnewton_state_tcxx . . $ gnewton_state_t# *) vstate;
56 gsl_vectorcxx . . $ gsl_vector# * d, * x_trial ;
57 gsl_permutationcxx . . $ gsl_permutation# * p;
58 gsl_matrixcxx . . $ gsl_matrix# * m;
59
60 m = gsl_matrix_calloccxx . . $ gsl_matrix_calloc(5a4d020b4836594). (n,n);
61
62 if (m == 0)
63 {
64 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("failed to allocate space for lu", GSL_ENOMEM);
65 }
66
67 state->lucxx . . $ $anonymous_type_4d022e410f63cd41_0#lu. = m ;
68
69 p = gsl_permutation_calloccxx . . $ gsl_permutation_calloc(311f4cfee96dd0e3). (n);
70
71 if (p == 0)
72 {
73 gsl_matrix_freecxx . . $ gsl_matrix_free(ab29a617cccd3636).(m);
74
75 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("failed to allocate space for permutation", GSL_ENOMEM);
76 }
77
78 state->permutationcxx . . $ $anonymous_type_4d022e410f63cd41_0#permutation. = p ;
79
80 d = gsl_vector_calloccxx . . $ gsl_vector_calloc(71d9e095f27e8ea9). (n);
81
82 if (d == 0)
83 {
84 gsl_permutation_freecxx . . $ gsl_permutation_free(bfe6c130f63679fa).(p);
85 gsl_matrix_freecxx . . $ gsl_matrix_free(ab29a617cccd3636).(m);
86
87 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("failed to allocate space for d", GSL_ENOMEM);
88 }
89
90 state->dcxx . . $ $anonymous_type_4d022e410f63cd41_0#d. = d;
91
92 x_trial = gsl_vector_calloccxx . . $ gsl_vector_calloc(71d9e095f27e8ea9). (n);
93
94 if (x_trial == 0)
95 {
96 gsl_vector_freecxx . . $ gsl_vector_free(5d65852ca0326259).(d);
97 gsl_permutation_freecxx . . $ gsl_permutation_free(bfe6c130f63679fa).(p);
98 gsl_matrix_freecxx . . $ gsl_matrix_free(ab29a617cccd3636).(m);
99
100 GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("failed to allocate space for x_trial", GSL_ENOMEM);
101 }
102
103 state->x_trialcxx . . $ $anonymous_type_4d022e410f63cd41_0#x_trial. = x_trial;
104
105 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
106 }
107
108
109 static int
110 gnewton_setcxx . . $ gnewton_set(36a4c1ecdfe5d338). (void * vstate, gsl_multiroot_function_fdfcxx . . $ gsl_multiroot_function_fdf# * FDF, gsl_vectorcxx . . $ gsl_vector# * x, gsl_vectorcxx . . $ gsl_vector# * f, gsl_matrixcxx . . $ gsl_matrix# * J, gsl_vectorcxx . . $ gsl_vector# * dx)
111 {
112 gnewton_state_tcxx . . $ gnewton_state_t# * state = (gnewton_state_tcxx . . $ gnewton_state_t# *) vstate;
113 size_t i, n = FDF->ncxx . . $ gsl_multiroot_function_fdf_struct#n. ;
114
115 GSL_MULTIROOT_FN_EVAL_F_DFcxx . . $ `external/gsl/gsl_multiroots.h:114:9`! (FDF, x, f, J);
116
117 for (i = 0; i < n; i++)
118 {
119 gsl_vector_setcxx . . $ gsl_vector_set(c35f863a529e8fae). (dx, i, 0.0);
120 }
121
122 state->phicxx . . $ $anonymous_type_4d022e410f63cd41_0#phi. = enormcxx . . $ enorm(1b712e435b5359e9).(f);
123
124 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
125 }
126
127 static int
128 gnewton_iteratecxx . . $ gnewton_iterate(36a4c1ecdfe5d338). (void * vstate, gsl_multiroot_function_fdfcxx . . $ gsl_multiroot_function_fdf# * fdf, gsl_vectorcxx . . $ gsl_vector# * x, gsl_vectorcxx . . $ gsl_vector# * f, gsl_matrixcxx . . $ gsl_matrix# * J, gsl_vectorcxx . . $ gsl_vector# * dx)
129 {
130 gnewton_state_tcxx . . $ gnewton_state_t# * state = (gnewton_state_tcxx . . $ gnewton_state_t# *) vstate;
131
132 int signum ;
133 double t, phi0, phi1;
134
135 size_t i;
136
137 size_t n = fdf->ncxx . . $ gsl_multiroot_function_fdf_struct#n. ;
138
139 gsl_matrix_memcpycxx . . $ gsl_matrix_memcpy(2d55a18be0e0c72f). (state->lucxx . . $ $anonymous_type_4d022e410f63cd41_0#lu., J);
140
141 gsl_linalg_LU_decompcxx . . $ gsl_linalg_LU_decomp(e9d4741e9a7c7a22). (state->lucxx . . $ $anonymous_type_4d022e410f63cd41_0#lu., state->permutationcxx . . $ $anonymous_type_4d022e410f63cd41_0#permutation., &signum);
142
143 gsl_linalg_LU_solvecxx . . $ gsl_linalg_LU_solve(58522a8301ae2475). (state->lucxx . . $ $anonymous_type_4d022e410f63cd41_0#lu., state->permutationcxx . . $ $anonymous_type_4d022e410f63cd41_0#permutation., f, state->dcxx . . $ $anonymous_type_4d022e410f63cd41_0#d.);
144
145 t = 1;
146
147 phi0 = state->phicxx . . $ $anonymous_type_4d022e410f63cd41_0#phi.;
148
149 new_step:
150
151 for (i = 0; i < n; i++)
152 {
153 double di = gsl_vector_getcxx . . $ gsl_vector_get(bd1f20df78adc7a). (state->dcxx . . $ $anonymous_type_4d022e410f63cd41_0#d., i);
154 double xi = gsl_vector_getcxx . . $ gsl_vector_get(bd1f20df78adc7a). (x, i);
155 gsl_vector_setcxx . . $ gsl_vector_set(c35f863a529e8fae). (state->x_trialcxx . . $ $anonymous_type_4d022e410f63cd41_0#x_trial., i, xi - t*di);
156 }
157
158 {
159 int status = GSL_MULTIROOT_FN_EVAL_Fcxx . . $ `external/gsl/gsl_multiroots.h:112:9`! (fdf, state->x_trial, f);
160
161 if (status != GSL_SUCCESScxx . . $ GSL_SUCCESS.)
162 {
163 return GSL_EBADFUNCcxx . . $ GSL_EBADFUNC.;
164 }
165 }
166
167 phi1 = enormcxx . . $ enorm(1b712e435b5359e9). (f);
168
169 if (phi1 > phi0 && t > GSL_DBL_EPSILONcxx . . $ `external/gsl/gsl_machine.h:17:9`!)
170 {
171 /* full step goes uphill, take a reduced step instead */
172
173 double theta = phi1 / phi0;
174 double u = (sqrt(1.0 + 6.0 * theta) - 1.0) / (3.0 * theta);
175
176 t *= u ;
177
178 goto new_step;
179 }
180
181 /* copy x_trial into x */
182
183 gsl_vector_memcpycxx . . $ gsl_vector_memcpy(950c164c4e50c555). (x, state->x_trialcxx . . $ $anonymous_type_4d022e410f63cd41_0#x_trial.);
184
185 for (i = 0; i < n; i++)
186 {
187 double di = gsl_vector_getcxx . . $ gsl_vector_get(bd1f20df78adc7a). (state->dcxx . . $ $anonymous_type_4d022e410f63cd41_0#d., i);
188 gsl_vector_setcxx . . $ gsl_vector_set(c35f863a529e8fae). (dx, i, -t*di);
189 }
190
191 {
192 int status = GSL_MULTIROOT_FN_EVAL_DFcxx . . $ `external/gsl/gsl_multiroots.h:113:9`! (fdf, x, J);
193
194 if (status != GSL_SUCCESScxx . . $ GSL_SUCCESS.)
195 {
196 return GSL_EBADFUNCcxx . . $ GSL_EBADFUNC.;
197 }
198 }
199
200 state->phicxx . . $ $anonymous_type_4d022e410f63cd41_0#phi. = phi1;
201
202 return GSL_SUCCESScxx . . $ GSL_SUCCESS.;
203 }
204
205
206 static void
207 gnewton_freecxx . . $ gnewton_free(5d22bdacc48458e8). (void * vstate)
208 {
209 gnewton_state_tcxx . . $ gnewton_state_t# * state = (gnewton_state_tcxx . . $ gnewton_state_t# *) vstate;
210
211 gsl_vector_freecxx . . $ gsl_vector_free(5d65852ca0326259).(state->dcxx . . $ $anonymous_type_4d022e410f63cd41_0#d.);
212 gsl_vector_freecxx . . $ gsl_vector_free(5d65852ca0326259).(state->x_trialcxx . . $ $anonymous_type_4d022e410f63cd41_0#x_trial.);
213 gsl_matrix_freecxx . . $ gsl_matrix_free(ab29a617cccd3636).(state->lucxx . . $ $anonymous_type_4d022e410f63cd41_0#lu.);
214 gsl_permutation_freecxx . . $ gsl_permutation_free(bfe6c130f63679fa).(state->permutationcxx . . $ $anonymous_type_4d022e410f63cd41_0#permutation.);
215 }
216
217
218 static const gsl_multiroot_fdfsolver_typecxx . . $ gsl_multiroot_fdfsolver_type# gnewton_typecxx . . $ gnewton_type. =
219 {"gnewton", /* name */
220 sizeof (gnewton_state_tcxx . . $ gnewton_state_t#),
221 &gnewton_alloccxx . . $ gnewton_alloc(c0a5f96701d3f89).,
222 &gnewton_setcxx . . $ gnewton_set(36a4c1ecdfe5d338).,
223 &gnewton_iteratecxx . . $ gnewton_iterate(36a4c1ecdfe5d338).,
224 &gnewton_freecxx . . $ gnewton_free(5d22bdacc48458e8).};
225
226 const gsl_multiroot_fdfsolver_typecxx . . $ gsl_multiroot_fdfsolver_type# * gsl_multiroot_fdfsolver_gnewtoncxx . . $ gsl_multiroot_fdfsolver_gnewton. = &gnewton_typecxx . . $ gnewton_type.;