ROL
ROL_Types.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Rapid Optimization Library (ROL) Package
5 // Copyright (2014) 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 lead developers:
38 // Drew Kouri (dpkouri@sandia.gov) and
39 // Denis Ridzal (dridzal@sandia.gov)
40 //
41 // ************************************************************************
42 // @HEADER
43 
49 #ifndef ROL_TYPES_HPP
50 #define ROL_TYPES_HPP
51 
52 #ifdef HAVE_ROL_DEBUG
53 #define ROL_VALIDATE( A ) A
54 #else
55 #define ROL_VALIDATE( A ) /* empty */
56 #endif
57 
58 #include <algorithm>
59 #include <complex>
60 #include <string>
61 #include <sstream>
62 #include <limits>
63 #include <Teuchos_getConst.hpp>
64 #include <Teuchos_RCP.hpp>
65 #include <Teuchos_ScalarTraits.hpp>
66 #include <Teuchos_TestForException.hpp>
67 #include <ROL_Vector.hpp>
68 #include <ROL_config.h>
69 
73 #define ROL_NUM_CHECKDERIV_STEPS 13
74 
75 
76 
77 namespace ROL {
78 
79 template<class T>
80 std::string NumberToString( T Number )
81 {
82  std::ostringstream ss;
83  ss << Number;
84  return ss.str();
85 }
86 
87 
90  template<class Real>
91  struct AlgorithmState {
92  int iter;
93  int minIter;
94  int nfval;
95  int ncval;
96  int ngrad;
97  Real value;
98  Real minValue;
99  Real gnorm;
100  Real cnorm;
101  Real snorm;
104  bool flag;
105  Teuchos::RCP<Vector<Real> > iterateVec;
106  Teuchos::RCP<Vector<Real> > lagmultVec;
107  Teuchos::RCP<Vector<Real> > minIterVec;
108  AlgorithmState(void) : iter(0), minIter(0), nfval(0), ngrad(0), value(0), minValue(0),
109  gnorm(std::numeric_limits<Real>::max()),
110  cnorm(std::numeric_limits<Real>::max()),
111  snorm(std::numeric_limits<Real>::max()),
112  aggregateGradientNorm(std::numeric_limits<Real>::max()),
113  aggregateModelError(std::numeric_limits<Real>::max()),
114  flag(false),
115  iterateVec(Teuchos::null), lagmultVec(Teuchos::null), minIterVec(Teuchos::null) {}
116  };
117 
120  template<class Real>
121  struct StepState {
122  Teuchos::RCP<Vector<Real> > gradientVec;
123  Teuchos::RCP<Vector<Real> > descentVec;
124  Teuchos::RCP<Vector<Real> > constraintVec;
125  int nfval;
126  int ngrad;
127  Real searchSize; // line search parameter (alpha) or trust-region radius (delta)
128  StepState(void) : gradientVec(Teuchos::null),
129  descentVec(Teuchos::null),
130  constraintVec(Teuchos::null),
131  nfval(0),
132  ngrad(0),
133  searchSize(0) {}
134  };
135 
138  template<class Real>
139  inline Real ROL_EPSILON(void) { return std::abs(Teuchos::ScalarTraits<Real>::eps()); }
140  //static const Real ROL_EPSILON<Real>() = std::abs(Teuchos::ScalarTraits<Real>::eps());
141 
144  template<class Real>
145  inline Real ROL_THRESHOLD(void) { return 10.0 * ROL_EPSILON<Real>(); }
146  //static const Real ROL_THRESHOLD = 10.0 * ROL_EPSILON<Real>()<Real>;
147 
150  template<class Real>
151  inline Real ROL_OVERFLOW(void) { return std::abs(Teuchos::ScalarTraits<Real>::rmax()); }
152  //static const double ROL_OVERFLOW = std::abs(Teuchos::ScalarTraits<double>::rmax());
153 
154  template<class Real>
155  inline Real ROL_INF(void) { return 0.1*ROL_OVERFLOW<Real>(); }
156  //static const double ROL_INF<Real>() = 0.1*ROL_OVERFLOW;
157 
158  template<class Real>
159  inline Real ROL_NINF(void) { return -ROL_INF<Real>(); }
160  //static const double ROL_NINF<Real>() = -ROL_INF<Real>();
161 
164  template<class Real>
165  inline Real ROL_UNDERFLOW(void) { return std::abs(Teuchos::ScalarTraits<Real>::rmin()); }
166  //static const double ROL_UNDERFLOW = std::abs(Teuchos::ScalarTraits<double>::rmin());
167 
169  bool operator()(char c) {
170  return (c ==' ' || c =='-' || c == '(' || c == ')' || c=='\'' || c=='\r' || c=='\n' || c=='\t');
171  }
172  };
173 
174  inline std::string removeStringFormat( std::string s ) {
175  std::string output = s;
176  output.erase( std::remove_if( output.begin(), output.end(), removeSpecialCharacters()), output.end() );
177  std::transform( output.begin(), output.end(), output.begin(), ::tolower );
178  return output;
179  }
180 
192  enum EStep{
202  };
203 
204  inline std::string EStepToString(EStep tr) {
205  std::string retString;
206  switch(tr) {
207  case STEP_AUGMENTEDLAGRANGIAN: retString = "Augmented Lagrangian"; break;
208  case STEP_BUNDLE: retString = "Bundle"; break;
209  case STEP_COMPOSITESTEP: retString = "Composite Step"; break;
210  case STEP_LINESEARCH: retString = "Line Search"; break;
211  case STEP_MOREAUYOSIDAPENALTY: retString = "Moreau-Yosida Penalty"; break;
212  case STEP_PRIMALDUALACTIVESET: retString = "Primal Dual Active Set"; break;
213  case STEP_TRUSTREGION: retString = "Trust Region"; break;
214  case STEP_INTERIORPOINT: retString = "Interior Point"; break;
215  case STEP_LAST: retString = "Last Type (Dummy)"; break;
216  default: retString = "INVALID EStep";
217  }
218  return retString;
219  }
220 
226  inline int isValidStep(EStep ls) {
227  return( (ls == STEP_AUGMENTEDLAGRANGIAN) ||
228  (ls == STEP_BUNDLE) ||
229  (ls == STEP_COMPOSITESTEP) ||
230  (ls == STEP_LINESEARCH) ||
231  (ls == STEP_MOREAUYOSIDAPENALTY) ||
232  (ls == STEP_PRIMALDUALACTIVESET) ||
233  (ls == STEP_TRUSTREGION) ||
234  (ls == STEP_INTERIORPOINT) ) ;
235  }
236 
237  inline EStep & operator++(EStep &type) {
238  return type = static_cast<EStep>(type+1);
239  }
240 
241  inline EStep operator++(EStep &type, int) {
242  EStep oldval = type;
243  ++type;
244  return oldval;
245  }
246 
247  inline EStep & operator--(EStep &type) {
248  return type = static_cast<EStep>(type-1);
249  }
250 
251  inline EStep operator--(EStep &type, int) {
252  EStep oldval = type;
253  --type;
254  return oldval;
255  }
256 
257  inline EStep StringToEStep(std::string s) {
258  s = removeStringFormat(s);
259  for ( EStep tr = STEP_AUGMENTEDLAGRANGIAN; tr < STEP_LAST; tr++ ) {
260  if ( !s.compare(removeStringFormat(EStepToString(tr))) ) {
261  return tr;
262  }
263  }
264  return STEP_TRUSTREGION;
265  }
266 
279  };
280 
281  inline std::string EBoundAlgorithmToString(EBoundAlgorithm tr) {
282  std::string retString;
283  switch(tr) {
284  case BOUNDALGORITHM_PROJECTED: retString = "Projected"; break;
285  case BOUNDALGORITHM_PRIMALDUALACTIVESET: retString = "Primal Dual Active Set"; break;
286  case BOUNDALGORITHM_INTERIORPOINTS: retString = "Interior Points"; break;
287  case BOUNDALGORITHM_LAST: retString = "Last Type (Dummy)"; break;
288  default: retString = "INVALID EBoundAlgorithm";
289  }
290  return retString;
291  }
292 
299  return( (d == BOUNDALGORITHM_PROJECTED) ||
302  );
303  }
304 
306  return type = static_cast<EBoundAlgorithm>(type+1);
307  }
308 
310  EBoundAlgorithm oldval = type;
311  ++type;
312  return oldval;
313  }
314 
316  return type = static_cast<EBoundAlgorithm>(type-1);
317  }
318 
320  EBoundAlgorithm oldval = type;
321  --type;
322  return oldval;
323  }
324 
325  inline EBoundAlgorithm StringToEBoundAlgorithm(std::string s) {
326  s = removeStringFormat(s);
327  for ( EBoundAlgorithm des = BOUNDALGORITHM_PROJECTED; des < BOUNDALGORITHM_LAST; des++ ) {
328  if ( !s.compare(removeStringFormat(EBoundAlgorithmToString(des))) ) {
329  return des;
330  }
331  }
333  }
334 
345  enum EDescent{
352  };
353 
354  inline std::string EDescentToString(EDescent tr) {
355  std::string retString;
356  switch(tr) {
357  case DESCENT_STEEPEST: retString = "Steepest Descent"; break;
358  case DESCENT_NONLINEARCG: retString = "Nonlinear CG"; break;
359  case DESCENT_SECANT: retString = "Quasi-Newton Method"; break;
360  case DESCENT_NEWTON: retString = "Newton's Method"; break;
361  case DESCENT_NEWTONKRYLOV: retString = "Newton-Krylov"; break;
362  case DESCENT_LAST: retString = "Last Type (Dummy)"; break;
363  default: retString = "INVALID ESecant";
364  }
365  return retString;
366  }
367 
373  inline int isValidDescent(EDescent d){
374  return( (d == DESCENT_STEEPEST) ||
375  (d == DESCENT_NONLINEARCG) ||
376  (d == DESCENT_SECANT) ||
377  (d == DESCENT_NEWTON) ||
378  (d == DESCENT_NEWTONKRYLOV)
379  );
380  }
381 
382  inline EDescent & operator++(EDescent &type) {
383  return type = static_cast<EDescent>(type+1);
384  }
385 
386  inline EDescent operator++(EDescent &type, int) {
387  EDescent oldval = type;
388  ++type;
389  return oldval;
390  }
391 
392  inline EDescent & operator--(EDescent &type) {
393  return type = static_cast<EDescent>(type-1);
394  }
395 
396  inline EDescent operator--(EDescent &type, int) {
397  EDescent oldval = type;
398  --type;
399  return oldval;
400  }
401 
402  inline EDescent StringToEDescent(std::string s) {
403  s = removeStringFormat(s);
404  for ( EDescent des = DESCENT_STEEPEST; des < DESCENT_LAST; des++ ) {
405  if ( !s.compare(removeStringFormat(EDescentToString(des))) ) {
406  return des;
407  }
408  }
409  return DESCENT_SECANT;
410  }
411 
420  enum ESecant{
427  };
428 
429  inline std::string ESecantToString(ESecant tr) {
430  std::string retString;
431  switch(tr) {
432  case SECANT_LBFGS: retString = "Limited-Memory BFGS"; break;
433  case SECANT_LDFP: retString = "Limited-Memory DFP"; break;
434  case SECANT_LSR1: retString = "Limited-Memory SR1"; break;
435  case SECANT_BARZILAIBORWEIN: retString = "Barzilai-Borwein"; break;
436  case SECANT_USERDEFINED: retString = "User-Defined"; break;
437  case SECANT_LAST: retString = "Last Type (Dummy)"; break;
438  default: retString = "INVALID ESecant";
439  }
440  return retString;
441  }
442 
448  inline int isValidSecant(ESecant s) {
449  return( (s == SECANT_LBFGS) ||
450  (s == SECANT_LDFP) ||
451  (s == SECANT_LSR1) ||
452  (s == SECANT_BARZILAIBORWEIN) ||
453  (s == SECANT_USERDEFINED)
454  );
455  }
456 
457  inline ESecant & operator++(ESecant &type) {
458  return type = static_cast<ESecant>(type+1);
459  }
460 
461  inline ESecant operator++(ESecant &type, int) {
462  ESecant oldval = type;
463  ++type;
464  return oldval;
465  }
466 
467  inline ESecant & operator--(ESecant &type) {
468  return type = static_cast<ESecant>(type-1);
469  }
470 
471  inline ESecant operator--(ESecant &type, int) {
472  ESecant oldval = type;
473  --type;
474  return oldval;
475  }
476 
477  inline ESecant StringToESecant(std::string s) {
478  s = removeStringFormat(s);
479  for ( ESecant sec = SECANT_LBFGS; sec < SECANT_LAST; sec++ ) {
480  if ( !s.compare(removeStringFormat(ESecantToString(sec))) ) {
481  return sec;
482  }
483  }
484  return SECANT_LBFGS;
485  }
486 
493  enum EKrylov{
499  };
500 
501  inline std::string EKrylovToString(EKrylov tr) {
502  std::string retString;
503  switch(tr) {
504  case KRYLOV_CG: retString = "Conjugate Gradients"; break;
505  case KRYLOV_CR: retString = "Conjugate Residuals"; break;
506  case KRYLOV_GMRES: retString = "GMRES"; break;
507  case KRYLOV_USERDEFINED: retString = "User Defined"; break;
508  case KRYLOV_LAST: retString = "Last Type (Dummy)"; break;
509  default: retString = "INVALID EKrylov";
510  }
511  return retString;
512  }
513 
519  inline int isValidKrylov(EKrylov d){
520  return( (d == KRYLOV_CG) ||
521  (d == KRYLOV_CR) ||
522  (d == KRYLOV_GMRES) ||
523  (d == KRYLOV_USERDEFINED) );
524  }
525 
526  inline EKrylov & operator++(EKrylov &type) {
527  return type = static_cast<EKrylov>(type+1);
528  }
529 
530  inline EKrylov operator++(EKrylov &type, int) {
531  EKrylov oldval = type;
532  ++type;
533  return oldval;
534  }
535 
536  inline EKrylov & operator--(EKrylov &type) {
537  return type = static_cast<EKrylov>(type-1);
538  }
539 
540  inline EKrylov operator--(EKrylov &type, int) {
541  EKrylov oldval = type;
542  --type;
543  return oldval;
544  }
545 
546  inline EKrylov StringToEKrylov(std::string s) {
547  s = removeStringFormat(s);
548  for ( EKrylov des = KRYLOV_CG; des < KRYLOV_LAST; des++ ) {
549  if ( !s.compare(removeStringFormat(EKrylovToString(des))) ) {
550  return des;
551  }
552  }
553  return KRYLOV_CG;
554  }
555 
581  };
582 
583  inline std::string ENonlinearCGToString(ENonlinearCG tr) {
584  std::string retString;
585  switch(tr) {
586  case NONLINEARCG_HESTENES_STIEFEL: retString = "Hestenes-Stiefel"; break;
587  case NONLINEARCG_FLETCHER_REEVES: retString = "Fletcher-Reeves"; break;
588  case NONLINEARCG_DANIEL: retString = "Daniel (uses Hessian)"; break;
589  case NONLINEARCG_POLAK_RIBIERE: retString = "Polak-Ribiere"; break;
590  case NONLINEARCG_FLETCHER_CONJDESC: retString = "Fletcher Conjugate Descent"; break;
591  case NONLINEARCG_LIU_STOREY: retString = "Liu-Storey"; break;
592  case NONLINEARCG_DAI_YUAN: retString = "Dai-Yuan"; break;
593  case NONLINEARCG_HAGER_ZHANG: retString = "Hager-Zhang"; break;
594  case NONLINEARCG_OREN_LUENBERGER: retString = "Oren-Luenberger"; break;
595  case NONLINEARCG_USERDEFINED: retString = "User Defined"; break;
596  case NONLINEARCG_LAST: retString = "Last Type (Dummy)"; break;
597  default: retString = "INVALID ENonlinearCG";
598  }
599  return retString;
600  }
601 
608  return( (s == NONLINEARCG_HESTENES_STIEFEL) ||
610  (s == NONLINEARCG_DANIEL) ||
611  (s == NONLINEARCG_POLAK_RIBIERE) ||
613  (s == NONLINEARCG_LIU_STOREY) ||
614  (s == NONLINEARCG_DAI_YUAN) ||
615  (s == NONLINEARCG_HAGER_ZHANG) ||
618  );
619  }
620 
622  return type = static_cast<ENonlinearCG>(type+1);
623  }
624 
625  inline ENonlinearCG operator++(ENonlinearCG &type, int) {
626  ENonlinearCG oldval = type;
627  ++type;
628  return oldval;
629  }
630 
632  return type = static_cast<ENonlinearCG>(type-1);
633  }
634 
635  inline ENonlinearCG operator--(ENonlinearCG &type, int) {
636  ENonlinearCG oldval = type;
637  --type;
638  return oldval;
639  }
640 
641  inline ENonlinearCG StringToENonlinearCG(std::string s) {
642  s = removeStringFormat(s);
643  for ( ENonlinearCG nlcg = NONLINEARCG_HESTENES_STIEFEL; nlcg < NONLINEARCG_LAST; nlcg++ ) {
644  if ( !s.compare(removeStringFormat(ENonlinearCGToString(nlcg))) ) {
645  return nlcg;
646  }
647  }
649  }
650 
671  };
672 
673  inline std::string ELineSearchToString(ELineSearch ls) {
674  std::string retString;
675  switch(ls) {
676  case LINESEARCH_ITERATIONSCALING: retString = "Iteration Scaling"; break;
677  case LINESEARCH_PATHBASEDTARGETLEVEL: retString = "Path-Based Target Level"; break;
678  case LINESEARCH_BACKTRACKING: retString = "Backtracking"; break;
679  case LINESEARCH_BISECTION: retString = "Bisection"; break;
680  case LINESEARCH_GOLDENSECTION: retString = "Golden Section"; break;
681  case LINESEARCH_CUBICINTERP: retString = "Cubic Interpolation"; break;
682  case LINESEARCH_BRENTS: retString = "Brent's"; break;
683  case LINESEARCH_USERDEFINED: retString = "User Defined"; break;
684  case LINESEARCH_LAST: retString = "Last Type (Dummy)"; break;
685  default: retString = "INVALID ELineSearch";
686  }
687  return retString;
688  }
689 
696  return( (ls == LINESEARCH_BACKTRACKING) ||
697  (ls == LINESEARCH_ITERATIONSCALING) ||
699  (ls == LINESEARCH_BISECTION) ||
700  (ls == LINESEARCH_GOLDENSECTION) ||
701  (ls == LINESEARCH_CUBICINTERP) ||
702  (ls == LINESEARCH_BRENTS) ||
703  (ls == LINESEARCH_USERDEFINED)
704  );
705  }
706 
708  return type = static_cast<ELineSearch>(type+1);
709  }
710 
711  inline ELineSearch operator++(ELineSearch &type, int) {
712  ELineSearch oldval = type;
713  ++type;
714  return oldval;
715  }
716 
718  return type = static_cast<ELineSearch>(type-1);
719  }
720 
721  inline ELineSearch operator--(ELineSearch &type, int) {
722  ELineSearch oldval = type;
723  --type;
724  return oldval;
725  }
726 
727  inline ELineSearch StringToELineSearch(std::string s) {
728  s = removeStringFormat(s);
729  for ( ELineSearch ls = LINESEARCH_ITERATIONSCALING; ls < LINESEARCH_LAST; ls++ ) {
730  if ( !s.compare(removeStringFormat(ELineSearchToString(ls))) ) {
731  return ls;
732  }
733  }
735  }
736 
752  };
753 
755  std::string retString;
756  switch(ls) {
757  case CURVATURECONDITION_WOLFE: retString = "Wolfe Conditions"; break;
758  case CURVATURECONDITION_STRONGWOLFE: retString = "Strong Wolfe Conditions"; break;
759  case CURVATURECONDITION_GENERALIZEDWOLFE: retString = "Generalized Wolfe Conditions"; break;
760  case CURVATURECONDITION_APPROXIMATEWOLFE: retString = "Approximate Wolfe Conditions"; break;
761  case CURVATURECONDITION_GOLDSTEIN: retString = "Goldstein Conditions"; break;
762  case CURVATURECONDITION_NULL: retString = "Null Curvature Condition"; break;
763  case CURVATURECONDITION_LAST: retString = "Last Type (Dummy)"; break;
764  default: retString = "INVALID ECurvatureCondition";
765  }
766  return retString;
767  }
768 
775  return( (ls == CURVATURECONDITION_WOLFE) ||
781  );
782  }
783 
785  return type = static_cast<ECurvatureCondition>(type+1);
786  }
787 
789  ECurvatureCondition oldval = type;
790  ++type;
791  return oldval;
792  }
793 
795  return type = static_cast<ECurvatureCondition>(type-1);
796  }
797 
799  ECurvatureCondition oldval = type;
800  --type;
801  return oldval;
802  }
803 
805  s = removeStringFormat(s);
807  if ( !s.compare(removeStringFormat(ECurvatureConditionToString(cc))) ) {
808  return cc;
809  }
810  }
812  }
813 
823  enum ECGFlag {
829  };
830 
831 
832  inline std::string ECGFlagToString(ECGFlag cgf) {
833  std::string retString;
834  switch(cgf) {
835  case CG_FLAG_SUCCESS:
836  retString = "Residual tolerance met";
837  break;
838  case CG_FLAG_ITEREXCEED:
839  retString = "Iteration limit exceeded";
840  break;
841  case CG_FLAG_NEGCURVE:
842  retString = "Negative curvature detected";
843  break;
844  case CG_FLAG_TRRADEX:
845  retString = "Trust-Region radius exceeded";
846  break;
847  default:
848  retString = "INVALID ECGFlag";
849  }
850  return retString;
851  }
852 
853 
874  };
875 
876  inline std::string ETestObjectivesToString(ETestObjectives to) {
877  std::string retString;
878  switch(to) {
879  case TESTOBJECTIVES_ROSENBROCK: retString = "Rosenbrock's Function"; break;
880  case TESTOBJECTIVES_FREUDENSTEINANDROTH: retString = "Freudenstein and Roth's Function"; break;
881  case TESTOBJECTIVES_BEALE: retString = "Beale's Function"; break;
882  case TESTOBJECTIVES_POWELL: retString = "Powell's Badly Scaled Function"; break;
883  case TESTOBJECTIVES_SUMOFSQUARES: retString = "Sum of Squares Function"; break;
884  case TESTOBJECTIVES_LEASTSQUARES: retString = "Least Squares Function"; break;
885  case TESTOBJECTIVES_POISSONCONTROL: retString = "Poisson Optimal Control"; break;
886  case TESTOBJECTIVES_POISSONINVERSION: retString = "Poisson Inversion Problem"; break;
887  case TESTOBJECTIVES_ZAKHAROV: retString = "Zakharov's Function"; break;
888  case TESTOBJECTIVES_LAST: retString = "Last Type (Dummy)"; break;
889  default: retString = "INVALID ETestObjectives";
890  }
891  return retString;
892  }
893 
900  return( (to == TESTOBJECTIVES_ROSENBROCK) ||
902  (to == TESTOBJECTIVES_BEALE) ||
903  (to == TESTOBJECTIVES_POWELL) ||
904  (to == TESTOBJECTIVES_SUMOFSQUARES) ||
905  (to == TESTOBJECTIVES_LEASTSQUARES) ||
909  );
910  }
911 
913  return type = static_cast<ETestObjectives>(type+1);
914  }
915 
917  ETestObjectives oldval = type;
918  ++type;
919  return oldval;
920  }
921 
923  return type = static_cast<ETestObjectives>(type-1);
924  }
925 
927  ETestObjectives oldval = type;
928  --type;
929  return oldval;
930  }
931 
932  inline ETestObjectives StringToETestObjectives(std::string s) {
933  s = removeStringFormat(s);
935  if ( !s.compare(removeStringFormat(ETestObjectivesToString(to))) ) {
936  return to;
937  }
938  }
940  }
941 
963  };
964 
965  inline std::string ETestOptProblemToString(ETestOptProblem to) {
966  std::string retString;
967  switch(to) {
968  case TESTOPTPROBLEM_HS1: retString = "Hock and Schittkowski Test Problem #1"; break;
969  case TESTOPTPROBLEM_HS2: retString = "Hock and Schittkowski Test Problem #2"; break;
970  case TESTOPTPROBLEM_HS3: retString = "Hock and Schittkowski Test Problem #3"; break;
971  case TESTOPTPROBLEM_HS4: retString = "Hock and Schittkowski Test Problem #4"; break;
972  case TESTOPTPROBLEM_HS5: retString = "Hock and Schittkowski Test Problem #5"; break;
973  case TESTOPTPROBLEM_HS25: retString = "Hock and Schittkowski Test Problem #25"; break;
974  case TESTOPTPROBLEM_HS38: retString = "Hock and Schittkowski Test Problem #38"; break;
975  case TESTOPTPROBLEM_HS45: retString = "Hock and Schittkowski Test Problem #45"; break;
976  case TESTOPTPROBLEM_BVP: retString = "Boundary Value Problem"; break;
977  case TESTOPTPROBLEM_LAST: retString = "Last Type (Dummy)"; break;
978  default: retString = "INVALID ETestOptProblem";
979  }
980  return retString;
981  }
982 
989  return( (to == TESTOPTPROBLEM_HS1) ||
990  (to == TESTOPTPROBLEM_HS2) ||
991  (to == TESTOPTPROBLEM_HS3) ||
992  (to == TESTOPTPROBLEM_HS4) ||
993  (to == TESTOPTPROBLEM_HS5) ||
994  (to == TESTOPTPROBLEM_HS25) ||
995  (to == TESTOPTPROBLEM_HS38) ||
996  (to == TESTOPTPROBLEM_HS45) ||
997  (to == TESTOPTPROBLEM_BVP) );
998  }
999 
1001  return type = static_cast<ETestOptProblem>(type+1);
1002  }
1003 
1005  ETestOptProblem oldval = type;
1006  ++type;
1007  return oldval;
1008  }
1009 
1011  return type = static_cast<ETestOptProblem>(type-1);
1012  }
1013 
1015  ETestOptProblem oldval = type;
1016  --type;
1017  return oldval;
1018  }
1019 
1021  s = removeStringFormat(s);
1022  for ( ETestOptProblem to = TESTOPTPROBLEM_HS1; to < TESTOPTPROBLEM_LAST; to++ ) {
1023  if ( !s.compare(removeStringFormat(ETestOptProblemToString(to))) ) {
1024  return to;
1025  }
1026  }
1027  return TESTOPTPROBLEM_HS1;
1028  }
1029 
1030 
1041  };
1042 
1043  inline std::string EConstraintToString(EConstraint c) {
1044  std::string retString;
1045  switch(c) {
1046  case CONSTRAINT_EQUALITY: retString = "Equality"; break;
1047  case CONSTRAINT_INEQUALITY: retString = "Inequality"; break;
1048  case CONSTRAINT_LAST: retString = "Last Type (Dummy)"; break;
1049  default: retString = "INVALID EConstraint";
1050  }
1051  return retString;
1052  }
1053 
1060  return( (c == CONSTRAINT_EQUALITY) ||
1061  (c == CONSTRAINT_INEQUALITY) );
1062  }
1063 
1065  return type = static_cast<EConstraint>(type+1);
1066  }
1067 
1068  inline EConstraint operator++(EConstraint &type, int) {
1069  EConstraint oldval = type;
1070  ++type;
1071  return oldval;
1072  }
1073 
1075  return type = static_cast<EConstraint>(type-1);
1076  }
1077 
1078  inline EConstraint operator--(EConstraint &type, int) {
1079  EConstraint oldval = type;
1080  --type;
1081  return oldval;
1082  }
1083 
1084  inline EConstraint StringToEConstraint(std::string s) {
1085  s = removeStringFormat(s);
1086  for ( EConstraint ctype = CONSTRAINT_EQUALITY; ctype < CONSTRAINT_LAST; ctype++ ) {
1087  if ( !s.compare(removeStringFormat(EConstraintToString(ctype))) ) {
1088  return ctype;
1089  }
1090  }
1091  return CONSTRAINT_EQUALITY;
1092  }
1093 
1094  // For use in gradient and Hessian checks
1095  namespace Finite_Difference_Arrays {
1096 
1097  // Finite difference steps in axpy form
1098  const int shifts[4][4] = { { 1, 0, 0, 0 }, // First order
1099  { -1, 2, 0, 0 }, // Second order
1100  { -1, 2, 1, 0 }, // Third order
1101  { -1, -1, 3, 1 } // Fourth order
1102  };
1103 
1104  // Finite difference weights
1105  const double weights[4][5] = { { -1.0, 1.0, 0.0, 0.0, 0.0 }, // First order
1106  { 0.0, -1.0/2.0, 1.0/2.0, 0.0, 0.0 }, // Second order
1107  { -1.0/2.0, -1.0/3.0, 1.0, -1.0/6.0, 0.0 }, // Third order
1108  { 0.0, -2.0/3.0, 1.0/12.0, 2.0/3.0, -1.0/12.0 } // Fourth order
1109  };
1110 
1111  }
1112 
1113 
1114 // Generic conversion from Element type to Real type
1115 template<class Real, class Element>
1116 struct TypeCaster {
1117  static Real ElementToReal( const Element &val ) {
1118  return Real(0);
1119  }
1120 };
1121 
1122 // Partially specialize for complex<Real>
1123 template<class Real>
1124 struct TypeCaster<Real, std::complex<Real> > {
1125  static Real ElementToReal( const std::complex<Real> &val ) {
1126  return val.real();
1127  }
1128 };
1129 
1130 // Fully specialize for double,float
1131 template<>
1132 struct TypeCaster<double,float> {
1133  static double ElementToReal( const float &val ) {
1134  return static_cast<double>(val);
1135  }
1136 };
1137 
1138 // Cast from Element type to Real type
1139 template<class Element, class Real>
1140 Real rol_cast(const Element &val) {
1142 }
1143 
1144 
1145 
1146 
1147 
1148 
1149 namespace Exception {
1150 
1151 class NotImplemented : public Teuchos::ExceptionBase {
1152 public:
1153  NotImplemented( const std::string& what_arg ) :
1154  Teuchos::ExceptionBase(what_arg) {}
1155 
1156 
1157 }; // class NotImplemented
1158 
1159 
1160 } // namespace Exception
1161 
1162 
1163 } // namespace ROL
1164 
1165 
1379 #endif
std::string ECGFlagToString(ECGFlag cgf)
Definition: ROL_Types.hpp:832
ETestOptProblem
Enumeration of test optimization problems.
Definition: ROL_Types.hpp:952
int isValidKrylov(EKrylov d)
Verifies validity of a Secant enum.
Definition: ROL_Types.hpp:519
EStep StringToEStep(std::string s)
Definition: ROL_Types.hpp:257
static Real ElementToReal(const Element &val)
Definition: ROL_Types.hpp:1117
int isValidConstraint(EConstraint c)
Verifies validity of a Secant enum.
Definition: ROL_Types.hpp:1059
int isValidSecant(ESecant s)
Verifies validity of a Secant enum.
Definition: ROL_Types.hpp:448
Real ROL_THRESHOLD(void)
Tolerance for various equality tests.
Definition: ROL_Types.hpp:145
const double weights[4][5]
Definition: ROL_Types.hpp:1105
ELineSearch StringToELineSearch(std::string s)
Definition: ROL_Types.hpp:727
EBoundAlgorithm StringToEBoundAlgorithm(std::string s)
Definition: ROL_Types.hpp:325
EBoundAlgorithm
Enumeration of algorithms to handle bound constraints.
Definition: ROL_Types.hpp:274
Real ROL_INF(void)
Definition: ROL_Types.hpp:155
int isValidBoundAlgorithm(EBoundAlgorithm d)
Verifies validity of a Bound Algorithm enum.
Definition: ROL_Types.hpp:298
NotImplemented(const std::string &what_arg)
Definition: ROL_Types.hpp:1153
std::string removeStringFormat(std::string s)
Definition: ROL_Types.hpp:174
ELineSearch
Enumeration of line-search types.
Definition: ROL_Types.hpp:661
EConstraint StringToEConstraint(std::string s)
Definition: ROL_Types.hpp:1084
ESecant StringToESecant(std::string s)
Definition: ROL_Types.hpp:477
std::string EDescentToString(EDescent tr)
Definition: ROL_Types.hpp:354
int isValidTestOptProblem(ETestOptProblem to)
Verifies validity of a TestOptProblem enum.
Definition: ROL_Types.hpp:988
static Real ElementToReal(const std::complex< Real > &val)
Definition: ROL_Types.hpp:1125
ECGFlag
Enumation of flags used by conjugate gradient methods.
Definition: ROL_Types.hpp:823
Teuchos::RCP< Vector< Real > > descentVec
Definition: ROL_Types.hpp:123
EKrylov
Enumeration of Krylov methods.
Definition: ROL_Types.hpp:493
int isValidTestObjectives(ETestObjectives to)
Verifies validity of a TestObjectives enum.
Definition: ROL_Types.hpp:899
EKrylov StringToEKrylov(std::string s)
Definition: ROL_Types.hpp:546
EDescent StringToEDescent(std::string s)
Definition: ROL_Types.hpp:402
State for algorithm class. Will be used for restarts.
Definition: ROL_Types.hpp:91
std::string NumberToString(T Number)
Definition: ROL_Types.hpp:80
ENonlinearCG
Enumeration of nonlinear CG algorithms.
Definition: ROL_Types.hpp:569
ETestObjectives StringToETestObjectives(std::string s)
Definition: ROL_Types.hpp:932
std::string ECurvatureConditionToString(ECurvatureCondition ls)
Definition: ROL_Types.hpp:754
Real rol_cast(const Element &val)
Definition: ROL_Types.hpp:1140
std::string EConstraintToString(EConstraint c)
Definition: ROL_Types.hpp:1043
ESecant
Enumeration of secant update algorithms.
Definition: ROL_Types.hpp:420
std::string ETestOptProblemToString(ETestOptProblem to)
Definition: ROL_Types.hpp:965
std::string ENonlinearCGToString(ENonlinearCG tr)
Definition: ROL_Types.hpp:583
ENonlinearCG StringToENonlinearCG(std::string s)
Definition: ROL_Types.hpp:641
int isValidDescent(EDescent d)
Verifies validity of a Secant enum.
Definition: ROL_Types.hpp:373
std::string ELineSearchToString(ELineSearch ls)
Definition: ROL_Types.hpp:673
ETrustRegion & operator--(ETrustRegion &type)
Real ROL_OVERFLOW(void)
Platform-dependent maximum double.
Definition: ROL_Types.hpp:151
int isValidLineSearch(ELineSearch ls)
Verifies validity of a LineSearch enum.
Definition: ROL_Types.hpp:695
State for step class. Will be used for restarts.
Definition: ROL_Types.hpp:121
int isValidStep(EStep ls)
Verifies validity of a TrustRegion enum.
Definition: ROL_Types.hpp:226
ETestObjectives
Enumeration of test objective functions.
Definition: ROL_Types.hpp:863
Teuchos::RCP< Vector< Real > > minIterVec
Definition: ROL_Types.hpp:107
std::string EKrylovToString(EKrylov tr)
Definition: ROL_Types.hpp:501
static double ElementToReal(const float &val)
Definition: ROL_Types.hpp:1133
Teuchos::RCP< Vector< Real > > constraintVec
Definition: ROL_Types.hpp:124
int isValidCurvatureCondition(ECurvatureCondition ls)
Verifies validity of a CurvatureCondition enum.
Definition: ROL_Types.hpp:774
ECurvatureCondition
Enumeration of line-search curvature conditions.
Definition: ROL_Types.hpp:744
std::string ETestObjectivesToString(ETestObjectives to)
Definition: ROL_Types.hpp:876
Teuchos::RCP< Vector< Real > > lagmultVec
Definition: ROL_Types.hpp:106
Teuchos::RCP< Vector< Real > > iterateVec
Definition: ROL_Types.hpp:105
ECurvatureCondition StringToECurvatureCondition(std::string s)
Definition: ROL_Types.hpp:804
Real ROL_EPSILON(void)
Platform-dependent machine epsilon.
Definition: ROL_Types.hpp:139
ETrustRegion & operator++(ETrustRegion &type)
std::string ESecantToString(ESecant tr)
Definition: ROL_Types.hpp:429
std::string EStepToString(EStep tr)
Definition: ROL_Types.hpp:204
EStep
Enumeration of step types.
Definition: ROL_Types.hpp:192
EConstraint
Enumeration of constraint types.
Definition: ROL_Types.hpp:1037
ETestOptProblem StringToETestOptProblem(std::string s)
Definition: ROL_Types.hpp:1020
Real ROL_UNDERFLOW(void)
Platform-dependent minimum double.
Definition: ROL_Types.hpp:165
int isValidNonlinearCG(ENonlinearCG s)
Verifies validity of a NonlinearCG enum.
Definition: ROL_Types.hpp:607
std::string EBoundAlgorithmToString(EBoundAlgorithm tr)
Definition: ROL_Types.hpp:281
EDescent
Enumeration of descent direction types.
Definition: ROL_Types.hpp:345
Real ROL_NINF(void)
Definition: ROL_Types.hpp:159
Teuchos::RCP< Vector< Real > > gradientVec
Definition: ROL_Types.hpp:122