MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NLPInterfacePack_CalcFiniteDiffProd.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #include <assert.h>
43 #include <math.h>
44 
45 #include <typeinfo>
46 #include <iomanip>
47 #include <sstream>
48 #include <limits>
49 
51 #include "NLPInterfacePack_NLP.hpp"
58 #include "Teuchos_FancyOStream.hpp"
59 #include "Teuchos_Assert.hpp"
60 
61 namespace NLPInterfacePack {
62 
64  EFDMethodOrder fd_method_order
65  ,EFDStepSelect fd_step_select
66  ,value_type fd_step_size
67  ,value_type fd_step_size_min
68  ,value_type fd_step_size_f
69  ,value_type fd_step_size_c
70  )
71  :fd_method_order_(fd_method_order)
72  ,fd_step_select_(fd_step_select)
73  ,fd_step_size_(fd_step_size)
74  ,fd_step_size_min_(fd_step_size_min)
75  ,fd_step_size_f_(fd_step_size_f)
76  ,fd_step_size_c_(fd_step_size_c)
77 {}
78 
80  const Vector &xo
81  ,const Vector *xl
82  ,const Vector *xu
83  ,const Vector &v
84  ,const value_type *fo
85  ,const Vector *co
86  ,bool check_nan_inf
87  ,NLP *nlp
88  ,value_type *Gf_prod
89  ,VectorMutable *Gc_prod
90  ,std::ostream *out_arg
91  ,bool trace
92  ,bool dump_all
93  ) const
94 {
95 
96  using std::setw;
97  using std::endl;
98  using std::right;
99 
100  using BLAS_Cpp::rows;
101  using BLAS_Cpp::cols;
102 
103  typedef VectorSpace::vec_mut_ptr_t vec_mut_ptr_t;
108  using LinAlgOpPack::V_StV;
109 
111  out = Teuchos::getFancyOStream(Teuchos::rcp(out_arg,false));
112  Teuchos::OSTab tab(out);
113 
114  //
115  // The gradient of the contraints is defined as the matrix Gc as:
116  //
117  // Gc= [ Gc1, Gc2, ..., Gcm ]
118  //
119  // [ dc1/dx(1) dc2/dx(1) ... dcm/dx(1) ]
120  // [ dc1/dx(2) dc2/dx(2) ... dcm/dx(2) ]
121  // Gc= [ . . ... . ]
122  // [ dc1/dx(n) dc2/dx(n) ... dcm/dx(n) ]
123  //
124  // [ (dc/dx(1))' ]
125  // [ (dc/dx(2))' ]
126  // Gc= [ . ]
127  // [ (dc/dx(n))' ]
128  //
129  // The gradient of the objective function is defined as the
130  // vector Gf as:
131  //
132  // [ (df/dx(1))' ]
133  // [ (df/dx(2))' ]
134  // Gf= [ . ]
135  // [ (df/dx(n))' ]
136  //
137  // To illustrate the theory behind this implementation consider
138  // the generic multi-variable function g(x) <: R^n -> R. Now let's
139  // consider we have the base point xo and the vector v to
140  // perturb g(x) along. First form the function g(xo+a*v) and then
141  // let's compute dg/da at a = 0:
142  //
143  // (1) d(g(xo+a*v))/d(a) at a = 0
144  // = sum( dg/dx(i) * dx(i)/da, i = 1...n)
145  // = sum( dg/dx(i) * v(i), i = 1...n)
146  // = Gf'*v
147  //
148  // Now we can approximate (1) using central differences as:
149  //
150  // (2) d(g(xo+a*v))/d(a) at a = 0
151  // \approx ( g(xo+h*v) - g(xo+h*v) ) / (2*h)
152  //
153  // If we equate (1) and (2) we have the approximation:
154  //
155  // (3) Gg' * v \approx ( g(xo+h*v) - g(xo+h*v) ) / (2*h)
156  //
157  // It should be clear how this applies to computing Gf'*v and Gc'*v.
158  //
159 
160  const size_type
161  n = nlp->n(),
162  m = nlp->m();
163 
164  const value_type
165  max_bnd_viol = nlp->max_var_bounds_viol();
166 
167  // /////////////////////////////////////////
168  // Validate the input
169 
171  m==0 && Gc_prod, std::invalid_argument
172  ,"CalcFiniteDiffProd::calc_deriv(...) : "
173  "Error, if nlp->m() == 0, then Gc_prod must equal NULL" );
175  Gc_prod && !Gc_prod->space().is_compatible(*nlp->space_c())
176  ,std::invalid_argument
177  ,"CalcFiniteDiffProd::calc_deriv(...) : "
178  "Error, Gc_prod (type \' "<<typeName(*Gc_prod)<<"\' "
179  "is not compatible with the NLP" );
181  (xl && !xu) || (!xl && xu), std::invalid_argument
182  ,"CalcFiniteDiffProd::calc_deriv(...) : "
183  "Error, both xl = "<<xl<<" and xu = "<<xu
184  <<" must be NULL or not NULL" );
185 
186  assert_print_nan_inf(xo,"xo",true,out.get());
187 
188  switch(this->fd_method_order()) {
189  case FD_ORDER_ONE:
190  if(out.get()&&trace) *out<<"\nUsing one-sided, first-order finite differences ...\n";
191  break;
192  case FD_ORDER_TWO:
193  if(out.get()&&trace) *out<<"\nUsing one-sided, second-order finite differences ...\n";
194  break;
196  if(out.get()&&trace) *out<<"\nUsing second-order central finite differences ...\n";
197  break;
198  case FD_ORDER_TWO_AUTO:
199  if(out.get()&&trace) *out<<"\nUsing auto selection of some second-order finite difference method ...\n";
200  break;
201  case FD_ORDER_FOUR:
202  if(out.get()&&trace) *out<<"\nUsing one-sided, fourth-order finite differences ...\n";
203  break;
205  if(out.get()&&trace) *out<<"\nUsing fourth-order central finite differences ...\n";
206  break;
207  case FD_ORDER_FOUR_AUTO:
208  if(out.get()&&trace) *out<<"\nUsing auto selection of some fourth-order finite difference method ...\n";
209  break;
210  default:
211  TEUCHOS_TEST_FOR_EXCEPT(true); // Should not get here!
212  }
213 
214  // ////////////////////////
215  // Find the step size
216 
217  //
218  // Get defaults for the optimal step sizes
219  //
220 
221  const value_type
222  sqrt_epsilon = ::pow(std::numeric_limits<value_type>::epsilon(),1.0/2.0),
223  u_optimal_1 = sqrt_epsilon,
224  u_optimal_2 = ::pow(sqrt_epsilon,1.0/2.0),
225  u_optimal_4 = ::pow(sqrt_epsilon,1.0/4.0),
226  xo_norm_inf = xo.norm_inf();
227 
228  value_type
229  uh_opt = 0.0;
230  switch(this->fd_method_order()) {
231  case FD_ORDER_ONE:
232  uh_opt = u_optimal_1 * ( fd_step_select() == FD_STEP_ABSOLUTE ? 1.0 : xo_norm_inf + 1.0 );
233  break;
234  case FD_ORDER_TWO:
236  case FD_ORDER_TWO_AUTO:
237  uh_opt = u_optimal_2 * ( fd_step_select() == FD_STEP_ABSOLUTE ? 1.0 : xo_norm_inf + 1.0 );
238  break;
239  case FD_ORDER_FOUR:
241  case FD_ORDER_FOUR_AUTO:
242  uh_opt = u_optimal_4 * ( fd_step_select() == FD_STEP_ABSOLUTE ? 1.0 : xo_norm_inf + 1.0 );
243  break;
244  default:
245  TEUCHOS_TEST_FOR_EXCEPT(true); // Should not get here!
246  }
247 
248  if(out.get()&&trace) *out<<"\nDefault optimal step length uh_opt = " << uh_opt << " ...\n";
249 
250  //
251  // Set the step sizes used.
252  //
253 
254  value_type
255  uh = this->fd_step_size(),
256  uh_f = this->fd_step_size_f(),
257  uh_c = this->fd_step_size_c(),
258  uh_min = this->fd_step_size_min();
259 
260  // uh
261  if( uh < 0 )
262  uh = uh_opt;
263  else if(fd_step_select() == FD_STEP_RELATIVE)
264  uh *= (xo_norm_inf + 1.0);
265  // uh_f
266  if( uh_f < 0 )
267  uh_f = uh;
268  else if(fd_step_select() == FD_STEP_RELATIVE)
269  uh_f *= (xo_norm_inf + 1.0);
270  // uh_c
271  if( uh_c < 0 )
272  uh_c = uh;
273  else if(fd_step_select() == FD_STEP_RELATIVE)
274  uh_c *= (xo_norm_inf + 1.0);
275 
276  if(out.get()&&trace) *out<<"\nIndividual step sizes initally set: uh="<<uh<<",uh_f="<<uh_f<<",uh_c="<<uh_c<<"\n";
277 
278  //
279  // Determine the maximum step size that can be used and
280  // still stay in the relaxed bounds.
281  //
282  // ToDo: Consider cramped bounds, one sided differences!
283  //
284 
286  if( xl ) {
287  std::pair<value_type,value_type>
288  u_pn
290  xo
291  ,v
292  ,*xl
293  ,*xu
294  ,max_bnd_viol
295  );
296  if( u_pn.first < -u_pn.second )
297  max_u_feas = u_pn.first;
298  else
299  max_u_feas = u_pn.second;
300  const value_type abs_max_u_feas = ::fabs(max_u_feas);
301  if( abs_max_u_feas < uh ) {
302  if( abs_max_u_feas < uh_min ) {
303  if(out.get())
304  *out
305  << "Warning, the size of the maximum finite difference step length\n"
306  << "that does not violate the relaxed variable bounds uh = "
307  << max_u_feas << " is less than the mimimum allowable step length\n"
308  << "uh_min = " << uh_min << " and the finite difference "
309  << "derivatives are not computed!\n";
310  return false;
311  }
312  if(out.get())
313  *out
314  << "Warning, the size of the maximum finite difference step length\n"
315  << "that does not violate the relaxed variable bounds uh = "
316  << max_u_feas << " is less than the desired step length\n"
317  << "uh = " << uh << " and the finite difference "
318  << "derivatives may be much less accurate!\n";
319  }
320  }
321 
322  //
323  // Set the actual method being used
324  //
325  // ToDo: Consider cramped bounds and method order.
326  //
327 
328  EFDMethodOrder fd_method_order = this->fd_method_order();
329  switch(fd_method_order) {
330  case FD_ORDER_TWO_AUTO:
331  fd_method_order = FD_ORDER_TWO_CENTRAL;
332  break;
333  case FD_ORDER_FOUR_AUTO:
334  fd_method_order = FD_ORDER_FOUR_CENTRAL;
335  break;
336  }
337 
338  // Compute the actual individual step size so as to stay in bounds
339  const value_type
340  abs_max_u_feas = ::fabs(max_u_feas);
341  value_type
342  num_u_i = 0;
343  switch(fd_method_order) {
344  case FD_ORDER_ONE:
345  num_u_i = 1.0;
346  break;
347  case FD_ORDER_TWO:
348  num_u_i = 2.0;
349  break;
351  num_u_i = 1.0;
352  break;
353  case FD_ORDER_FOUR:
354  num_u_i = 4.0;
355  break;
357  num_u_i = 2.0;
358  break;
359  default:
360  TEUCHOS_TEST_FOR_EXCEPT(true); // Should not get here!
361  }
362 
363  uh = ( abs_max_u_feas/num_u_i < uh ? max_u_feas/num_u_i : uh ); // This can be a negative number!
364  uh_f = ( abs_max_u_feas/num_u_i < uh_f ? max_u_feas/num_u_i : uh_f ); //""
365  uh_c = ( abs_max_u_feas/num_u_i < uh_c ? max_u_feas/num_u_i : uh_c ); //""
366 
367  if( uh_min < 0 ) {
368  uh_min = uh / 100.0;
369  }
370 
371  if(out.get()&&trace) *out<<"\nIndividual step sizes to fit in bounds: uh="<<uh<<",uh_f="<<uh_f<<",uh_c="<<uh_c<<"\n";
372 
373  //
374  // Remember some stuff
375  //
376 
377  value_type *f_saved = NULL;
378  VectorMutable *c_saved = NULL;
379 
380  f_saved = nlp->get_f();
381  if(m) c_saved = nlp->get_c();
382 
383  int p_saved;
384  if(out.get())
385  p_saved = out->precision();
386 
387  // ///////////////////////////////////////////////
388  // Compute the directional derivatives
389 
390  try {
391 
392  value_type
393  f;
394  vec_mut_ptr_t
395  x = nlp->space_x()->create_member();
396  vec_mut_ptr_t
397  c = m && Gc_prod ? nlp->space_c()->create_member() : Teuchos::null;
398 
399  // Set the quanitities used to compute with
400 
401  nlp->set_f(&f);
402  if(m) nlp->set_c( c.get() );
403 
404  const int dbl_p = 15;
405  if(out.get())
406  *out << std::setprecision(dbl_p);
407 
408  //
409  // Compute the weighted sum of the terms
410  //
411 
412  int num_evals = 0;
413  value_type dwgt = 0.0;
414  switch(fd_method_order) {
415  case FD_ORDER_ONE: // may only need one eval if f(xo) etc is passed in
416  num_evals = 2;
417  dwgt = 1.0;
418  break;
419  case FD_ORDER_TWO: // may only need two evals if c(xo) etc is passed in
420  num_evals = 3;
421  dwgt = 2.0;
422  break;
424  num_evals = 2;
425  dwgt = 2.0;
426  break;
427  case FD_ORDER_FOUR:
428  num_evals = 5;
429  dwgt = 12.0;
430  break;
432  num_evals = 5;
433  dwgt = 12.0;
434  break;
435  default:
436  TEUCHOS_TEST_FOR_EXCEPT(true); // Should not get here!
437  }
438  if(Gc_prod) *Gc_prod = 0.0;
439  if(Gf_prod) *Gf_prod = 0.0;
440  for( int eval_i = 1; eval_i <= num_evals; ++eval_i ) {
441  // Set the step constant and the weighting constant
442  value_type
443  uh_i = 0.0,
444  wgt_i = 0.0;
445  switch(fd_method_order) {
446  case FD_ORDER_ONE: {
447  switch(eval_i) {
448  case 1:
449  uh_i = +0.0;
450  wgt_i = -1.0;
451  break;
452  case 2:
453  uh_i = +1.0;
454  wgt_i = +1.0;
455  break;
456  }
457  break;
458  }
459  case FD_ORDER_TWO: {
460  switch(eval_i) {
461  case 1:
462  uh_i = +0.0;
463  wgt_i = -3.0;
464  break;
465  case 2:
466  uh_i = +1.0;
467  wgt_i = +4.0;
468  break;
469  case 3:
470  uh_i = +2.0;
471  wgt_i = -1.0;
472  break;
473  }
474  break;
475  }
476  case FD_ORDER_TWO_CENTRAL: {
477  switch(eval_i) {
478  case 1:
479  uh_i = -1.0;
480  wgt_i = -1.0;
481  break;
482  case 2:
483  uh_i = +1.0;
484  wgt_i = +1.0;
485  break;
486  }
487  break;
488  }
489  case FD_ORDER_FOUR: {
490  switch(eval_i) {
491  case 1:
492  uh_i = +0.0;
493  wgt_i = -25.0;
494  break;
495  case 2:
496  uh_i = +1.0;
497  wgt_i = +48.0;
498  break;
499  case 3:
500  uh_i = +2.0;
501  wgt_i = -36.0;
502  break;
503  case 4:
504  uh_i = +3.0;
505  wgt_i = +16.0;
506  break;
507  case 5:
508  uh_i = +4.0;
509  wgt_i = -3.0;
510  break;
511  }
512  break;
513  }
514  case FD_ORDER_FOUR_CENTRAL: {
515  switch(eval_i) {
516  case 1:
517  uh_i = -2.0;
518  wgt_i = +1.0;
519  break;
520  case 2:
521  uh_i = -1.0;
522  wgt_i = -8.0;
523  break;
524  case 3:
525  uh_i = +1.0;
526  wgt_i = +8.0;
527  break;
528  case 4:
529  uh_i = +2.0;
530  wgt_i = -1.0;
531  break;
532  }
533  break;
534  }
535  }
536 
537  if(out.get()&&dump_all) {
538  *out<<"\nxo =\n" << xo;
539  *out<<"\nv =\n" << v;
540  if(fo) *out << "\nfo = " << *fo << "\n";
541  if(co) *out << "\nco =\n" << *co;
542  }
543  // Compute the weighted term and add it to the sum
544  bool new_point = true;
545  if(Gc_prod) {
546  if( co && uh_i == 0.0 ) {
547  if(out.get()&&trace) *out<<"\nBase c = co ...\n";
548  *c = *co;
549  }
550  else {
551  if( new_point || uh_c != uh ) {
552  *x = xo; Vp_StV( x.get(), uh_i * uh_c, v ); // x = xo + uh_i*uh_c*v
553  }
554  if(out.get()&&trace) *out<<"\nComputing c = c(xo+"<<(uh_i*uh_c)<<"*v) ...\n";
555  if(out.get()&&dump_all) *out<<"\nxo+"<<(uh_i*uh_c)<<"*v =\n" << *x;
556  nlp->calc_c(*x,new_point);
557  }
558  new_point = false;
559  if(out.get() && dump_all) *out << "\nc =\n" << *c;
560  if(check_nan_inf)
561  assert_print_nan_inf(*c,"c(xo+u*v)",true,out.get());
562  if(out.get()&&trace) *out<<"\nGc_prod += "<<wgt_i<<"*c ...\n";
563  Vp_StV( Gc_prod, wgt_i, *c );
564  if(out.get() && dump_all) *out<<"\nGc_prod =\n" << *Gc_prod;
565  }
566 
567  if(Gf_prod) {
568  if( fo && uh_i == 0.0 ) {
569  if(out.get()&&trace) *out<<"\nBase f = fo ...\n";
570  f = *fo;
571  }
572  else {
573  if( new_point || uh_f != uh ) {
574  *x = xo; Vp_StV( x.get(), uh_i * uh_f, v ); // x = xo + uh_i*uh_f*v
575  new_point = true;
576  }
577  if(out.get()&&trace) *out<<"\nComputing f = f(xo+"<<(uh_i*uh_f)<<"*v) ...\n";
578  if(out.get() && dump_all) *out<<"\nxo+"<<(uh_i*uh_f)<<"*v =\n" << *x;
579  nlp->calc_f(*x,new_point);
580  }
581  new_point = false;
582  if(out.get() && dump_all) *out<<"\nf = " << f << "\n";
583  if(check_nan_inf)
584  assert_print_nan_inf(f,"f(xo+u*v)",true,out.get());
585  if(out.get()&&trace) *out<<"\nGf_prod += "<<wgt_i<<"*f ...\n";
586  *Gf_prod += wgt_i * f;
587  if(out.get() && dump_all) *out<<"\nGf_prod = " << *Gf_prod << "\n";
588  }
589 
590  }
591 
592  //
593  // Multiply by the scaling factor!
594  //
595 
596  if(Gc_prod) {
597  if(out.get()&&trace) *out<<"\nGc_prod *= "<<(1.0 / (dwgt * uh_c))<<" ...\n";
598  Vt_S( Gc_prod, 1.0 / (dwgt * uh_c) );
599  if(out.get() && dump_all)
600  *out<<"\nFinal Gc_prod =\n" << *Gc_prod;
601  }
602 
603  if(Gf_prod) {
604  if(out.get()&&trace) *out<<"\nGf_prod *= "<<(1.0 / (dwgt * uh_f))<<" ...\n";
605  *Gf_prod *= ( 1.0 / (dwgt * uh_f) );
606  if(out.get() && dump_all)
607  *out<<"\nFinal Gf_prod = " << *Gf_prod << "\n";
608  }
609 
610  } // end try
611  catch(...) {
612  nlp->set_f( f_saved );
613  if(m) nlp->set_c( c_saved );
614  if(out.get())
615  *out << std::setprecision(p_saved);
616  throw;
617  }
618 
619  nlp->set_f( f_saved );
620  if(m) nlp->set_c( c_saved );
621  if(out.get())
622  *out << std::setprecision(p_saved);
623 
624  return true;
625 }
626 
627 } // end namespace NLPInterfacePack
Use FD_ORDER_FOUR_CENTRAL when not limited by bounds, otherwise use FD_ORDER_FOUR.
AbstractLinAlgPack::size_type size_type
virtual void calc_c(const Vector &x, bool newx=true) const
Update the constraint residual vector for c at the point x and put it in the stored reference...
void f()
std::string typeName(const T &t)
CalcFiniteDiffProd(EFDMethodOrder fd_method_order=FD_ORDER_FOUR_AUTO, EFDStepSelect fd_step_select=FD_STEP_ABSOLUTE, value_type fd_step_size=-1.0, value_type fd_step_size_min=-1.0, value_type fd_step_size_f=-1.0, value_type fd_step_size_c=-1.0)
void pow(DVectorSlice *vs_lhs, const DVectorSlice &vs_rhs1, const DVectorSlice &vs_rhs2)
vs_lhs = pow(vs_rhs1,vs_rhs2)
void Vt_S(VectorMutable *v_lhs, const value_type &alpha)
v_lhs *= alpha
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void Vp_StV(VectorMutable *v_lhs, const value_type &alpha, const Vector &v_rhs)
v_lhs = alpha * v_rhs + v_lhs
size_type rows(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
Return rows of a possible transposed matrix.
T * get() const
void V_StV(VectorMutable *v_lhs, value_type alpha, const V &V_rhs)
v_lhs = alpha * V_rhs.
AbstractLinAlgPack::VectorSpace * space_c
Use O(eps^2) one sided finite differences (cramped bounds)
AbstractLinAlgPack::VectorSpace * space_x
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual void calc_f(const Vector &x, bool newx=true) const
Update the value for the objective f at the point x and put it in the stored reference.
virtual size_type n() const
Return the number of variables.
std::ostream * out
virtual void set_c(VectorMutable *c)
Set a pointer to a vector to be updated when this->calc_c() is called.
virtual value_type * get_f()
Return pointer passed to this->set_f().
bool assert_print_nan_inf(const value_type &val, const char name[], bool throw_excpt, std::ostream *out)
This function asserts if a value_type scalare is a NaN or Inf and optionally prints out these entires...
NLP interface class {abstract}.
virtual value_type max_var_bounds_viol() const =0
Set the maximum absolute value for which the variable bounds may be violated by when computing functi...
std::pair< value_type, value_type > max_near_feas_step(const Vector &x, const Vector &d, const Vector &xl, const Vector &xu, value_type max_bnd_viol)
Computes the maximum positive and negative step that can be taken that are within the relaxed bounds...
virtual bool calc_deriv_product(const Vector &xo, const Vector *xl, const Vector *xu, const Vector &v, const value_type *fo, const Vector *co, bool check_nan_inf, NLP *nlp, value_type *Gf_prod, VectorMutable *Gc_prod, std::ostream *out, bool trace=false, bool dump_all=false) const
Compute the directional derivatives by finite differences.
AbstractLinAlgPack::value_type value_type
Use FD_ORDER_TWO_CENTRAL when not limited by bounds, otherwise use FD_ORDER_TWO.
Use O(eps^4) one sided finite differences (cramped bounds)
virtual vec_mut_ptr_t create_member() const =0
Create a vector member from the vector space.
virtual size_type m() const
Return the number of general equality constraints.
int n
virtual VectorMutable * get_c()
Return pointer passed to this->set_c().
size_type cols(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
Return columns of a possible transposed matrix.
Use O(eps) one sided finite differences (cramped bounds)
virtual void set_f(value_type *f)
Set a pointer to an value to be updated when this->calc_f() is called.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)