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