3
|
1 // NPSOL.h -*- C++ -*- |
|
2 /* |
|
3 |
1862
|
4 Copyright (C) 1996 John W. Eaton |
3
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
3
|
21 |
|
22 */ |
|
23 |
382
|
24 #if !defined (octave_NPSOL_h) |
|
25 #define octave_NPSOL_h 1 |
|
26 |
1296
|
27 #if defined (__GNUG__) |
|
28 #pragma interface |
|
29 #endif |
|
30 |
645
|
31 #ifndef NPSOL_MISSING |
|
32 |
1874
|
33 #include <cfloat> |
1862
|
34 #include <cmath> |
|
35 |
461
|
36 #include "dColVector.h" |
3
|
37 #include "NLP.h" |
|
38 |
1862
|
39 class |
|
40 NPSOL_options |
3
|
41 { |
1862
|
42 public: |
3
|
43 |
1862
|
44 NPSOL_options (void) { init (); } |
|
45 |
1873
|
46 NPSOL_options (const NPSOL_options& opt) { set_options (opt); } |
287
|
47 |
1866
|
48 NPSOL_options& operator = (const NPSOL_options& opt) |
1862
|
49 { |
|
50 if (this != &opt) |
1873
|
51 set_options (opt); |
287
|
52 |
1862
|
53 return *this; |
|
54 } |
|
55 |
|
56 ~NPSOL_options (void) { } |
287
|
57 |
|
58 void init (void); |
1862
|
59 |
1873
|
60 void set_default_options (void) { init (); } |
287
|
61 |
1873
|
62 void set_options (const NPSOL_options& opt); |
1862
|
63 |
|
64 // XXX FIXME XXX -- is this a good idea? |
|
65 |
|
66 // Passing invalid values to the set_* functions will result in |
|
67 // setting the default option. |
|
68 |
|
69 void set_central_difference_interval (double val) |
|
70 { x_central_difference_interval = (val > 0.0) ? val : -1.0; } |
|
71 |
|
72 void set_crash_tolerance (double val) |
|
73 { x_crash_tolerance = (val >= 0.0) ? val : 0.1; } |
|
74 |
|
75 void set_difference_interval (double val) |
|
76 { x_difference_interval = (val > 0.0) ? val : -1.0; } |
|
77 |
|
78 void set_function_precision (double val) |
|
79 { x_function_precision = (val > 0.0) ? val : ::pow (DBL_EPSILON, 0.9); } |
|
80 |
|
81 void set_infinite_bound (double val) |
|
82 { x_infinite_bound = (val > 0.0) ? val : 1.0e+30; } |
|
83 |
|
84 void set_infinite_step (double val) |
|
85 { x_infinite_step = (val > 0.0) ? val : 1.0e+30; } |
|
86 |
|
87 void set_linear_feasibility_tolerance (double val) |
|
88 { |
|
89 x_linear_feasibility_tolerance |
|
90 = (val > 0.0) ? val : ::sqrt (DBL_EPSILON); |
|
91 } |
287
|
92 |
1862
|
93 void set_linesearch_tolerance (double val) |
|
94 { x_linesearch_tolerance = (val >= 0.0 && val < 1.0) ? val : 0.9; } |
|
95 |
|
96 void set_nonlinear_feasibility_tolerance (double val) |
|
97 { |
|
98 x_nonlinear_feasibility_tolerance |
|
99 = (val > 0.0) ? val : ::sqrt (DBL_EPSILON); |
|
100 } |
|
101 |
|
102 void set_optimality_tolerance (double val) |
|
103 { x_optimality_tolerance = (val > 0.0) ? val : ::pow (DBL_EPSILON, 0.8); } |
|
104 |
|
105 void set_derivative_level (int val) |
|
106 { x_derivative_level = (val >= 0 && val < 4) ? val : 0; } |
|
107 |
|
108 void set_major_iteration_limit (int val) |
|
109 { x_major_iteration_limit = (val > 0) ? val : -1; } |
287
|
110 |
1862
|
111 void set_minor_iteration_limit (int val) |
|
112 { x_minor_iteration_limit = (val > 0) ? val : -1; } |
|
113 |
|
114 void set_major_print_level (int val) |
|
115 { x_major_print_level = (val >= 0) ? val : -1; } |
|
116 |
|
117 void set_minor_print_level (int val) |
|
118 { x_minor_print_level = (val >= 0) ? val : -1; } |
|
119 |
|
120 void set_start_objective_check (int val) |
|
121 { x_start_objective_check = (val >= 0) ? val : -1; } |
|
122 |
|
123 void set_start_constraint_check (int val) |
|
124 { x_start_constraint_check = (val >= 0) ? val : -1; } |
|
125 |
|
126 void set_stop_objective_check (int val) |
|
127 { x_stop_objective_check = (val >= 0) ? val : -1; } |
287
|
128 |
1862
|
129 void set_stop_constraint_check (int val) |
|
130 { x_stop_constraint_check = (val >= 0) ? val : -1; } |
|
131 |
|
132 void set_verify_level (int val) |
|
133 { |
|
134 x_verify_level |
|
135 = ((val > -1 && val < 4) || (val > 9 && val < 14)) ? val : 0; |
|
136 } |
|
137 |
|
138 double central_difference_interval (void) const |
|
139 { return x_central_difference_interval; } |
|
140 |
|
141 double crash_tolerance (void) const |
|
142 { return x_crash_tolerance; } |
|
143 |
|
144 double difference_interval (void) const |
|
145 { return x_difference_interval; } |
|
146 |
|
147 double function_precision (void) const |
|
148 { return x_function_precision; } |
|
149 |
|
150 double infinite_bound (void) const |
|
151 { return x_infinite_bound; } |
|
152 |
|
153 double infinite_step (void) const |
|
154 { return x_infinite_step; } |
|
155 |
|
156 double linear_feasibility_tolerance (void) const |
|
157 { return x_linear_feasibility_tolerance; } |
|
158 |
|
159 double linesearch_tolerance (void) const |
|
160 { return x_linesearch_tolerance; } |
3
|
161 |
1862
|
162 double nonlinear_feasibility_tolerance (void) const |
|
163 { return x_nonlinear_feasibility_tolerance; } |
|
164 |
|
165 double optimality_tolerance (void) const |
|
166 { return x_optimality_tolerance; } |
|
167 |
|
168 int derivative_level (void) const |
|
169 { return x_derivative_level; } |
|
170 |
|
171 int major_iteration_limit (void) const |
|
172 { return x_major_iteration_limit; } |
|
173 |
|
174 int minor_iteration_limit (void) const |
|
175 { return x_minor_iteration_limit; } |
|
176 |
|
177 int major_print_level (void) const |
|
178 { return x_major_print_level; } |
287
|
179 |
1862
|
180 int minor_print_level (void) const |
|
181 { return x_minor_print_level; } |
|
182 |
|
183 int start_objective_check (void) const |
|
184 { return x_start_objective_check; } |
|
185 |
|
186 int start_constraint_check (void) const |
|
187 { return x_start_constraint_check; } |
|
188 |
|
189 int stop_objective_check (void) const |
|
190 { return x_stop_objective_check; } |
|
191 |
|
192 int stop_constraint_check (void) const |
|
193 { return x_stop_constraint_check; } |
|
194 |
|
195 int verify_level (void) const |
|
196 { return x_verify_level; } |
|
197 |
|
198 protected: |
287
|
199 |
|
200 void pass_options_to_npsol (void); |
|
201 |
|
202 void set_option (const char *key, int opt); |
|
203 void set_option (const char *key, double opt); |
|
204 |
1862
|
205 private: |
287
|
206 |
|
207 double x_central_difference_interval; |
|
208 double x_crash_tolerance; |
|
209 double x_difference_interval; |
|
210 double x_function_precision; |
|
211 double x_infinite_bound; |
|
212 double x_infinite_step; |
|
213 double x_linear_feasibility_tolerance; |
|
214 double x_linesearch_tolerance; |
|
215 double x_nonlinear_feasibility_tolerance; |
|
216 double x_optimality_tolerance; |
1862
|
217 |
287
|
218 int x_derivative_level; |
|
219 int x_major_iteration_limit; |
|
220 int x_minor_iteration_limit; |
|
221 int x_major_print_level; |
|
222 int x_minor_print_level; |
|
223 int x_start_objective_check; |
|
224 int x_start_constraint_check; |
|
225 int x_stop_objective_check; |
|
226 int x_stop_constraint_check; |
|
227 int x_verify_level; |
|
228 }; |
|
229 |
1862
|
230 class |
|
231 NPSOL : public NLP, public NPSOL_options |
287
|
232 { |
1862
|
233 public: |
287
|
234 |
1833
|
235 NPSOL (void) |
|
236 : NLP (), NPSOL_options () { } |
287
|
237 |
1833
|
238 NPSOL (const ColumnVector& x, const Objective& phi) |
|
239 : NLP (x, phi), NPSOL_options () { } |
3
|
240 |
1833
|
241 NPSOL (const ColumnVector& x, const Objective& phi, const Bounds& b) |
|
242 : NLP (x, phi, b), NPSOL_options () { } |
3
|
243 |
1528
|
244 NPSOL (const ColumnVector& x, const Objective& phi, const Bounds& b, |
1833
|
245 const LinConst& lc) |
|
246 : NLP (x, phi, b, lc), NPSOL_options () { } |
3
|
247 |
1528
|
248 NPSOL (const ColumnVector& x, const Objective& phi, const Bounds& b, |
|
249 const LinConst& lc, const NLConst& nlc) |
1833
|
250 : NLP (x, phi, b, lc, nlc), NPSOL_options () { } |
3
|
251 |
1833
|
252 NPSOL (const ColumnVector& x, const Objective& phi, const LinConst& lc) |
|
253 : NLP (x, phi, lc), NPSOL_options () { } |
3
|
254 |
1528
|
255 NPSOL (const ColumnVector& x, const Objective& phi, const LinConst& lc, |
1833
|
256 const NLConst& nlc) |
|
257 : NLP (x, phi, lc, nlc), NPSOL_options () { } |
3
|
258 |
1528
|
259 NPSOL (const ColumnVector& x, const Objective& phi, |
1833
|
260 const NLConst& nlc) |
|
261 : NLP (x, phi, nlc), NPSOL_options () { } |
3
|
262 |
1528
|
263 NPSOL (const ColumnVector& x, const Objective& phi, const Bounds& b, |
1833
|
264 const NLConst& nlc) |
|
265 : NLP (x, phi, b, nlc), NPSOL_options () { } |
3
|
266 |
1833
|
267 NPSOL (const NPSOL& a) |
|
268 : NLP (a), NPSOL_options () { } |
1528
|
269 |
1834
|
270 NPSOL& operator = (const NPSOL& a) |
|
271 { |
1835
|
272 if (this != &a) |
|
273 { |
|
274 NLP::operator = (a); |
|
275 NPSOL_options::operator = (a); |
|
276 } |
1834
|
277 return *this; |
|
278 } |
|
279 |
|
280 ~NPSOL (void) { } |
|
281 |
1528
|
282 ColumnVector do_minimize (double& objf, int& inform, ColumnVector& lambda); |
1941
|
283 |
|
284 private: |
|
285 |
|
286 int attempt; |
3
|
287 }; |
|
288 |
255
|
289 // XXX FIXME XXX -- would be nice to not have to have this global |
|
290 // variable. |
|
291 // Nonzero means an error occurred in the calculation of the objective |
|
292 // function, and the user wants us to quit. |
|
293 extern int npsol_objective_error; |
|
294 |
1359
|
295 #endif |
238
|
296 #endif |
3
|
297 |
|
298 /* |
|
299 ;;; Local Variables: *** |
|
300 ;;; mode: C++ *** |
|
301 ;;; page-delimiter: "^/\\*" *** |
|
302 ;;; End: *** |
|
303 */ |