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 
181  // Types of optimization problem
182  enum EProblem {
183  TYPE_U = 0,
188  };
189 
201  enum EStep{
211  };
212 
213  inline std::string EStepToString(EStep tr) {
214  std::string retString;
215  switch(tr) {
216  case STEP_AUGMENTEDLAGRANGIAN: retString = "Augmented Lagrangian"; break;
217  case STEP_BUNDLE: retString = "Bundle"; break;
218  case STEP_COMPOSITESTEP: retString = "Composite Step"; break;
219  case STEP_LINESEARCH: retString = "Line Search"; break;
220  case STEP_MOREAUYOSIDAPENALTY: retString = "Moreau-Yosida Penalty"; break;
221  case STEP_PRIMALDUALACTIVESET: retString = "Primal Dual Active Set"; break;
222  case STEP_TRUSTREGION: retString = "Trust Region"; break;
223  case STEP_INTERIORPOINT: retString = "Interior Point"; break;
224  case STEP_LAST: retString = "Last Type (Dummy)"; break;
225  default: retString = "INVALID EStep";
226  }
227  return retString;
228  }
229 
230  inline int isCompatibleStep( EProblem p, EStep s ) {
231  int comp;
232  switch(p) {
233 
234  case TYPE_U: comp = ( (s == STEP_LINESEARCH) ||
235  (s == STEP_TRUSTREGION) );
236  break;
237 
238  case TYPE_B: comp = ( (s == STEP_LINESEARCH) ||
239  (s == STEP_TRUSTREGION) ||
240  (s == STEP_MOREAUYOSIDAPENALTY) );
241  break;
242 
243  case TYPE_E: comp = ( (s == STEP_COMPOSITESTEP) ||
244  (s == STEP_AUGMENTEDLAGRANGIAN) );
245  break;
246 
247  case TYPE_EB: comp = ( (s == STEP_AUGMENTEDLAGRANGIAN) ||
248  (s == STEP_MOREAUYOSIDAPENALTY) );
249  break;
250 
251  case TYPE_LAST: comp = 0; break;
252  default: comp = 0;
253  }
254  return comp;
255  }
256 
257  inline std::string EProblemToString( EProblem p ) {
258  std::string retString;
259  switch(p) {
260  case TYPE_U: retString = "Type-U"; break;
261  case TYPE_E: retString = "Type-E"; break;
262  case TYPE_B: retString = "Type-B"; break;
263  case TYPE_EB: retString = "Type-EB"; break;
264  case TYPE_LAST: retString = "Type-Last (Dummy)"; break;
265  default: retString = "Invalid EProblem";
266  }
267  return retString;
268  }
269 
270 
276  inline int isValidStep(EStep ls) {
277  return( (ls == STEP_AUGMENTEDLAGRANGIAN) ||
278  (ls == STEP_BUNDLE) ||
279  (ls == STEP_COMPOSITESTEP) ||
280  (ls == STEP_LINESEARCH) ||
281  (ls == STEP_MOREAUYOSIDAPENALTY) ||
282  (ls == STEP_PRIMALDUALACTIVESET) ||
283  (ls == STEP_TRUSTREGION) ||
284  (ls == STEP_INTERIORPOINT) ) ;
285  }
286 
287  inline EStep & operator++(EStep &type) {
288  return type = static_cast<EStep>(type+1);
289  }
290 
291  inline EStep operator++(EStep &type, int) {
292  EStep oldval = type;
293  ++type;
294  return oldval;
295  }
296 
297  inline EStep & operator--(EStep &type) {
298  return type = static_cast<EStep>(type-1);
299  }
300 
301  inline EStep operator--(EStep &type, int) {
302  EStep oldval = type;
303  --type;
304  return oldval;
305  }
306 
307  inline EStep StringToEStep(std::string s) {
308  s = removeStringFormat(s);
309  for ( EStep tr = STEP_AUGMENTEDLAGRANGIAN; tr < STEP_LAST; tr++ ) {
310  if ( !s.compare(removeStringFormat(EStepToString(tr))) ) {
311  return tr;
312  }
313  }
314  return STEP_TRUSTREGION;
315  }
316 
329  };
330 
331  inline std::string EBoundAlgorithmToString(EBoundAlgorithm tr) {
332  std::string retString;
333  switch(tr) {
334  case BOUNDALGORITHM_PROJECTED: retString = "Projected"; break;
335  case BOUNDALGORITHM_PRIMALDUALACTIVESET: retString = "Primal Dual Active Set"; break;
336  case BOUNDALGORITHM_INTERIORPOINTS: retString = "Interior Points"; break;
337  case BOUNDALGORITHM_LAST: retString = "Last Type (Dummy)"; break;
338  default: retString = "INVALID EBoundAlgorithm";
339  }
340  return retString;
341  }
342 
349  return( (d == BOUNDALGORITHM_PROJECTED) ||
352  );
353  }
354 
356  return type = static_cast<EBoundAlgorithm>(type+1);
357  }
358 
360  EBoundAlgorithm oldval = type;
361  ++type;
362  return oldval;
363  }
364 
366  return type = static_cast<EBoundAlgorithm>(type-1);
367  }
368 
370  EBoundAlgorithm oldval = type;
371  --type;
372  return oldval;
373  }
374 
375  inline EBoundAlgorithm StringToEBoundAlgorithm(std::string s) {
376  s = removeStringFormat(s);
377  for ( EBoundAlgorithm des = BOUNDALGORITHM_PROJECTED; des < BOUNDALGORITHM_LAST; des++ ) {
378  if ( !s.compare(removeStringFormat(EBoundAlgorithmToString(des))) ) {
379  return des;
380  }
381  }
383  }
384 
395  enum EDescent{
402  };
403 
404  inline std::string EDescentToString(EDescent tr) {
405  std::string retString;
406  switch(tr) {
407  case DESCENT_STEEPEST: retString = "Steepest Descent"; break;
408  case DESCENT_NONLINEARCG: retString = "Nonlinear CG"; break;
409  case DESCENT_SECANT: retString = "Quasi-Newton Method"; break;
410  case DESCENT_NEWTON: retString = "Newton's Method"; break;
411  case DESCENT_NEWTONKRYLOV: retString = "Newton-Krylov"; break;
412  case DESCENT_LAST: retString = "Last Type (Dummy)"; break;
413  default: retString = "INVALID ESecant";
414  }
415  return retString;
416  }
417 
423  inline int isValidDescent(EDescent d){
424  return( (d == DESCENT_STEEPEST) ||
425  (d == DESCENT_NONLINEARCG) ||
426  (d == DESCENT_SECANT) ||
427  (d == DESCENT_NEWTON) ||
428  (d == DESCENT_NEWTONKRYLOV)
429  );
430  }
431 
432  inline EDescent & operator++(EDescent &type) {
433  return type = static_cast<EDescent>(type+1);
434  }
435 
436  inline EDescent operator++(EDescent &type, int) {
437  EDescent oldval = type;
438  ++type;
439  return oldval;
440  }
441 
442  inline EDescent & operator--(EDescent &type) {
443  return type = static_cast<EDescent>(type-1);
444  }
445 
446  inline EDescent operator--(EDescent &type, int) {
447  EDescent oldval = type;
448  --type;
449  return oldval;
450  }
451 
452  inline EDescent StringToEDescent(std::string s) {
453  s = removeStringFormat(s);
454  for ( EDescent des = DESCENT_STEEPEST; des < DESCENT_LAST; des++ ) {
455  if ( !s.compare(removeStringFormat(EDescentToString(des))) ) {
456  return des;
457  }
458  }
459  return DESCENT_SECANT;
460  }
461 
470  enum ESecant{
477  };
478 
479  inline std::string ESecantToString(ESecant tr) {
480  std::string retString;
481  switch(tr) {
482  case SECANT_LBFGS: retString = "Limited-Memory BFGS"; break;
483  case SECANT_LDFP: retString = "Limited-Memory DFP"; break;
484  case SECANT_LSR1: retString = "Limited-Memory SR1"; break;
485  case SECANT_BARZILAIBORWEIN: retString = "Barzilai-Borwein"; break;
486  case SECANT_USERDEFINED: retString = "User-Defined"; break;
487  case SECANT_LAST: retString = "Last Type (Dummy)"; break;
488  default: retString = "INVALID ESecant";
489  }
490  return retString;
491  }
492 
498  inline int isValidSecant(ESecant s) {
499  return( (s == SECANT_LBFGS) ||
500  (s == SECANT_LDFP) ||
501  (s == SECANT_LSR1) ||
502  (s == SECANT_BARZILAIBORWEIN) ||
503  (s == SECANT_USERDEFINED)
504  );
505  }
506 
507  inline ESecant & operator++(ESecant &type) {
508  return type = static_cast<ESecant>(type+1);
509  }
510 
511  inline ESecant operator++(ESecant &type, int) {
512  ESecant oldval = type;
513  ++type;
514  return oldval;
515  }
516 
517  inline ESecant & operator--(ESecant &type) {
518  return type = static_cast<ESecant>(type-1);
519  }
520 
521  inline ESecant operator--(ESecant &type, int) {
522  ESecant oldval = type;
523  --type;
524  return oldval;
525  }
526 
527  inline ESecant StringToESecant(std::string s) {
528  s = removeStringFormat(s);
529  for ( ESecant sec = SECANT_LBFGS; sec < SECANT_LAST; sec++ ) {
530  if ( !s.compare(removeStringFormat(ESecantToString(sec))) ) {
531  return sec;
532  }
533  }
534  return SECANT_LBFGS;
535  }
536 
543  enum EKrylov{
549  };
550 
551  inline std::string EKrylovToString(EKrylov tr) {
552  std::string retString;
553  switch(tr) {
554  case KRYLOV_CG: retString = "Conjugate Gradients"; break;
555  case KRYLOV_CR: retString = "Conjugate Residuals"; break;
556  case KRYLOV_GMRES: retString = "GMRES"; break;
557  case KRYLOV_USERDEFINED: retString = "User Defined"; break;
558  case KRYLOV_LAST: retString = "Last Type (Dummy)"; break;
559  default: retString = "INVALID EKrylov";
560  }
561  return retString;
562  }
563 
569  inline int isValidKrylov(EKrylov d){
570  return( (d == KRYLOV_CG) ||
571  (d == KRYLOV_CR) ||
572  (d == KRYLOV_GMRES) ||
573  (d == KRYLOV_USERDEFINED) );
574  }
575 
576  inline EKrylov & operator++(EKrylov &type) {
577  return type = static_cast<EKrylov>(type+1);
578  }
579 
580  inline EKrylov operator++(EKrylov &type, int) {
581  EKrylov oldval = type;
582  ++type;
583  return oldval;
584  }
585 
586  inline EKrylov & operator--(EKrylov &type) {
587  return type = static_cast<EKrylov>(type-1);
588  }
589 
590  inline EKrylov operator--(EKrylov &type, int) {
591  EKrylov oldval = type;
592  --type;
593  return oldval;
594  }
595 
596  inline EKrylov StringToEKrylov(std::string s) {
597  s = removeStringFormat(s);
598  for ( EKrylov des = KRYLOV_CG; des < KRYLOV_LAST; des++ ) {
599  if ( !s.compare(removeStringFormat(EKrylovToString(des))) ) {
600  return des;
601  }
602  }
603  return KRYLOV_CG;
604  }
605 
631  };
632 
633  inline std::string ENonlinearCGToString(ENonlinearCG tr) {
634  std::string retString;
635  switch(tr) {
636  case NONLINEARCG_HESTENES_STIEFEL: retString = "Hestenes-Stiefel"; break;
637  case NONLINEARCG_FLETCHER_REEVES: retString = "Fletcher-Reeves"; break;
638  case NONLINEARCG_DANIEL: retString = "Daniel (uses Hessian)"; break;
639  case NONLINEARCG_POLAK_RIBIERE: retString = "Polak-Ribiere"; break;
640  case NONLINEARCG_FLETCHER_CONJDESC: retString = "Fletcher Conjugate Descent"; break;
641  case NONLINEARCG_LIU_STOREY: retString = "Liu-Storey"; break;
642  case NONLINEARCG_DAI_YUAN: retString = "Dai-Yuan"; break;
643  case NONLINEARCG_HAGER_ZHANG: retString = "Hager-Zhang"; break;
644  case NONLINEARCG_OREN_LUENBERGER: retString = "Oren-Luenberger"; break;
645  case NONLINEARCG_USERDEFINED: retString = "User Defined"; break;
646  case NONLINEARCG_LAST: retString = "Last Type (Dummy)"; break;
647  default: retString = "INVALID ENonlinearCG";
648  }
649  return retString;
650  }
651 
658  return( (s == NONLINEARCG_HESTENES_STIEFEL) ||
660  (s == NONLINEARCG_DANIEL) ||
661  (s == NONLINEARCG_POLAK_RIBIERE) ||
663  (s == NONLINEARCG_LIU_STOREY) ||
664  (s == NONLINEARCG_DAI_YUAN) ||
665  (s == NONLINEARCG_HAGER_ZHANG) ||
668  );
669  }
670 
672  return type = static_cast<ENonlinearCG>(type+1);
673  }
674 
675  inline ENonlinearCG operator++(ENonlinearCG &type, int) {
676  ENonlinearCG oldval = type;
677  ++type;
678  return oldval;
679  }
680 
682  return type = static_cast<ENonlinearCG>(type-1);
683  }
684 
685  inline ENonlinearCG operator--(ENonlinearCG &type, int) {
686  ENonlinearCG oldval = type;
687  --type;
688  return oldval;
689  }
690 
691  inline ENonlinearCG StringToENonlinearCG(std::string s) {
692  s = removeStringFormat(s);
693  for ( ENonlinearCG nlcg = NONLINEARCG_HESTENES_STIEFEL; nlcg < NONLINEARCG_LAST; nlcg++ ) {
694  if ( !s.compare(removeStringFormat(ENonlinearCGToString(nlcg))) ) {
695  return nlcg;
696  }
697  }
699  }
700 
721  };
722 
723  inline std::string ELineSearchToString(ELineSearch ls) {
724  std::string retString;
725  switch(ls) {
726  case LINESEARCH_ITERATIONSCALING: retString = "Iteration Scaling"; break;
727  case LINESEARCH_PATHBASEDTARGETLEVEL: retString = "Path-Based Target Level"; break;
728  case LINESEARCH_BACKTRACKING: retString = "Backtracking"; break;
729  case LINESEARCH_BISECTION: retString = "Bisection"; break;
730  case LINESEARCH_GOLDENSECTION: retString = "Golden Section"; break;
731  case LINESEARCH_CUBICINTERP: retString = "Cubic Interpolation"; break;
732  case LINESEARCH_BRENTS: retString = "Brent's"; break;
733  case LINESEARCH_USERDEFINED: retString = "User Defined"; break;
734  case LINESEARCH_LAST: retString = "Last Type (Dummy)"; break;
735  default: retString = "INVALID ELineSearch";
736  }
737  return retString;
738  }
739 
746  return( (ls == LINESEARCH_BACKTRACKING) ||
747  (ls == LINESEARCH_ITERATIONSCALING) ||
749  (ls == LINESEARCH_BISECTION) ||
750  (ls == LINESEARCH_GOLDENSECTION) ||
751  (ls == LINESEARCH_CUBICINTERP) ||
752  (ls == LINESEARCH_BRENTS) ||
753  (ls == LINESEARCH_USERDEFINED)
754  );
755  }
756 
758  return type = static_cast<ELineSearch>(type+1);
759  }
760 
761  inline ELineSearch operator++(ELineSearch &type, int) {
762  ELineSearch oldval = type;
763  ++type;
764  return oldval;
765  }
766 
768  return type = static_cast<ELineSearch>(type-1);
769  }
770 
771  inline ELineSearch operator--(ELineSearch &type, int) {
772  ELineSearch oldval = type;
773  --type;
774  return oldval;
775  }
776 
777  inline ELineSearch StringToELineSearch(std::string s) {
778  s = removeStringFormat(s);
779  for ( ELineSearch ls = LINESEARCH_ITERATIONSCALING; ls < LINESEARCH_LAST; ls++ ) {
780  if ( !s.compare(removeStringFormat(ELineSearchToString(ls))) ) {
781  return ls;
782  }
783  }
785  }
786 
802  };
803 
805  std::string retString;
806  switch(ls) {
807  case CURVATURECONDITION_WOLFE: retString = "Wolfe Conditions"; break;
808  case CURVATURECONDITION_STRONGWOLFE: retString = "Strong Wolfe Conditions"; break;
809  case CURVATURECONDITION_GENERALIZEDWOLFE: retString = "Generalized Wolfe Conditions"; break;
810  case CURVATURECONDITION_APPROXIMATEWOLFE: retString = "Approximate Wolfe Conditions"; break;
811  case CURVATURECONDITION_GOLDSTEIN: retString = "Goldstein Conditions"; break;
812  case CURVATURECONDITION_NULL: retString = "Null Curvature Condition"; break;
813  case CURVATURECONDITION_LAST: retString = "Last Type (Dummy)"; break;
814  default: retString = "INVALID ECurvatureCondition";
815  }
816  return retString;
817  }
818 
825  return( (ls == CURVATURECONDITION_WOLFE) ||
831  );
832  }
833 
835  return type = static_cast<ECurvatureCondition>(type+1);
836  }
837 
839  ECurvatureCondition oldval = type;
840  ++type;
841  return oldval;
842  }
843 
845  return type = static_cast<ECurvatureCondition>(type-1);
846  }
847 
849  ECurvatureCondition oldval = type;
850  --type;
851  return oldval;
852  }
853 
855  s = removeStringFormat(s);
857  if ( !s.compare(removeStringFormat(ECurvatureConditionToString(cc))) ) {
858  return cc;
859  }
860  }
862  }
863 
874  enum ECGFlag {
881  };
882 
883 
884  inline std::string ECGFlagToString(ECGFlag cgf) {
885  std::string retString;
886  switch(cgf) {
887  case CG_FLAG_SUCCESS:
888  retString = "Residual tolerance met";
889  break;
890  case CG_FLAG_ITEREXCEED:
891  retString = "Iteration limit exceeded";
892  break;
893  case CG_FLAG_NEGCURVE:
894  retString = "Negative curvature detected";
895  break;
896  case CG_FLAG_TRRADEX:
897  retString = "Trust-Region radius exceeded";
898  break;
899  case CG_FLAG_ZERORHS:
900  retString = "Initial right hand side is zero";
901  break;
902  default:
903  retString = "INVALID ECGFlag";
904  }
905  return retString;
906  }
907 
908 
929  };
930 
931  inline std::string ETestObjectivesToString(ETestObjectives to) {
932  std::string retString;
933  switch(to) {
934  case TESTOBJECTIVES_ROSENBROCK: retString = "Rosenbrock's Function"; break;
935  case TESTOBJECTIVES_FREUDENSTEINANDROTH: retString = "Freudenstein and Roth's Function"; break;
936  case TESTOBJECTIVES_BEALE: retString = "Beale's Function"; break;
937  case TESTOBJECTIVES_POWELL: retString = "Powell's Badly Scaled Function"; break;
938  case TESTOBJECTIVES_SUMOFSQUARES: retString = "Sum of Squares Function"; break;
939  case TESTOBJECTIVES_LEASTSQUARES: retString = "Least Squares Function"; break;
940  case TESTOBJECTIVES_POISSONCONTROL: retString = "Poisson Optimal Control"; break;
941  case TESTOBJECTIVES_POISSONINVERSION: retString = "Poisson Inversion Problem"; break;
942  case TESTOBJECTIVES_ZAKHAROV: retString = "Zakharov's Function"; break;
943  case TESTOBJECTIVES_LAST: retString = "Last Type (Dummy)"; break;
944  default: retString = "INVALID ETestObjectives";
945  }
946  return retString;
947  }
948 
955  return( (to == TESTOBJECTIVES_ROSENBROCK) ||
957  (to == TESTOBJECTIVES_BEALE) ||
958  (to == TESTOBJECTIVES_POWELL) ||
959  (to == TESTOBJECTIVES_SUMOFSQUARES) ||
960  (to == TESTOBJECTIVES_LEASTSQUARES) ||
964  );
965  }
966 
968  return type = static_cast<ETestObjectives>(type+1);
969  }
970 
972  ETestObjectives oldval = type;
973  ++type;
974  return oldval;
975  }
976 
978  return type = static_cast<ETestObjectives>(type-1);
979  }
980 
982  ETestObjectives oldval = type;
983  --type;
984  return oldval;
985  }
986 
987  inline ETestObjectives StringToETestObjectives(std::string s) {
988  s = removeStringFormat(s);
990  if ( !s.compare(removeStringFormat(ETestObjectivesToString(to))) ) {
991  return to;
992  }
993  }
995  }
996 
1018  };
1019 
1020  inline std::string ETestOptProblemToString(ETestOptProblem to) {
1021  std::string retString;
1022  switch(to) {
1023  case TESTOPTPROBLEM_HS1: retString = "Hock and Schittkowski Test Problem #1"; break;
1024  case TESTOPTPROBLEM_HS2: retString = "Hock and Schittkowski Test Problem #2"; break;
1025  case TESTOPTPROBLEM_HS3: retString = "Hock and Schittkowski Test Problem #3"; break;
1026  case TESTOPTPROBLEM_HS4: retString = "Hock and Schittkowski Test Problem #4"; break;
1027  case TESTOPTPROBLEM_HS5: retString = "Hock and Schittkowski Test Problem #5"; break;
1028  case TESTOPTPROBLEM_HS25: retString = "Hock and Schittkowski Test Problem #25"; break;
1029  case TESTOPTPROBLEM_HS38: retString = "Hock and Schittkowski Test Problem #38"; break;
1030  case TESTOPTPROBLEM_HS45: retString = "Hock and Schittkowski Test Problem #45"; break;
1031  case TESTOPTPROBLEM_BVP: retString = "Boundary Value Problem"; break;
1032  case TESTOPTPROBLEM_LAST: retString = "Last Type (Dummy)"; break;
1033  default: retString = "INVALID ETestOptProblem";
1034  }
1035  return retString;
1036  }
1037 
1044  return( (to == TESTOPTPROBLEM_HS1) ||
1045  (to == TESTOPTPROBLEM_HS2) ||
1046  (to == TESTOPTPROBLEM_HS3) ||
1047  (to == TESTOPTPROBLEM_HS4) ||
1048  (to == TESTOPTPROBLEM_HS5) ||
1049  (to == TESTOPTPROBLEM_HS25) ||
1050  (to == TESTOPTPROBLEM_HS38) ||
1051  (to == TESTOPTPROBLEM_HS45) ||
1052  (to == TESTOPTPROBLEM_BVP) );
1053  }
1054 
1056  return type = static_cast<ETestOptProblem>(type+1);
1057  }
1058 
1060  ETestOptProblem oldval = type;
1061  ++type;
1062  return oldval;
1063  }
1064 
1066  return type = static_cast<ETestOptProblem>(type-1);
1067  }
1068 
1070  ETestOptProblem oldval = type;
1071  --type;
1072  return oldval;
1073  }
1074 
1076  s = removeStringFormat(s);
1077  for ( ETestOptProblem to = TESTOPTPROBLEM_HS1; to < TESTOPTPROBLEM_LAST; to++ ) {
1078  if ( !s.compare(removeStringFormat(ETestOptProblemToString(to))) ) {
1079  return to;
1080  }
1081  }
1082  return TESTOPTPROBLEM_HS1;
1083  }
1084 
1085 
1096  };
1097 
1098  inline std::string EConstraintToString(EConstraint c) {
1099  std::string retString;
1100  switch(c) {
1101  case CONSTRAINT_EQUALITY: retString = "Equality"; break;
1102  case CONSTRAINT_INEQUALITY: retString = "Inequality"; break;
1103  case CONSTRAINT_LAST: retString = "Last Type (Dummy)"; break;
1104  default: retString = "INVALID EConstraint";
1105  }
1106  return retString;
1107  }
1108 
1115  return( (c == CONSTRAINT_EQUALITY) ||
1116  (c == CONSTRAINT_INEQUALITY) );
1117  }
1118 
1120  return type = static_cast<EConstraint>(type+1);
1121  }
1122 
1123  inline EConstraint operator++(EConstraint &type, int) {
1124  EConstraint oldval = type;
1125  ++type;
1126  return oldval;
1127  }
1128 
1130  return type = static_cast<EConstraint>(type-1);
1131  }
1132 
1133  inline EConstraint operator--(EConstraint &type, int) {
1134  EConstraint oldval = type;
1135  --type;
1136  return oldval;
1137  }
1138 
1139  inline EConstraint StringToEConstraint(std::string s) {
1140  s = removeStringFormat(s);
1141  for ( EConstraint ctype = CONSTRAINT_EQUALITY; ctype < CONSTRAINT_LAST; ctype++ ) {
1142  if ( !s.compare(removeStringFormat(EConstraintToString(ctype))) ) {
1143  return ctype;
1144  }
1145  }
1146  return CONSTRAINT_EQUALITY;
1147  }
1148 
1149  // For use in gradient and Hessian checks
1150  namespace Finite_Difference_Arrays {
1151 
1152  // Finite difference steps in axpy form
1153  const int shifts[4][4] = { { 1, 0, 0, 0 }, // First order
1154  { -1, 2, 0, 0 }, // Second order
1155  { -1, 2, 1, 0 }, // Third order
1156  { -1, -1, 3, 1 } // Fourth order
1157  };
1158 
1159  // Finite difference weights
1160  const double weights[4][5] = { { -1.0, 1.0, 0.0, 0.0, 0.0 }, // First order
1161  { 0.0, -1.0/2.0, 1.0/2.0, 0.0, 0.0 }, // Second order
1162  { -1.0/2.0, -1.0/3.0, 1.0, -1.0/6.0, 0.0 }, // Third order
1163  { 0.0, -2.0/3.0, 1.0/12.0, 2.0/3.0, -1.0/12.0 } // Fourth order
1164  };
1165 
1166  }
1167 
1168 
1169 // Generic conversion from Element type to Real type
1170 template<class Real, class Element>
1171 struct TypeCaster {
1172  static Real ElementToReal( const Element &val ) {
1173  return Real(0);
1174  }
1175 };
1176 
1177 // Partially specialize for complex<Real>
1178 template<class Real>
1179 struct TypeCaster<Real, std::complex<Real> > {
1180  static Real ElementToReal( const std::complex<Real> &val ) {
1181  return val.real();
1182  }
1183 };
1184 
1185 // Fully specialize for double,float
1186 template<>
1187 struct TypeCaster<double,float> {
1188  static double ElementToReal( const float &val ) {
1189  return static_cast<double>(val);
1190  }
1191 };
1192 
1193 // Cast from Element type to Real type
1194 template<class Element, class Real>
1195 Real rol_cast(const Element &val) {
1197 }
1198 
1199 
1200 
1201 
1202 
1203 
1204 namespace Exception {
1205 
1206 class NotImplemented : public Teuchos::ExceptionBase {
1207 public:
1208  NotImplemented( const std::string& what_arg ) :
1209  Teuchos::ExceptionBase(what_arg) {}
1210 
1211 
1212 }; // class NotImplemented
1213 
1214 
1215 } // namespace Exception
1216 
1217 
1218 } // namespace ROL
1219 
1220 
1434 #endif
std::string ECGFlagToString(ECGFlag cgf)
Definition: ROL_Types.hpp:884
ETestOptProblem
Enumeration of test optimization problems.
Definition: ROL_Types.hpp:1007
int isValidKrylov(EKrylov d)
Verifies validity of a Secant enum.
Definition: ROL_Types.hpp:569
EStep StringToEStep(std::string s)
Definition: ROL_Types.hpp:307
static Real ElementToReal(const Element &val)
Definition: ROL_Types.hpp:1172
int isValidConstraint(EConstraint c)
Verifies validity of a Secant enum.
Definition: ROL_Types.hpp:1114
int isValidSecant(ESecant s)
Verifies validity of a Secant enum.
Definition: ROL_Types.hpp:498
Real ROL_THRESHOLD(void)
Tolerance for various equality tests.
Definition: ROL_Types.hpp:145
const double weights[4][5]
Definition: ROL_Types.hpp:1160
ELineSearch StringToELineSearch(std::string s)
Definition: ROL_Types.hpp:777
EBoundAlgorithm StringToEBoundAlgorithm(std::string s)
Definition: ROL_Types.hpp:375
EBoundAlgorithm
Enumeration of algorithms to handle bound constraints.
Definition: ROL_Types.hpp:324
Real ROL_INF(void)
Definition: ROL_Types.hpp:155
int isValidBoundAlgorithm(EBoundAlgorithm d)
Verifies validity of a Bound Algorithm enum.
Definition: ROL_Types.hpp:348
NotImplemented(const std::string &what_arg)
Definition: ROL_Types.hpp:1208
std::string removeStringFormat(std::string s)
Definition: ROL_Types.hpp:174
ELineSearch
Enumeration of line-search types.
Definition: ROL_Types.hpp:711
EConstraint StringToEConstraint(std::string s)
Definition: ROL_Types.hpp:1139
ESecant StringToESecant(std::string s)
Definition: ROL_Types.hpp:527
std::string EDescentToString(EDescent tr)
Definition: ROL_Types.hpp:404
int isValidTestOptProblem(ETestOptProblem to)
Verifies validity of a TestOptProblem enum.
Definition: ROL_Types.hpp:1043
static Real ElementToReal(const std::complex< Real > &val)
Definition: ROL_Types.hpp:1180
ECGFlag
Enumation of flags used by conjugate gradient methods.
Definition: ROL_Types.hpp:874
Teuchos::RCP< Vector< Real > > descentVec
Definition: ROL_Types.hpp:123
EKrylov
Enumeration of Krylov methods.
Definition: ROL_Types.hpp:543
int isValidTestObjectives(ETestObjectives to)
Verifies validity of a TestObjectives enum.
Definition: ROL_Types.hpp:954
EKrylov StringToEKrylov(std::string s)
Definition: ROL_Types.hpp:596
EDescent StringToEDescent(std::string s)
Definition: ROL_Types.hpp:452
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:619
ETestObjectives StringToETestObjectives(std::string s)
Definition: ROL_Types.hpp:987
std::string ECurvatureConditionToString(ECurvatureCondition ls)
Definition: ROL_Types.hpp:804
Real rol_cast(const Element &val)
Definition: ROL_Types.hpp:1195
std::string EConstraintToString(EConstraint c)
Definition: ROL_Types.hpp:1098
ESecant
Enumeration of secant update algorithms.
Definition: ROL_Types.hpp:470
std::string ETestOptProblemToString(ETestOptProblem to)
Definition: ROL_Types.hpp:1020
std::string ENonlinearCGToString(ENonlinearCG tr)
Definition: ROL_Types.hpp:633
ENonlinearCG StringToENonlinearCG(std::string s)
Definition: ROL_Types.hpp:691
int isValidDescent(EDescent d)
Verifies validity of a Secant enum.
Definition: ROL_Types.hpp:423
std::string ELineSearchToString(ELineSearch ls)
Definition: ROL_Types.hpp:723
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:745
State for step class. Will be used for restarts.
Definition: ROL_Types.hpp:121
std::string EProblemToString(EProblem p)
Definition: ROL_Types.hpp:257
int isValidStep(EStep ls)
Verifies validity of a TrustRegion enum.
Definition: ROL_Types.hpp:276
ETestObjectives
Enumeration of test objective functions.
Definition: ROL_Types.hpp:918
Teuchos::RCP< Vector< Real > > minIterVec
Definition: ROL_Types.hpp:107
std::string EKrylovToString(EKrylov tr)
Definition: ROL_Types.hpp:551
static double ElementToReal(const float &val)
Definition: ROL_Types.hpp:1188
int isCompatibleStep(EProblem p, EStep s)
Definition: ROL_Types.hpp:230
Teuchos::RCP< Vector< Real > > constraintVec
Definition: ROL_Types.hpp:124
int isValidCurvatureCondition(ECurvatureCondition ls)
Verifies validity of a CurvatureCondition enum.
Definition: ROL_Types.hpp:824
ECurvatureCondition
Enumeration of line-search curvature conditions.
Definition: ROL_Types.hpp:794
std::string ETestObjectivesToString(ETestObjectives to)
Definition: ROL_Types.hpp:931
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:854
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:479
std::string EStepToString(EStep tr)
Definition: ROL_Types.hpp:213
EStep
Enumeration of step types.
Definition: ROL_Types.hpp:201
EConstraint
Enumeration of constraint types.
Definition: ROL_Types.hpp:1092
ETestOptProblem StringToETestOptProblem(std::string s)
Definition: ROL_Types.hpp:1075
Real ROL_UNDERFLOW(void)
Platform-dependent minimum double.
Definition: ROL_Types.hpp:165
EProblem
Definition: ROL_Types.hpp:182
int isValidNonlinearCG(ENonlinearCG s)
Verifies validity of a NonlinearCG enum.
Definition: ROL_Types.hpp:657
std::string EBoundAlgorithmToString(EBoundAlgorithm tr)
Definition: ROL_Types.hpp:331
EDescent
Enumeration of descent direction types.
Definition: ROL_Types.hpp:395
Real ROL_NINF(void)
Definition: ROL_Types.hpp:159
Teuchos::RCP< Vector< Real > > gradientVec
Definition: ROL_Types.hpp:122