7
|
1 // f-npsol.cc -*- C++ -*- |
1
|
2 /* |
|
3 |
296
|
4 Copyright (C) 1993, 1994 John W. Eaton |
1
|
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 |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include "config.h" |
1
|
26 #endif |
|
27 |
|
28 #ifndef NPSOL_MISSING |
|
29 |
287
|
30 #include <strstream.h> |
|
31 |
1
|
32 #include "NPSOL.h" |
|
33 |
|
34 #include "tree-const.h" |
|
35 #include "variables.h" |
287
|
36 #include "builtins.h" |
1
|
37 #include "gripes.h" |
|
38 #include "error.h" |
287
|
39 #include "pager.h" |
1
|
40 #include "utils.h" |
7
|
41 #include "f-npsol.h" |
1
|
42 |
|
43 // Global pointers for user defined functions required by npsol. |
488
|
44 static tree_fvc *npsol_objective; |
|
45 static tree_fvc *npsol_constraints; |
1
|
46 |
|
47 #ifdef WITH_DLD |
497
|
48 Octave_object |
|
49 builtin_npsol_2 (const Octave_object& args, int nargin, int nargout) |
1
|
50 { |
|
51 return npsol (args, nargin, nargout); |
|
52 } |
272
|
53 |
497
|
54 Octave_object |
|
55 builtin_npsol_options_2 (const Octave_object& args, int nargin, int nargout) |
272
|
56 { |
|
57 return npsol_options (args, nargin, nargout); |
|
58 } |
1
|
59 #endif |
|
60 |
287
|
61 static NPSOL_options npsol_opts; |
|
62 |
1
|
63 double |
162
|
64 npsol_objective_function (const ColumnVector& x) |
1
|
65 { |
|
66 int n = x.capacity (); |
|
67 |
|
68 tree_constant decision_vars; |
|
69 if (n > 1) |
|
70 { |
|
71 Matrix m (n, 1); |
|
72 for (int i = 0; i < n; i++) |
|
73 m (i, 0) = x.elem (i); |
|
74 decision_vars = tree_constant (m); |
|
75 } |
|
76 else |
|
77 { |
|
78 double d = x.elem (0); |
|
79 decision_vars = tree_constant (d); |
|
80 } |
|
81 |
|
82 // tree_constant name = tree_constant (npsol_objective->name ()); |
497
|
83 Octave_object args (2); |
|
84 // args(0) = name; |
|
85 args(1) = decision_vars; |
1
|
86 |
255
|
87 static double retval; |
|
88 retval = 0.0; |
|
89 |
1
|
90 tree_constant objective_value; |
488
|
91 if (npsol_objective != (tree_fvc *) NULL) |
1
|
92 { |
497
|
93 Octave_object tmp = npsol_objective->eval (0, 1, args, 2); |
255
|
94 |
|
95 if (error_state) |
|
96 { |
|
97 error ("npsol: error evaluating objective function"); |
|
98 npsol_objective_error = 1; // XXX FIXME XXX |
|
99 return retval; |
|
100 } |
|
101 |
497
|
102 if (tmp.length () > 0 && tmp(0).is_defined ()) |
|
103 objective_value = tmp(0); |
1
|
104 else |
|
105 { |
158
|
106 error ("npsol: error evaluating objective function"); |
255
|
107 npsol_objective_error = 1; // XXX FIXME XXX |
|
108 return retval; |
1
|
109 } |
|
110 } |
|
111 |
|
112 switch (objective_value.const_type ()) |
|
113 { |
|
114 case tree_constant_rep::matrix_constant: |
|
115 { |
|
116 Matrix m = objective_value.matrix_value (); |
|
117 if (m.rows () == 1 && m.columns () == 1) |
|
118 retval = m.elem (0, 0); |
|
119 else |
255
|
120 { |
|
121 gripe_user_returned_invalid ("npsol_objective"); |
|
122 npsol_objective_error = 1; // XXX FIXME XXX |
|
123 } |
1
|
124 } |
|
125 break; |
|
126 case tree_constant_rep::scalar_constant: |
|
127 retval = objective_value.double_value (); |
|
128 break; |
|
129 default: |
|
130 gripe_user_returned_invalid ("npsol_objective"); |
255
|
131 npsol_objective_error = 1; // XXX FIXME XXX |
1
|
132 break; |
|
133 } |
|
134 |
|
135 return retval; |
|
136 } |
|
137 |
|
138 ColumnVector |
162
|
139 npsol_constraint_function (const ColumnVector& x) |
1
|
140 { |
|
141 ColumnVector retval; |
|
142 |
|
143 int n = x.capacity (); |
|
144 |
|
145 tree_constant decision_vars; |
|
146 if (n > 1) |
|
147 { |
|
148 Matrix m (n, 1); |
|
149 for (int i = 0; i < n; i++) |
|
150 m (i, 0) = x.elem (i); |
|
151 decision_vars = tree_constant (m); |
|
152 } |
|
153 else |
|
154 { |
|
155 double d = x.elem (0); |
|
156 decision_vars = tree_constant (d); |
|
157 } |
|
158 |
|
159 // tree_constant name = tree_constant (npsol_constraints->name ()); |
497
|
160 Octave_object args (2); |
|
161 // args(0) = name; |
|
162 args(1) = decision_vars; |
1
|
163 |
488
|
164 if (npsol_constraints != (tree_fvc *)NULL) |
1
|
165 { |
497
|
166 Octave_object tmp = npsol_constraints->eval (0, 1, args, 2); |
255
|
167 |
|
168 if (error_state) |
|
169 { |
|
170 error ("npsol: error evaluating constraints"); |
|
171 return retval; |
|
172 } |
|
173 |
497
|
174 if (tmp.length () > 0 && tmp(0).is_defined ()) |
1
|
175 { |
497
|
176 retval = tmp(0).to_vector (); |
255
|
177 |
|
178 if (retval.length () <= 0) |
|
179 error ("npsol: error evaluating constraints"); |
1
|
180 } |
|
181 else |
497
|
182 error ("npsol: error evaluating constraints"); |
1
|
183 } |
|
184 |
|
185 return retval; |
|
186 } |
|
187 |
|
188 int |
|
189 linear_constraints_ok (const ColumnVector& x, const ColumnVector& llb, |
|
190 const Matrix& c, const ColumnVector& lub, |
|
191 char *warn_for, int warn) |
|
192 { |
|
193 int x_len = x.capacity (); |
|
194 int llb_len = llb.capacity (); |
|
195 int lub_len = lub.capacity (); |
|
196 int c_rows = c.rows (); |
|
197 int c_cols = c.columns (); |
|
198 |
132
|
199 int ok = 1; |
|
200 if (warn) |
|
201 { |
|
202 if (c_rows == 0 || c_cols == 0 || llb_len == 0 || lub_len == 0) |
|
203 { |
|
204 ok = 0; |
158
|
205 error ("%s: linear constraints must have nonzero dimensions", |
|
206 warn_for); |
132
|
207 } |
|
208 else if (x_len != c_cols || llb_len != lub_len || llb_len != c_rows) |
|
209 { |
|
210 ok = 0; |
158
|
211 error ("%s: linear constraints have inconsistent dimensions", |
|
212 warn_for); |
132
|
213 } |
|
214 } |
1
|
215 |
|
216 return ok; |
|
217 } |
|
218 |
|
219 int |
|
220 nonlinear_constraints_ok (const ColumnVector& x, const ColumnVector& nllb, |
|
221 nonlinear_fcn g, const ColumnVector& nlub, |
|
222 char *warn_for, int warn) |
|
223 { |
|
224 int nllb_len = nllb.capacity (); |
|
225 int nlub_len = nlub.capacity (); |
|
226 ColumnVector c = (*g) (x); |
|
227 int c_len = c.capacity (); |
|
228 |
132
|
229 int ok = 1; |
|
230 if (warn) |
|
231 { |
|
232 if (nllb_len == 0 || nlub_len == 0 || c_len == 0) |
|
233 { |
|
234 ok = 0; |
158
|
235 error ("%s: nonlinear constraints have nonzero dimensions", |
|
236 warn_for); |
132
|
237 } |
|
238 else if (nllb_len != nlub_len || nllb_len != c_len) |
|
239 { |
|
240 ok = 0; |
162
|
241 error ("%s: nonlinear constraints have inconsistent dimensions", |
|
242 warn_for); |
132
|
243 } |
135
|
244 } |
1
|
245 return ok; |
|
246 } |
|
247 |
497
|
248 Octave_object |
|
249 npsol (const Octave_object& args, int nargin, int nargout) |
1
|
250 { |
|
251 /* |
|
252 |
|
253 Handle all of the following: |
|
254 |
|
255 1. npsol (x, phi) |
|
256 2. npsol (x, phi, lb, ub) |
|
257 3. npsol (x, phi, lb, ub, llb, c, lub) |
|
258 4. npsol (x, phi, lb, ub, llb, c, lub, nllb, g, nlub) |
|
259 5. npsol (x, phi, lb, ub, nllb, g, nlub) |
|
260 6. npsol (x, phi, llb, c, lub, nllb, g, nlub) |
|
261 7. npsol (x, phi, llb, c, lub) |
|
262 8. npsol (x, phi, nllb, g, nlub) |
|
263 |
|
264 */ |
|
265 |
|
266 // Assumes that we have been given the correct number of arguments. |
|
267 |
497
|
268 Octave_object retval; |
1
|
269 |
497
|
270 ColumnVector x = args(1).to_vector (); |
1
|
271 |
|
272 if (x.capacity () == 0) |
|
273 { |
158
|
274 error ("npsol: expecting vector as first argument"); |
1
|
275 return retval; |
|
276 } |
|
277 |
497
|
278 npsol_objective = is_valid_function (args(2), "npsol", 1); |
488
|
279 if (npsol_objective == (tree_fvc *) NULL |
1
|
280 || takes_correct_nargs (npsol_objective, 2, "npsol", 1) != 1) |
|
281 return retval; |
|
282 |
|
283 Objective func (npsol_objective_function); |
|
284 |
|
285 ColumnVector soln; |
|
286 |
|
287 Bounds bounds; |
|
288 if (nargin == 5 || nargin == 8 || nargin == 11) |
|
289 { |
497
|
290 ColumnVector lb = args(3).to_vector (); |
|
291 ColumnVector ub = args(4).to_vector (); |
1
|
292 |
|
293 int lb_len = lb.capacity (); |
|
294 int ub_len = ub.capacity (); |
|
295 if (lb_len != ub_len || lb_len != x.capacity ()) |
|
296 { |
214
|
297 error ("npsol: lower and upper bounds and decision variable vector"); |
|
298 error ("must all have the same number of elements"); |
1
|
299 return retval; |
|
300 } |
|
301 |
|
302 bounds.resize (lb_len); |
|
303 bounds.set_lower_bounds (lb); |
|
304 bounds.set_upper_bounds (ub); |
|
305 } |
|
306 |
|
307 double objf; |
|
308 ColumnVector lambda; |
|
309 int inform; |
|
310 |
|
311 if (nargin == 3) |
|
312 { |
|
313 // 1. npsol (x, phi) |
|
314 |
|
315 NPSOL nlp (x, func); |
287
|
316 nlp.copy (npsol_opts); |
1
|
317 soln = nlp.minimize (objf, inform, lambda); |
|
318 |
|
319 goto solved; |
|
320 } |
|
321 |
|
322 if (nargin == 5) |
|
323 { |
|
324 // 2. npsol (x, phi, lb, ub) |
|
325 |
|
326 NPSOL nlp (x, func, bounds); |
287
|
327 nlp.copy (npsol_opts); |
1
|
328 soln = nlp.minimize (objf, inform, lambda); |
|
329 |
|
330 goto solved; |
|
331 } |
|
332 |
488
|
333 npsol_constraints = (tree_fvc *) NULL; |
1
|
334 if (nargin == 6 || nargin == 8 || nargin == 9 || nargin == 11) |
497
|
335 npsol_constraints = is_valid_function (args(nargin-2), "npsol", 0); |
1
|
336 |
|
337 if (nargin == 8 || nargin == 6) |
|
338 { |
488
|
339 if (npsol_constraints == (tree_fvc *) NULL) |
1
|
340 { |
497
|
341 ColumnVector lub = args(nargin-1).to_vector (); |
|
342 Matrix c = args(nargin-2).to_matrix (); |
|
343 ColumnVector llb = args(nargin-3).to_vector (); |
1
|
344 |
215
|
345 if (llb.capacity () == 0 || lub.capacity () == 0) |
|
346 { |
|
347 error ("npsol: bounds for linear constraints must be vectors"); |
|
348 return retval; |
|
349 } |
1
|
350 |
|
351 if (! linear_constraints_ok (x, llb, c, lub, "npsol", 1)) |
|
352 return retval; |
|
353 |
215
|
354 LinConst linear_constraints (llb, c, lub); |
|
355 |
1
|
356 if (nargin == 6) |
|
357 { |
|
358 // 7. npsol (x, phi, llb, c, lub) |
|
359 |
|
360 NPSOL nlp (x, func, linear_constraints); |
287
|
361 nlp.copy (npsol_opts); |
1
|
362 soln = nlp.minimize (objf, inform, lambda); |
|
363 } |
|
364 else |
|
365 { |
|
366 // 3. npsol (x, phi, lb, ub, llb, c, lub) |
|
367 |
|
368 NPSOL nlp (x, func, bounds, linear_constraints); |
287
|
369 nlp.copy (npsol_opts); |
1
|
370 soln = nlp.minimize (objf, inform, lambda); |
|
371 } |
|
372 goto solved; |
|
373 } |
|
374 else |
|
375 { |
|
376 if (takes_correct_nargs (npsol_constraints, 2, "npsol", 1)) |
|
377 { |
497
|
378 ColumnVector nlub = args(nargin-1).to_vector (); |
|
379 ColumnVector nllb = args(nargin-3).to_vector (); |
1
|
380 |
|
381 NLFunc const_func (npsol_constraint_function); |
|
382 |
|
383 if (! nonlinear_constraints_ok |
|
384 (x, nllb, npsol_constraint_function, nlub, "npsol", 1)) |
|
385 return retval; |
|
386 |
|
387 NLConst nonlinear_constraints (nllb, const_func, nlub); |
|
388 |
|
389 if (nargin == 6) |
|
390 { |
|
391 // 8. npsol (x, phi, nllb, g, nlub) |
|
392 |
|
393 NPSOL nlp (x, func, nonlinear_constraints); |
287
|
394 nlp.copy (npsol_opts); |
1
|
395 soln = nlp.minimize (objf, inform, lambda); |
|
396 } |
|
397 else |
|
398 { |
|
399 // 5. npsol (x, phi, lb, ub, nllb, g, nlub) |
|
400 |
|
401 NPSOL nlp (x, func, bounds, nonlinear_constraints); |
287
|
402 nlp.copy (npsol_opts); |
1
|
403 soln = nlp.minimize (objf, inform, lambda); |
|
404 } |
|
405 goto solved; |
|
406 } |
|
407 } |
|
408 } |
|
409 |
|
410 if (nargin == 9 || nargin == 11) |
|
411 { |
488
|
412 if (npsol_constraints == (tree_fvc *) NULL) |
1
|
413 { |
|
414 // Produce error message. |
497
|
415 is_valid_function (args(nargin-2), "npsol", 1); |
1
|
416 } |
|
417 else |
|
418 { |
|
419 if (takes_correct_nargs (npsol_constraints, 2, "npsol", 1)) |
|
420 { |
497
|
421 ColumnVector nlub = args(nargin-1).to_vector (); |
|
422 ColumnVector nllb = args(nargin-3).to_vector (); |
1
|
423 |
|
424 NLFunc const_func (npsol_constraint_function); |
|
425 |
|
426 if (! nonlinear_constraints_ok |
|
427 (x, nllb, npsol_constraint_function, nlub, "npsol", 1)) |
|
428 return retval; |
|
429 |
|
430 NLConst nonlinear_constraints (nllb, const_func, nlub); |
|
431 |
497
|
432 ColumnVector lub = args(nargin-4).to_vector (); |
|
433 Matrix c = args(nargin-5).to_matrix (); |
|
434 ColumnVector llb = args(nargin-6).to_vector (); |
1
|
435 |
215
|
436 if (llb.capacity () == 0 || lub.capacity () == 0) |
|
437 { |
|
438 error ("npsol: bounds for linear constraints must be vectors"); |
|
439 return retval; |
|
440 } |
|
441 |
1
|
442 if (! linear_constraints_ok (x, llb, c, lub, "npsol", 1)) |
|
443 return retval; |
|
444 |
|
445 LinConst linear_constraints (llb, c, lub); |
|
446 |
|
447 if (nargin == 9) |
|
448 { |
|
449 // 6. npsol (x, phi, llb, c, lub, nllb, g, nlub) |
|
450 |
|
451 NPSOL nlp (x, func, linear_constraints, |
|
452 nonlinear_constraints); |
287
|
453 nlp.copy (npsol_opts); |
1
|
454 soln = nlp.minimize (objf, inform, lambda); |
|
455 } |
|
456 else |
|
457 { |
|
458 // 4. npsol (x, phi, lb, ub, llb, c, lub, nllb, g, nlub) |
|
459 |
|
460 NPSOL nlp (x, func, bounds, linear_constraints, |
|
461 nonlinear_constraints); |
287
|
462 nlp.copy (npsol_opts); |
1
|
463 soln = nlp.minimize (objf, inform, lambda); |
|
464 } |
|
465 goto solved; |
|
466 } |
|
467 } |
|
468 } |
|
469 |
|
470 return retval; |
|
471 |
|
472 solved: |
|
473 |
497
|
474 retval.resize (nargout ? nargout : 1); |
|
475 retval(0) = tree_constant (soln, 1); |
1
|
476 if (nargout > 1) |
497
|
477 retval(1) = tree_constant (objf); |
1
|
478 if (nargout > 2) |
497
|
479 retval(2) = tree_constant ((double) inform); |
1
|
480 if (nargout > 3) |
497
|
481 retval(3) = tree_constant (lambda); |
1
|
482 |
|
483 return retval; |
|
484 } |
|
485 |
287
|
486 typedef void (NPSOL_options::*d_set_opt_mf) (double); |
|
487 typedef void (NPSOL_options::*i_set_opt_mf) (int); |
|
488 typedef double (NPSOL_options::*d_get_opt_mf) (void); |
|
489 typedef int (NPSOL_options::*i_get_opt_mf) (void); |
|
490 |
|
491 #define MAX_TOKENS 5 |
|
492 |
|
493 struct NPSOL_OPTIONS |
|
494 { |
|
495 char *keyword; |
|
496 char *kw_tok[MAX_TOKENS + 1]; |
|
497 int min_len[MAX_TOKENS + 1]; |
|
498 int min_toks_to_match; |
|
499 d_set_opt_mf d_set_fcn; |
|
500 i_set_opt_mf i_set_fcn; |
|
501 d_get_opt_mf d_get_fcn; |
|
502 i_get_opt_mf i_get_fcn; |
|
503 }; |
|
504 |
497
|
505 static NPSOL_OPTIONS npsol_option_table [] = |
287
|
506 { |
|
507 { "central difference interval", |
|
508 { "central", "difference", "interval", NULL, NULL, NULL, }, |
|
509 { 2, 0, 0, 0, 0, 0, }, 1, |
|
510 NPSOL_options::set_central_difference_interval, NULL, |
|
511 NPSOL_options::central_difference_interval, NULL, }, |
|
512 |
|
513 { "crash tolerance", |
|
514 { "crash", "tolerance", NULL, NULL, NULL, NULL, }, |
|
515 { 2, 0, 0, 0, 0, 0, }, 1, |
|
516 NPSOL_options::set_crash_tolerance, NULL, |
|
517 NPSOL_options::crash_tolerance, NULL, }, |
|
518 |
|
519 { "derivative level", |
|
520 { "derivative", "level", NULL, NULL, NULL, NULL, }, |
|
521 { 1, 0, 0, 0, 0, 0, }, 1, |
|
522 NULL, NPSOL_options::set_derivative_level, |
|
523 NULL, NPSOL_options::derivative_level, }, |
|
524 |
|
525 { "difference interval", |
|
526 { "difference", "interval", NULL, NULL, NULL, NULL, }, |
|
527 { 3, 0, 0, 0, 0, 0, }, 1, |
|
528 NPSOL_options::set_difference_interval, NULL, |
|
529 NPSOL_options::difference_interval, NULL, }, |
|
530 |
|
531 { "function precision", |
|
532 { "function", "precision", NULL, NULL, NULL, NULL, }, |
|
533 { 2, 0, 0, 0, 0, 0, }, 1, |
|
534 NPSOL_options::set_function_precision, NULL, |
|
535 NPSOL_options::function_precision, NULL, }, |
|
536 |
|
537 { "infinite bound size", |
|
538 { "infinite", "bound", "size", NULL, NULL, NULL, }, |
|
539 { 1, 1, 0, 0, 0, 0, }, 2, |
|
540 NPSOL_options::set_infinite_bound, NULL, |
|
541 NPSOL_options::infinite_bound, NULL, }, |
|
542 |
|
543 { "infinite step size", |
|
544 { "infinite", "step", "size", NULL, NULL, NULL, }, |
|
545 { 1, 1, 0, 0, 0, 0, }, 2, |
|
546 NPSOL_options::set_infinite_step, NULL, |
|
547 NPSOL_options::infinite_step, NULL, }, |
|
548 |
|
549 { "linear feasibility tolerance", |
|
550 { "linear", "feasibility", "tolerance", NULL, NULL, NULL, }, |
|
551 { 5, 0, 0, 0, 0, 0, }, 1, |
|
552 NPSOL_options::set_linear_feasibility_tolerance, NULL, |
|
553 NPSOL_options::linear_feasibility_tolerance, NULL, }, |
|
554 |
|
555 { "linesearch tolerance", |
|
556 { "linesearch", "tolerance", NULL, NULL, NULL, NULL, }, |
|
557 { 5, 0, 0, 0, 0, 0, }, 1, |
|
558 NPSOL_options::set_linesearch_tolerance, NULL, |
|
559 NPSOL_options::linesearch_tolerance, NULL, }, |
|
560 |
|
561 { "major iteration limit", |
|
562 { "major", "iteration", "limit", NULL, NULL, NULL, }, |
|
563 { 2, 1, 0, 0, 0, 0, }, 2, |
|
564 NULL, NPSOL_options::set_major_iteration_limit, |
|
565 NULL, NPSOL_options::major_iteration_limit, }, |
|
566 |
|
567 { "minor iteration limit", |
|
568 { "minor", "iteration", "limit", NULL, NULL, NULL, }, |
|
569 { 2, 1, 0, 0, 0, 0, }, 2, |
|
570 NULL, NPSOL_options::set_minor_iteration_limit, |
|
571 NULL, NPSOL_options::minor_iteration_limit, }, |
|
572 |
|
573 { "major print level", |
|
574 { "major", "print", "level", NULL, NULL, NULL, }, |
|
575 { 2, 1, 0, 0, 0, 0, }, 2, |
|
576 NULL, NPSOL_options::set_major_print_level, |
|
577 NULL, NPSOL_options::major_print_level, }, |
|
578 |
|
579 { "minor print level", |
|
580 { "minor", "print", "level", NULL, NULL, NULL, }, |
|
581 { 2, 1, 0, 0, 0, 0, }, 2, |
|
582 NULL, NPSOL_options::set_minor_print_level, |
|
583 NULL, NPSOL_options::minor_print_level, }, |
|
584 |
|
585 { "nonlinear feasibility tolerance", |
|
586 { "nonlinear", "feasibility", "tolerance", NULL, NULL, }, |
|
587 { 1, 0, 0, 0, 0, 0, }, 1, |
|
588 NPSOL_options::set_nonlinear_feasibility_tolerance, NULL, |
|
589 NPSOL_options::nonlinear_feasibility_tolerance, NULL, }, |
|
590 |
|
591 { "optimality tolerance", |
|
592 { "optimality", "tolerance", NULL, NULL, NULL, NULL, }, |
|
593 { 1, 0, 0, 0, 0, 0, }, 1, |
|
594 NPSOL_options::set_optimality_tolerance, NULL, |
|
595 NPSOL_options::optimality_tolerance, NULL, }, |
|
596 |
|
597 { "start objective check at variable", |
|
598 { "start", "objective", "check", "at", "variable", NULL, }, |
|
599 { 3, 1, 0, 0, 0, 0, }, 2, |
|
600 NULL, NPSOL_options::set_start_objective_check, |
|
601 NULL, NPSOL_options::start_objective_check, }, |
|
602 |
|
603 { "start constraint check at variable", |
|
604 { "start", "constraint", "check", "at", "variable", NULL, }, |
|
605 { 3, 1, 0, 0, 0, 0, }, 2, |
|
606 NULL, NPSOL_options::set_start_constraint_check, |
|
607 NULL, NPSOL_options::start_constraint_check, }, |
|
608 |
|
609 { "stop objective check at variable", |
|
610 { "stop", "objective", "check", "at", "variable", NULL, }, |
|
611 { 3, 1, 0, 0, 0, 0, }, 2, |
|
612 NULL, NPSOL_options::set_stop_objective_check, |
|
613 NULL, NPSOL_options::stop_objective_check, }, |
|
614 |
|
615 { "stop constraint check at variable", |
|
616 { "stop", "constraint", "check", "at", "variable", NULL, }, |
|
617 { 3, 1, 0, 0, 0, 0, }, 2, |
|
618 NULL, NPSOL_options::set_stop_constraint_check, |
|
619 NULL, NPSOL_options::stop_constraint_check, }, |
|
620 |
|
621 { "verify level", |
|
622 { "verify", "level", NULL, NULL, NULL, NULL, }, |
|
623 { 1, 0, 0, 0, 0, 0, }, 1, |
|
624 NULL, NPSOL_options::set_verify_level, |
|
625 NULL, NPSOL_options::verify_level, }, |
|
626 |
|
627 { NULL, |
|
628 { NULL, NULL, NULL, NULL, NULL, NULL, }, |
|
629 { 0, 0, 0, 0, 0, 0, }, 0, |
|
630 NULL, NULL, NULL, NULL, }, |
|
631 }; |
|
632 |
|
633 static void |
|
634 print_npsol_option_list (void) |
|
635 { |
|
636 ostrstream output_buf; |
|
637 |
|
638 print_usage ("npsol_options", 1); |
|
639 |
|
640 output_buf << "\n" |
|
641 << "Options for npsol include:\n\n" |
|
642 << " keyword value\n" |
|
643 << " ------- -----\n\n"; |
|
644 |
|
645 NPSOL_OPTIONS *list = npsol_option_table; |
|
646 |
|
647 char *keyword; |
|
648 while ((keyword = list->keyword) != (char *) NULL) |
|
649 { |
|
650 output_buf.form (" %-40s ", keyword); |
|
651 if (list->d_get_fcn) |
|
652 { |
|
653 double val = (npsol_opts.*list->d_get_fcn) (); |
|
654 if (val < 0.0) |
|
655 output_buf << "computed automatically"; |
|
656 else |
|
657 output_buf << val; |
|
658 } |
|
659 else |
|
660 { |
|
661 int val = (npsol_opts.*list->i_get_fcn) (); |
|
662 if (val < 0) |
|
663 output_buf << "depends on problem size"; |
|
664 else |
|
665 output_buf << val; |
|
666 } |
|
667 output_buf << "\n"; |
|
668 list++; |
|
669 } |
|
670 |
|
671 output_buf << "\n" << ends; |
|
672 maybe_page_output (output_buf); |
|
673 } |
|
674 |
|
675 static void |
|
676 do_npsol_option (char *keyword, double val) |
|
677 { |
|
678 NPSOL_OPTIONS *list = npsol_option_table; |
|
679 |
|
680 while (list->keyword != (char *) NULL) |
|
681 { |
|
682 if (keyword_almost_match (list->kw_tok, list->min_len, keyword, |
|
683 list->min_toks_to_match, MAX_TOKENS)) |
|
684 { |
|
685 if (list->d_set_fcn) |
|
686 (npsol_opts.*list->d_set_fcn) (val); |
|
687 else |
|
688 (npsol_opts.*list->i_set_fcn) (NINT (val)); |
|
689 |
|
690 return; |
|
691 } |
|
692 list++; |
|
693 } |
|
694 |
|
695 warning ("npsol_options: no match for `%s'", keyword); |
|
696 } |
|
697 |
497
|
698 Octave_object |
|
699 npsol_options (const Octave_object& args, int nargin, int nargout) |
272
|
700 { |
497
|
701 Octave_object retval; |
272
|
702 |
287
|
703 if (nargin == 1) |
|
704 { |
|
705 print_npsol_option_list (); |
|
706 } |
|
707 else if (nargin == 3) |
|
708 { |
497
|
709 if (args(1).is_string_type ()) |
287
|
710 { |
497
|
711 char *keyword = args(1).string_value (); |
|
712 double val = args(2).double_value (); |
287
|
713 do_npsol_option (keyword, val); |
|
714 } |
|
715 else |
|
716 print_usage ("npsol_options"); |
|
717 } |
|
718 else |
|
719 { |
|
720 print_usage ("npsol_options"); |
|
721 } |
|
722 |
272
|
723 return retval; |
|
724 } |
|
725 |
1
|
726 #endif |
|
727 |
|
728 /* |
|
729 ;;; Local Variables: *** |
|
730 ;;; mode: C++ *** |
|
731 ;;; page-delimiter: "^/\\*" *** |
|
732 ;;; End: *** |
|
733 */ |