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