3
|
1 // NPSOL.cc -*- C++ -*- |
|
2 /* |
|
3 |
1011
|
4 Copyright (C) 1992, 1993, 1994, 1995 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 |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
238
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
238
|
26 #endif |
|
27 |
|
28 #include <math.h> |
288
|
29 #include <float.h> |
287
|
30 #include <string.h> |
|
31 #include <strstream.h> |
238
|
32 |
3
|
33 #ifndef NPSOL_MISSING |
|
34 |
461
|
35 #include "dMatrix.h" |
|
36 |
3
|
37 #include "NPSOL.h" |
|
38 #include "f77-uscore.h" |
|
39 #include "sun-utils.h" |
|
40 |
|
41 extern "C" |
|
42 { |
1253
|
43 int F77_FCN (npoptn, NPOPTN) (const char*, long); |
3
|
44 |
1253
|
45 int F77_FCN (npsol, NPSOL) (int&, int&, int&, int&, int&, int&, |
|
46 double*, double*, double*, |
|
47 int (*)(int&, const int&, const int&, |
|
48 const int&, int*, double*, |
|
49 double*, double*, int*), |
|
50 int (*)(int&, const int&, double*, |
|
51 double*, double*, int*), |
|
52 int&, int&, int*, double*, double*, |
|
53 double*, double&, double*, double*, |
|
54 double*, int*, int&, double*, int&); |
3
|
55 } |
|
56 |
255
|
57 // XXX FIXME XXX -- would be nice to not have to have this global |
|
58 // variable. |
|
59 // Nonzero means an error occurred in the calculation of the objective |
|
60 // function, and the user wants us to quit. |
|
61 int npsol_objective_error = 0; |
|
62 |
3
|
63 static objective_fcn user_phi; |
|
64 static gradient_fcn user_grad; |
|
65 static nonlinear_fcn user_g; |
|
66 static jacobian_fcn user_jac; |
|
67 |
|
68 int |
1251
|
69 npsol_objfun (int& mode, const int& n, double *xx, double *objf, |
|
70 double *objgrd, int* nstate) |
3
|
71 { |
1251
|
72 Vector tmp_x (n); |
3
|
73 |
255
|
74 npsol_objective_error = 0; |
|
75 |
1251
|
76 for (int i = 0; i < n; i++) |
3
|
77 tmp_x.elem (i) = xx[i]; |
|
78 |
1251
|
79 if (mode == 0 || mode == 2) |
3
|
80 { |
|
81 double value = (*user_phi) (tmp_x); |
255
|
82 |
|
83 if (npsol_objective_error) |
|
84 { |
1251
|
85 mode = -1; |
255
|
86 return 0; |
|
87 } |
|
88 |
3
|
89 #if defined (sun) && defined (__GNUC__) |
|
90 assign_double (objf, value); |
|
91 #else |
|
92 *objf = value; |
|
93 #endif |
|
94 } |
|
95 |
1251
|
96 if ((mode == 1 || mode == 2) && user_grad) |
3
|
97 { |
1251
|
98 Vector tmp_grad (n); |
3
|
99 |
|
100 tmp_grad = (*user_grad) (tmp_x); |
|
101 |
255
|
102 if (tmp_grad.length () == 0) |
1251
|
103 mode = -1; |
255
|
104 else |
|
105 { |
1251
|
106 for (i = 0; i < n; i++) |
255
|
107 objgrd[i] = tmp_grad.elem (i); |
|
108 } |
3
|
109 } |
|
110 |
|
111 return 0; |
|
112 } |
|
113 |
|
114 int |
1251
|
115 npsol_confun (int& mode, const int& ncnln, const int& n, |
|
116 const int& nrowj, int* needc, double *xx, |
|
117 double *cons, double *cjac, int* nstate) |
3
|
118 { |
1251
|
119 Vector tmp_x (n); |
|
120 Vector tmp_c (ncnln); |
3
|
121 |
1251
|
122 for (int i = 0; i < n; i++) |
3
|
123 tmp_x.elem (i) = xx[i]; |
|
124 |
|
125 tmp_c = (*user_g) (tmp_x); |
|
126 |
255
|
127 if (tmp_c.length () == 0) |
|
128 { |
1251
|
129 mode = -1; |
255
|
130 return 0; |
|
131 } |
|
132 else |
|
133 { |
1251
|
134 for (i = 0; i < ncnln; i++) |
255
|
135 cons[i] = tmp_c.elem (i); |
|
136 } |
3
|
137 |
533
|
138 if (user_jac) |
3
|
139 { |
1251
|
140 Matrix tmp_jac (ncnln, n); |
3
|
141 |
|
142 tmp_jac = (*user_jac) (tmp_x); |
|
143 |
255
|
144 if (tmp_jac.rows () == 0 || tmp_jac.columns () == 0) |
1251
|
145 mode = -1; |
255
|
146 else |
|
147 { |
1251
|
148 int ld = nrowj; |
|
149 for (int j = 0; j < n; j++) |
|
150 for (i = 0; i < ncnln; i++) |
255
|
151 cjac[i+j*ld] = tmp_jac (i, j); |
|
152 } |
3
|
153 } |
|
154 |
|
155 return 0; |
|
156 } |
|
157 |
|
158 Vector |
|
159 NPSOL::minimize (void) |
|
160 { |
|
161 double objf; |
|
162 int inform; |
|
163 Vector lambda; |
|
164 return minimize (objf, inform, lambda); |
|
165 } |
|
166 |
|
167 Vector |
|
168 NPSOL::minimize (double& objf) |
|
169 { |
|
170 int inform; |
|
171 Vector lambda; |
|
172 return minimize (objf, inform, lambda); |
|
173 } |
|
174 |
|
175 Vector |
|
176 NPSOL::minimize (double& objf, int& inform) |
|
177 { |
|
178 Vector lambda; |
|
179 return minimize (objf, inform, lambda); |
|
180 } |
|
181 |
|
182 Vector |
|
183 NPSOL::minimize (double& objf, int& inform, Vector& lambda) |
|
184 { |
656
|
185 // Dimensions of various things. |
3
|
186 |
|
187 int n = x.capacity (); |
|
188 int nclin = lc.size (); |
|
189 int ncnln = nlc.size (); |
|
190 int nrowa = 1 > nclin ? 1 : nclin; |
|
191 int nrowj = 1 > ncnln ? 1 : ncnln; |
|
192 int nrowr = n; |
|
193 |
656
|
194 // Informative stuff. |
3
|
195 |
|
196 int iter; |
|
197 int *istate = new int [n+nclin+ncnln]; |
|
198 |
656
|
199 // User defined function stuff is defined above in the functions |
|
200 // npsol_confun() and npsol_objfun(); |
3
|
201 |
656
|
202 // Constraint stuff. |
3
|
203 |
|
204 double dummy; |
|
205 double *pclin = &dummy; |
|
206 Matrix clin; |
|
207 if (nclin > 0) |
|
208 { |
|
209 clin = lc.constraint_matrix (); |
|
210 pclin = clin.fortran_vec (); |
|
211 } |
|
212 |
|
213 double *clow = new double [n+nclin+ncnln]; |
|
214 double *cup = new double [n+nclin+ncnln]; |
|
215 |
|
216 if (bnds.size () > 0) |
|
217 { |
|
218 for (int i = 0; i < n; i++) |
|
219 { |
|
220 clow[i] = bnds.lower_bound (i); |
|
221 cup[i] = bnds.upper_bound (i); |
|
222 } |
|
223 } |
|
224 else |
|
225 { |
|
226 double huge = 1.0e30; |
|
227 for (int i = 0; i < n; i++) |
|
228 { |
|
229 clow[i] = -huge; |
|
230 cup[i] = huge; |
|
231 } |
|
232 } |
|
233 |
|
234 for (int i = 0; i < nclin; i++) |
|
235 { |
|
236 clow[i+n] = lc.lower_bound (i); |
|
237 cup[i+n] = lc.upper_bound (i); |
|
238 } |
|
239 |
|
240 for (i = 0; i < ncnln; i++) |
|
241 { |
|
242 clow[i+n+nclin] = nlc.lower_bound (i); |
|
243 cup[i+n+nclin] = nlc.upper_bound (i); |
|
244 } |
|
245 |
656
|
246 double *c = 0; |
|
247 double *cjac = 0; |
3
|
248 if (ncnln > 0) |
|
249 { |
|
250 c = new double [ncnln]; |
|
251 cjac = new double [nrowj*n]; |
|
252 } |
|
253 |
656
|
254 // Objective stuff. |
3
|
255 |
|
256 double *objgrd = new double [n]; |
|
257 |
656
|
258 // Other stuff. |
3
|
259 |
|
260 double *r = new double [n*n]; |
|
261 |
|
262 lambda.resize (n+nclin+ncnln); |
|
263 double *pclambda = lambda.fortran_vec (); |
|
264 |
656
|
265 // Decision variable stuff. |
3
|
266 |
|
267 double *px = x.fortran_vec (); |
|
268 |
656
|
269 // Workspace parameters. |
3
|
270 |
|
271 int lenw; |
|
272 int leniw = 3 * n + nclin + 2 * ncnln; |
|
273 if (nclin == 0 && ncnln == 0) |
|
274 lenw = 20*n; |
|
275 else if (ncnln == 0) |
|
276 lenw = 2*n*(10 + n) + 11*nclin; |
|
277 else |
|
278 lenw = 2*n*(n + 10) + nclin*(n + 11) + ncnln*(2*n + 21); |
|
279 |
|
280 int *iw = new int [leniw]; |
|
281 double *w = new double [lenw]; |
|
282 |
|
283 user_phi = phi.objective_function (); |
|
284 user_grad = phi.gradient_function (); |
|
285 user_g = nlc.function (); |
|
286 user_jac = nlc.jacobian_function (); |
|
287 |
287
|
288 pass_options_to_npsol (); |
3
|
289 |
533
|
290 if (! user_jac && ! user_grad) |
1253
|
291 F77_FCN (npoptn, NPOPTN) ("Derivative Level 0", 18L); |
533
|
292 else if (! user_jac && user_grad) |
1253
|
293 F77_FCN (npoptn, NPOPTN) ("Derivative Level 1", 18L); |
533
|
294 else if (user_jac && ! user_grad) |
1253
|
295 F77_FCN (npoptn, NPOPTN) ("Derivative Level 2", 18L); |
533
|
296 else if (user_jac && user_grad) |
1253
|
297 F77_FCN (npoptn, NPOPTN) ("Derivative Level 3", 18L); |
3
|
298 |
130
|
299 int attempt = 0; |
|
300 while (attempt++ < 5) |
3
|
301 { |
|
302 |
1253
|
303 F77_FCN (npsol, NPSOL) (n, nclin, ncnln, nrowa, nrowj, nrowr, |
|
304 pclin, clow, cup, npsol_confun, |
|
305 npsol_objfun, inform, iter, istate, c, |
|
306 cjac, pclambda, objf, objgrd, r, px, iw, |
|
307 leniw, w, lenw); |
3
|
308 |
|
309 if (inform == 6 || inform == 1) |
|
310 continue; |
|
311 else |
|
312 break; |
|
313 } |
|
314 |
656
|
315 // Clean up. |
|
316 |
|
317 delete [] istate; |
|
318 delete [] clow; |
|
319 delete [] cup; |
|
320 delete [] c; |
658
|
321 delete [] cjac; |
656
|
322 delete [] objgrd; |
|
323 delete [] r; |
|
324 delete [] iw; |
|
325 delete [] w; |
|
326 |
|
327 // See how it went. |
3
|
328 |
|
329 return x; |
|
330 } |
|
331 |
|
332 Vector |
|
333 NPSOL::minimize (const Vector& xnew) |
|
334 { |
|
335 x = xnew; |
|
336 return minimize (); |
|
337 } |
|
338 |
|
339 Vector |
|
340 NPSOL::minimize (const Vector& xnew, double& objf) |
|
341 { |
|
342 x = xnew; |
|
343 return minimize (objf); |
|
344 } |
|
345 |
|
346 Vector |
|
347 NPSOL::minimize (const Vector& xnew, double& objf, int& inform) |
|
348 { |
|
349 x = xnew; |
|
350 return minimize (objf, inform); |
|
351 } |
|
352 |
|
353 Vector |
|
354 NPSOL::minimize (const Vector& xnew, double& objf, int& inform, Vector& lambda) |
|
355 { |
|
356 x = xnew; |
|
357 return minimize (objf, inform, lambda); |
|
358 } |
|
359 |
|
360 NPSOL& |
|
361 NPSOL::option (char *s) |
|
362 { |
287
|
363 cerr << "This function no longer has any effect.\n" |
|
364 << "Use the NPSOL_option class instead\n"; |
|
365 |
|
366 return *this; |
|
367 } |
|
368 |
|
369 NPSOL_options::NPSOL_options (void) |
|
370 { |
|
371 init (); |
|
372 } |
|
373 |
|
374 NPSOL_options::NPSOL_options (const NPSOL_options& opt) |
|
375 { |
|
376 copy (opt); |
|
377 } |
|
378 |
|
379 NPSOL_options& |
|
380 NPSOL_options::operator = (const NPSOL_options& opt) |
|
381 { |
|
382 if (this != &opt) |
|
383 copy (opt); |
|
384 |
3
|
385 return *this; |
|
386 } |
|
387 |
287
|
388 NPSOL_options::~NPSOL_options (void) |
|
389 { |
|
390 } |
|
391 |
|
392 void |
|
393 NPSOL_options::init (void) |
|
394 { |
|
395 x_central_difference_interval = -1.0; |
|
396 x_crash_tolerance = 0.1; |
|
397 x_difference_interval = -1.0; |
|
398 x_function_precision = pow (DBL_EPSILON, 0.9); |
|
399 x_infinite_bound = 1.0e+30; |
|
400 x_infinite_step = 1.0e+30; |
|
401 x_linear_feasibility_tolerance = sqrt (DBL_EPSILON); |
|
402 x_linesearch_tolerance = 0.9; |
|
403 x_nonlinear_feasibility_tolerance = sqrt (DBL_EPSILON); |
|
404 x_optimality_tolerance = pow (DBL_EPSILON, 0.8); |
|
405 x_derivative_level = 0; |
|
406 x_major_iteration_limit = -1; |
|
407 x_minor_iteration_limit = -1; |
|
408 x_major_print_level = 0; |
|
409 x_minor_print_level = 0; |
|
410 x_start_objective_check = 1; |
|
411 x_start_constraint_check = 1; |
|
412 x_stop_objective_check = -1; |
|
413 x_stop_constraint_check = -1; |
|
414 x_verify_level = 0; |
|
415 } |
|
416 |
|
417 void |
|
418 NPSOL_options::copy (const NPSOL_options& opt) |
|
419 { |
|
420 x_central_difference_interval = opt.x_central_difference_interval; |
|
421 x_crash_tolerance = opt.x_crash_tolerance; |
|
422 x_difference_interval = opt.x_difference_interval; |
|
423 x_function_precision = opt.x_function_precision; |
|
424 x_infinite_bound = opt.x_infinite_bound; |
|
425 x_infinite_step = opt.x_infinite_step; |
|
426 x_linear_feasibility_tolerance = opt.x_linear_feasibility_tolerance; |
|
427 x_linesearch_tolerance = opt.x_linesearch_tolerance; |
|
428 x_nonlinear_feasibility_tolerance = opt.x_nonlinear_feasibility_tolerance; |
|
429 x_optimality_tolerance = opt.x_optimality_tolerance; |
|
430 x_derivative_level = opt.x_derivative_level; |
|
431 x_major_iteration_limit = opt.x_major_iteration_limit; |
|
432 x_minor_iteration_limit = opt.x_minor_iteration_limit; |
|
433 x_major_print_level = opt.x_major_print_level; |
|
434 x_minor_print_level = opt.x_minor_print_level; |
|
435 x_start_objective_check = opt.x_start_objective_check; |
|
436 x_start_constraint_check = opt.x_start_constraint_check; |
|
437 x_stop_objective_check = opt.x_stop_objective_check; |
|
438 x_stop_constraint_check = opt.x_stop_constraint_check; |
|
439 x_verify_level = opt.x_verify_level; |
|
440 } |
|
441 |
|
442 void |
|
443 NPSOL_options::set_default_options (void) |
|
444 { |
|
445 init (); |
|
446 } |
|
447 |
|
448 /* |
|
449 * Passing invalid values to the set_* functions will result in |
|
450 * setting the default option. |
|
451 */ |
|
452 |
|
453 void |
|
454 NPSOL_options::set_central_difference_interval (double val) |
|
455 { |
|
456 x_central_difference_interval = (val > 0.0) ? val : -1.0; |
|
457 } |
|
458 |
|
459 void |
|
460 NPSOL_options::set_crash_tolerance (double val) |
|
461 { |
|
462 x_crash_tolerance = (val >= 0.0) ? val : 0.1; |
|
463 } |
|
464 |
|
465 void |
|
466 NPSOL_options::set_difference_interval (double val) |
|
467 { |
|
468 x_difference_interval = (val > 0.0) ? val : -1.0; |
|
469 } |
|
470 |
|
471 void |
|
472 NPSOL_options::set_function_precision (double val) |
|
473 { |
|
474 x_function_precision = (val > 0.0) ? val : pow (DBL_EPSILON, 0.9); |
|
475 } |
|
476 |
|
477 void |
|
478 NPSOL_options::set_infinite_bound (double val) |
|
479 { |
|
480 x_infinite_bound = (val > 0.0) ? val : 1.0e+30; |
|
481 } |
|
482 |
|
483 void |
|
484 NPSOL_options::set_infinite_step (double val) |
|
485 { |
|
486 x_infinite_step = (val > 0.0) ? val : 1.0e+30; |
|
487 } |
|
488 |
|
489 void |
|
490 NPSOL_options::set_linear_feasibility_tolerance (double val) |
|
491 { |
|
492 x_linear_feasibility_tolerance = (val > 0.0) ? val : sqrt (DBL_EPSILON); |
|
493 } |
|
494 |
|
495 void |
|
496 NPSOL_options::set_linesearch_tolerance (double val) |
|
497 { |
|
498 x_linesearch_tolerance = (val >= 0.0 && val < 1.0) ? val : 0.9; |
|
499 } |
|
500 |
|
501 void |
|
502 NPSOL_options::set_nonlinear_feasibility_tolerance (double val) |
|
503 { |
|
504 x_nonlinear_feasibility_tolerance = (val > 0.0) ? val : sqrt (DBL_EPSILON); |
|
505 } |
|
506 |
|
507 void |
|
508 NPSOL_options::set_optimality_tolerance (double val) |
|
509 { |
|
510 x_optimality_tolerance = (val > 0.0) ? val : pow (DBL_EPSILON, 0.8); |
|
511 } |
|
512 |
|
513 void |
|
514 NPSOL_options::set_derivative_level (int val) |
|
515 { |
|
516 x_derivative_level = (val >= 0 && val < 4) ? val : 0; |
|
517 } |
|
518 |
|
519 void |
|
520 NPSOL_options::set_major_iteration_limit (int val) |
|
521 { |
|
522 x_major_iteration_limit = (val > 0) ? val : -1; |
|
523 } |
|
524 |
|
525 void |
|
526 NPSOL_options::set_minor_iteration_limit (int val) |
|
527 { |
|
528 x_minor_iteration_limit = (val > 0) ? val : -1; |
|
529 } |
|
530 |
|
531 void |
|
532 NPSOL_options::set_major_print_level (int val) |
|
533 { |
|
534 x_major_print_level = (val >= 0) ? val : -1; |
|
535 } |
|
536 |
|
537 void |
|
538 NPSOL_options::set_minor_print_level (int val) |
|
539 { |
|
540 x_minor_print_level = (val >= 0) ? val : -1; |
|
541 } |
|
542 |
|
543 void |
|
544 NPSOL_options::set_start_objective_check (int val) |
|
545 { |
|
546 x_start_objective_check = (val >= 0) ? val : -1; |
|
547 } |
|
548 |
|
549 void |
|
550 NPSOL_options::set_start_constraint_check (int val) |
|
551 { |
|
552 x_start_constraint_check = (val >= 0) ? val : -1; |
|
553 } |
|
554 |
|
555 void |
|
556 NPSOL_options::set_stop_objective_check (int val) |
|
557 { |
|
558 x_stop_objective_check = (val >= 0) ? val : -1; |
|
559 } |
|
560 |
3
|
561 void |
287
|
562 NPSOL_options::set_stop_constraint_check (int val) |
|
563 { |
|
564 x_stop_constraint_check = (val >= 0) ? val : -1; |
|
565 } |
|
566 |
|
567 void |
|
568 NPSOL_options::set_verify_level (int val) |
|
569 { |
|
570 x_verify_level = ((val > -1 && val < 4) || (val > 9 && val < 14)) ? val : 0; |
|
571 } |
|
572 |
|
573 double |
|
574 NPSOL_options::central_difference_interval (void) const |
|
575 { |
|
576 return x_central_difference_interval; |
|
577 } |
|
578 |
|
579 double |
|
580 NPSOL_options::crash_tolerance (void) const |
|
581 { |
|
582 return x_crash_tolerance; |
|
583 } |
|
584 |
|
585 double |
|
586 NPSOL_options::difference_interval (void) const |
|
587 { |
|
588 return x_difference_interval; |
|
589 } |
|
590 |
|
591 double |
|
592 NPSOL_options::function_precision (void) const |
|
593 { |
|
594 return x_function_precision; |
|
595 } |
|
596 |
|
597 double |
|
598 NPSOL_options::infinite_bound (void) const |
|
599 { |
|
600 return x_infinite_bound; |
|
601 } |
|
602 |
|
603 double |
|
604 NPSOL_options::infinite_step (void) const |
|
605 { |
|
606 return x_infinite_step; |
|
607 } |
|
608 |
|
609 double |
|
610 NPSOL_options::linear_feasibility_tolerance (void) const |
|
611 { |
|
612 return x_linear_feasibility_tolerance; |
|
613 } |
|
614 |
|
615 double |
|
616 NPSOL_options::linesearch_tolerance (void) const |
|
617 { |
|
618 return x_linesearch_tolerance; |
|
619 } |
|
620 |
|
621 double |
|
622 NPSOL_options::nonlinear_feasibility_tolerance (void) const |
|
623 { |
|
624 return x_nonlinear_feasibility_tolerance; |
|
625 } |
|
626 |
|
627 double |
|
628 NPSOL_options::optimality_tolerance (void) const |
|
629 { |
|
630 return x_optimality_tolerance; |
|
631 } |
|
632 |
|
633 int |
|
634 NPSOL_options::derivative_level (void) const |
|
635 { |
|
636 return x_derivative_level; |
|
637 } |
|
638 |
|
639 int |
|
640 NPSOL_options::major_iteration_limit (void) const |
|
641 { |
|
642 return x_major_iteration_limit; |
|
643 } |
|
644 |
|
645 int |
|
646 NPSOL_options::minor_iteration_limit (void) const |
|
647 { |
|
648 return x_minor_iteration_limit; |
|
649 } |
|
650 |
|
651 int |
|
652 NPSOL_options::major_print_level (void) const |
|
653 { |
|
654 return x_major_print_level; |
|
655 } |
|
656 |
|
657 int |
|
658 NPSOL_options::minor_print_level (void) const |
|
659 { |
|
660 return x_minor_print_level; |
|
661 } |
|
662 |
|
663 int |
|
664 NPSOL_options::start_objective_check (void) const |
|
665 { |
|
666 return x_start_objective_check; |
|
667 } |
|
668 |
|
669 int |
|
670 NPSOL_options::start_constraint_check (void) const |
|
671 { |
|
672 return x_start_constraint_check; |
|
673 } |
|
674 |
|
675 int |
|
676 NPSOL_options::stop_objective_check (void) const |
|
677 { |
|
678 return x_stop_objective_check; |
|
679 } |
|
680 |
|
681 int |
|
682 NPSOL_options::stop_constraint_check (void) const |
|
683 { |
|
684 return x_stop_constraint_check; |
|
685 } |
|
686 |
|
687 int |
|
688 NPSOL_options::verify_level (void) const |
|
689 { |
|
690 return x_verify_level; |
|
691 } |
|
692 |
|
693 void |
|
694 NPSOL_options::pass_options_to_npsol (void) |
3
|
695 { |
1253
|
696 F77_FCN (npoptn, NPOPTN) ("Nolist", 6L); |
|
697 F77_FCN (npoptn, NPOPTN) ("Defaults", 8L); |
287
|
698 |
|
699 if (x_central_difference_interval > 0.0) |
|
700 set_option ("Central Difference", x_central_difference_interval); |
|
701 |
|
702 set_option ("Crash Tolerance", x_crash_tolerance); |
|
703 |
|
704 if (x_difference_interval > 0.0) |
|
705 set_option ("Difference Interval", x_difference_interval); |
|
706 |
|
707 set_option ("Function Precision", x_function_precision); |
|
708 |
|
709 set_option ("Infinite Bound", x_infinite_bound); |
|
710 |
|
711 set_option ("Infinite Step", x_infinite_step); |
|
712 |
|
713 set_option ("Linear Feasibility", x_linear_feasibility_tolerance); |
|
714 |
|
715 set_option ("Linesearch Tolerance", x_linesearch_tolerance); |
|
716 |
|
717 set_option ("Nonlinear Feasibility", x_nonlinear_feasibility_tolerance); |
|
718 |
|
719 set_option ("Optimality Tolerance", x_optimality_tolerance); |
|
720 |
|
721 set_option ("Derivative Level", x_derivative_level); |
|
722 |
|
723 if (x_major_iteration_limit > 0) |
|
724 set_option ("Major Iteration", x_major_iteration_limit); |
|
725 |
|
726 if (x_minor_iteration_limit > 0) |
|
727 set_option ("Minor Iteration", x_minor_iteration_limit); |
|
728 |
|
729 set_option ("Major Print", x_major_print_level); |
|
730 |
|
731 set_option ("Minor Print", x_minor_print_level); |
|
732 |
|
733 set_option ("Start Objective", x_start_objective_check); |
|
734 |
|
735 set_option ("Start Constraint", x_start_constraint_check); |
|
736 |
|
737 if (x_stop_objective_check > 0) |
|
738 set_option ("Stop Objective", x_stop_objective_check); |
|
739 |
|
740 if (x_stop_constraint_check > 0) |
|
741 set_option ("Stop Constraint", x_stop_constraint_check); |
|
742 |
|
743 set_option ("Verify Level", x_verify_level); |
|
744 } |
|
745 |
|
746 void |
|
747 NPSOL_options::set_option (const char *key, int opt) |
|
748 { |
|
749 ostrstream buf; |
|
750 buf << key << " " << opt << ends; |
|
751 char *command = buf.str (); |
|
752 size_t len = strlen (command); |
1253
|
753 F77_FCN (npoptn, NPOPTN) (command, (long) len); |
287
|
754 delete [] command; |
|
755 } |
|
756 |
|
757 void |
|
758 NPSOL_options::set_option (const char *key, double opt) |
|
759 { |
|
760 ostrstream buf; |
|
761 buf << key << " " << opt << ends; |
|
762 char *command = buf.str (); |
|
763 size_t len = strlen (command); |
1253
|
764 F77_FCN (npoptn, NPOPTN) (command, (long) len); |
287
|
765 delete [] command; |
3
|
766 } |
|
767 |
|
768 #endif /* NPSOL_MISSING */ |
|
769 |
|
770 /* |
|
771 ;;; Local Variables: *** |
|
772 ;;; mode: C++ *** |
|
773 ;;; page-delimiter: "^/\\*" *** |
|
774 ;;; End: *** |
|
775 */ |