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 <string>
60 #include <limits>
61 #include <Teuchos_getConst.hpp>
62 #include <Teuchos_RCP.hpp>
63 #include <Teuchos_ScalarTraits.hpp>
64 #include <Teuchos_TestForException.hpp>
65 #include <ROL_Vector.hpp>
66 
70 #define ROL_NUM_CHECKDERIV_STEPS 13
71 
72 namespace ROL {
73 
76  template<class Real>
77  struct AlgorithmState {
78  int iter;
79  int minIter;
80  int nfval;
81  int ncval;
82  int ngrad;
83  Real value;
84  Real minValue;
85  Real gnorm;
86  Real cnorm;
87  Real snorm;
90  bool flag;
91  Teuchos::RCP<Vector<Real> > iterateVec;
92  Teuchos::RCP<Vector<Real> > lagmultVec;
93  Teuchos::RCP<Vector<Real> > minIterVec;
94  AlgorithmState(void) : iter(0), minIter(0), nfval(0), ngrad(0), value(0), minValue(0),
95  gnorm(std::numeric_limits<Real>::max()),
96  cnorm(std::numeric_limits<Real>::max()),
97  snorm(std::numeric_limits<Real>::max()),
98  aggregateGradientNorm(std::numeric_limits<Real>::max()),
99  aggregateModelError(std::numeric_limits<Real>::max()),
100  flag(false),
101  iterateVec(Teuchos::null), lagmultVec(Teuchos::null), minIterVec(Teuchos::null) {}
102  };
103 
106  template<class Real>
107  struct StepState {
108  Teuchos::RCP<Vector<Real> > gradientVec;
109  Teuchos::RCP<Vector<Real> > descentVec;
110  Teuchos::RCP<Vector<Real> > constraintVec;
111  Real searchSize; // line search parameter (alpha) or trust-region radius (delta)
112  StepState(void) : gradientVec(Teuchos::null), descentVec(Teuchos::null), constraintVec(Teuchos::null),
113  searchSize(0) {}
114  };
115 
118  static const double ROL_EPSILON = std::abs(Teuchos::ScalarTraits<double>::eps());
119 
122  static const double ROL_THRESHOLD = 10.0 * ROL_EPSILON;
123 
126  static const double ROL_OVERFLOW = std::abs(Teuchos::ScalarTraits<double>::rmax());
127 
130  static const double ROL_UNDERFLOW = std::abs(Teuchos::ScalarTraits<double>::rmin());
131 
133  bool operator()(char c) {
134  return (c ==' ' || c =='-' || c == '(' || c == ')' || c=='\'' || c=='\r' || c=='\n' || c=='\t');
135  }
136  };
137 
138  inline std::string removeStringFormat( std::string s ) {
139  std::string output = s;
140  output.erase( std::remove_if( output.begin(), output.end(), removeSpecialCharacters()), output.end() );
141  std::transform( output.begin(), output.end(), output.begin(), ::tolower );
142  return output;
143  }
144 
156  enum EStep{
165  };
166 
167  inline std::string EStepToString(EStep tr) {
168  std::string retString;
169  switch(tr) {
170  case STEP_AUGMENTEDLAGRANGIAN: retString = "Augmented Lagrangian"; break;
171  case STEP_BUNDLE: retString = "Bundle"; break;
172  case STEP_COMPOSITESTEP: retString = "Composite Step"; break;
173  case STEP_LINESEARCH: retString = "Line Search"; break;
174  case STEP_MOREAUYOSIDAPENALTY: retString = "Moreau-Yosida Penalty"; break;
175  case STEP_PRIMALDUALACTIVESET: retString = "Primal Dual Active Set"; break;
176  case STEP_TRUSTREGION: retString = "Trust Region"; break;
177  case STEP_LAST: retString = "Last Type (Dummy)"; break;
178  default: retString = "INVALID EStep";
179  }
180  return retString;
181  }
182 
188  inline int isValidStep(EStep ls) {
189  return( (ls == STEP_AUGMENTEDLAGRANGIAN) ||
190  (ls == STEP_BUNDLE) ||
191  (ls == STEP_COMPOSITESTEP) ||
192  (ls == STEP_LINESEARCH) ||
193  (ls == STEP_MOREAUYOSIDAPENALTY) ||
194  (ls == STEP_PRIMALDUALACTIVESET) ||
195  (ls == STEP_TRUSTREGION) );
196  }
197 
198  inline EStep & operator++(EStep &type) {
199  return type = static_cast<EStep>(type+1);
200  }
201 
202  inline EStep operator++(EStep &type, int) {
203  EStep oldval = type;
204  ++type;
205  return oldval;
206  }
207 
208  inline EStep & operator--(EStep &type) {
209  return type = static_cast<EStep>(type-1);
210  }
211 
212  inline EStep operator--(EStep &type, int) {
213  EStep oldval = type;
214  --type;
215  return oldval;
216  }
217 
218  inline EStep StringToEStep(std::string s) {
219  s = removeStringFormat(s);
220  for ( EStep tr = STEP_AUGMENTEDLAGRANGIAN; tr < STEP_LAST; tr++ ) {
221  if ( !s.compare(removeStringFormat(EStepToString(tr))) ) {
222  return tr;
223  }
224  }
225  return STEP_TRUSTREGION;
226  }
227 
240  };
241 
242  inline std::string EBoundAlgorithmToString(EBoundAlgorithm tr) {
243  std::string retString;
244  switch(tr) {
245  case BOUNDALGORITHM_PROJECTED: retString = "Projected"; break;
246  case BOUNDALGORITHM_PRIMALDUALACTIVESET: retString = "Primal Dual Active Set"; break;
247  case BOUNDALGORITHM_INTERIORPOINTS: retString = "Interior Points"; break;
248  case BOUNDALGORITHM_LAST: retString = "Last Type (Dummy)"; break;
249  default: retString = "INVALID EBoundAlgorithm";
250  }
251  return retString;
252  }
253 
260  return( (d == BOUNDALGORITHM_PROJECTED) ||
263  );
264  }
265 
267  return type = static_cast<EBoundAlgorithm>(type+1);
268  }
269 
271  EBoundAlgorithm oldval = type;
272  ++type;
273  return oldval;
274  }
275 
277  return type = static_cast<EBoundAlgorithm>(type-1);
278  }
279 
281  EBoundAlgorithm oldval = type;
282  --type;
283  return oldval;
284  }
285 
286  inline EBoundAlgorithm StringToEBoundAlgorithm(std::string s) {
287  s = removeStringFormat(s);
288  for ( EBoundAlgorithm des = BOUNDALGORITHM_PROJECTED; des < BOUNDALGORITHM_LAST; des++ ) {
289  if ( !s.compare(removeStringFormat(EBoundAlgorithmToString(des))) ) {
290  return des;
291  }
292  }
294  }
295 
306  enum EDescent{
313  };
314 
315  inline std::string EDescentToString(EDescent tr) {
316  std::string retString;
317  switch(tr) {
318  case DESCENT_STEEPEST: retString = "Steepest Descent"; break;
319  case DESCENT_NONLINEARCG: retString = "Nonlinear CG"; break;
320  case DESCENT_SECANT: retString = "Quasi-Newton Method"; break;
321  case DESCENT_NEWTON: retString = "Newton's Method"; break;
322  case DESCENT_NEWTONKRYLOV: retString = "Newton-Krylov"; break;
323  case DESCENT_LAST: retString = "Last Type (Dummy)"; break;
324  default: retString = "INVALID ESecant";
325  }
326  return retString;
327  }
328 
334  inline int isValidDescent(EDescent d){
335  return( (d == DESCENT_STEEPEST) ||
336  (d == DESCENT_NONLINEARCG) ||
337  (d == DESCENT_SECANT) ||
338  (d == DESCENT_NEWTON) ||
339  (d == DESCENT_NEWTONKRYLOV)
340  );
341  }
342 
343  inline EDescent & operator++(EDescent &type) {
344  return type = static_cast<EDescent>(type+1);
345  }
346 
347  inline EDescent operator++(EDescent &type, int) {
348  EDescent oldval = type;
349  ++type;
350  return oldval;
351  }
352 
353  inline EDescent & operator--(EDescent &type) {
354  return type = static_cast<EDescent>(type-1);
355  }
356 
357  inline EDescent operator--(EDescent &type, int) {
358  EDescent oldval = type;
359  --type;
360  return oldval;
361  }
362 
363  inline EDescent StringToEDescent(std::string s) {
364  s = removeStringFormat(s);
365  for ( EDescent des = DESCENT_STEEPEST; des < DESCENT_LAST; des++ ) {
366  if ( !s.compare(removeStringFormat(EDescentToString(des))) ) {
367  return des;
368  }
369  }
370  return DESCENT_SECANT;
371  }
372 
381  enum ESecant{
388  };
389 
390  inline std::string ESecantToString(ESecant tr) {
391  std::string retString;
392  switch(tr) {
393  case SECANT_LBFGS: retString = "Limited-Memory BFGS"; break;
394  case SECANT_LDFP: retString = "Limited-Memory DFP"; break;
395  case SECANT_LSR1: retString = "Limited-Memory SR1"; break;
396  case SECANT_BARZILAIBORWEIN: retString = "Barzilai-Borwein"; break;
397  case SECANT_USERDEFINED: retString = "User-Defined"; break;
398  case SECANT_LAST: retString = "Last Type (Dummy)"; break;
399  default: retString = "INVALID ESecant";
400  }
401  return retString;
402  }
403 
409  inline int isValidSecant(ESecant s) {
410  return( (s == SECANT_LBFGS) ||
411  (s == SECANT_LDFP) ||
412  (s == SECANT_LSR1) ||
413  (s == SECANT_BARZILAIBORWEIN) ||
414  (s == SECANT_USERDEFINED)
415  );
416  }
417 
418  inline ESecant & operator++(ESecant &type) {
419  return type = static_cast<ESecant>(type+1);
420  }
421 
422  inline ESecant operator++(ESecant &type, int) {
423  ESecant oldval = type;
424  ++type;
425  return oldval;
426  }
427 
428  inline ESecant & operator--(ESecant &type) {
429  return type = static_cast<ESecant>(type-1);
430  }
431 
432  inline ESecant operator--(ESecant &type, int) {
433  ESecant oldval = type;
434  --type;
435  return oldval;
436  }
437 
438  inline ESecant StringToESecant(std::string s) {
439  s = removeStringFormat(s);
440  for ( ESecant sec = SECANT_LBFGS; sec < SECANT_LAST; sec++ ) {
441  if ( !s.compare(removeStringFormat(ESecantToString(sec))) ) {
442  return sec;
443  }
444  }
445  return SECANT_LBFGS;
446  }
447 
454  enum EKrylov{
459  };
460 
461  inline std::string EKrylovToString(EKrylov tr) {
462  std::string retString;
463  switch(tr) {
464  case KRYLOV_CG: retString = "Conjugate Gradients"; break;
465  case KRYLOV_CR: retString = "Conjugate Residuals"; break;
466  case KRYLOV_USERDEFINED: retString = "User Defined"; break;
467  case KRYLOV_LAST: retString = "Last Type (Dummy)"; break;
468  default: retString = "INVALID EKrylov";
469  }
470  return retString;
471  }
472 
478  inline int isValidKrylov(EKrylov d){
479  return( (d == KRYLOV_CG) ||
480  (d == KRYLOV_CR) ||
481  (d == KRYLOV_USERDEFINED) );
482  }
483 
484  inline EKrylov & operator++(EKrylov &type) {
485  return type = static_cast<EKrylov>(type+1);
486  }
487 
488  inline EKrylov operator++(EKrylov &type, int) {
489  EKrylov oldval = type;
490  ++type;
491  return oldval;
492  }
493 
494  inline EKrylov & operator--(EKrylov &type) {
495  return type = static_cast<EKrylov>(type-1);
496  }
497 
498  inline EKrylov operator--(EKrylov &type, int) {
499  EKrylov oldval = type;
500  --type;
501  return oldval;
502  }
503 
504  inline EKrylov StringToEKrylov(std::string s) {
505  s = removeStringFormat(s);
506  for ( EKrylov des = KRYLOV_CG; des < KRYLOV_LAST; des++ ) {
507  if ( !s.compare(removeStringFormat(EKrylovToString(des))) ) {
508  return des;
509  }
510  }
511  return KRYLOV_CG;
512  }
513 
538  };
539 
540  inline std::string ENonlinearCGToString(ENonlinearCG tr) {
541  std::string retString;
542  switch(tr) {
543  case NONLINEARCG_HESTENES_STIEFEL: retString = "Hestenes-Stiefel"; break;
544  case NONLINEARCG_FLETCHER_REEVES: retString = "Fletcher-Reeves"; break;
545  case NONLINEARCG_DANIEL: retString = "Daniel (uses Hessian)"; break;
546  case NONLINEARCG_POLAK_RIBIERE: retString = "Polak-Ribiere"; break;
547  case NONLINEARCG_FLETCHER_CONJDESC: retString = "Fletcher Conjugate Descent"; break;
548  case NONLINEARCG_LIU_STOREY: retString = "Liu-Storey"; break;
549  case NONLINEARCG_DAI_YUAN: retString = "Dai-Yuan"; break;
550  case NONLINEARCG_HAGER_ZHANG: retString = "Hager-Zhang"; break;
551  case NONLINEARCG_OREN_LUENBERGER: retString = "Oren-Luenberger"; break;
552  case NONLINEARCG_LAST: retString = "Last Type (Dummy)"; break;
553  default: retString = "INVALID ENonlinearCG";
554  }
555  return retString;
556  }
557 
564  return( (s == NONLINEARCG_HESTENES_STIEFEL) ||
566  (s == NONLINEARCG_DANIEL) ||
567  (s == NONLINEARCG_POLAK_RIBIERE) ||
569  (s == NONLINEARCG_LIU_STOREY) ||
570  (s == NONLINEARCG_DAI_YUAN) ||
571  (s == NONLINEARCG_HAGER_ZHANG) ||
573  );
574  }
575 
577  return type = static_cast<ENonlinearCG>(type+1);
578  }
579 
580  inline ENonlinearCG operator++(ENonlinearCG &type, int) {
581  ENonlinearCG oldval = type;
582  ++type;
583  return oldval;
584  }
585 
587  return type = static_cast<ENonlinearCG>(type-1);
588  }
589 
590  inline ENonlinearCG operator--(ENonlinearCG &type, int) {
591  ENonlinearCG oldval = type;
592  --type;
593  return oldval;
594  }
595 
596  inline ENonlinearCG StringToENonlinearCG(std::string s) {
597  s = removeStringFormat(s);
598  for ( ENonlinearCG nlcg = NONLINEARCG_HESTENES_STIEFEL; nlcg < NONLINEARCG_LAST; nlcg++ ) {
599  if ( !s.compare(removeStringFormat(ENonlinearCGToString(nlcg))) ) {
600  return nlcg;
601  }
602  }
604  }
605 
626  };
627 
628  inline std::string ELineSearchToString(ELineSearch ls) {
629  std::string retString;
630  switch(ls) {
631  case LINESEARCH_ITERATIONSCALING: retString = "Iteration Scaling"; break;
632  case LINESEARCH_PATHBASEDTARGETLEVEL: retString = "Path-Based Target Level"; break;
633  case LINESEARCH_BACKTRACKING: retString = "Backtracking"; break;
634  case LINESEARCH_BISECTION: retString = "Bisection"; break;
635  case LINESEARCH_GOLDENSECTION: retString = "Golden Section"; break;
636  case LINESEARCH_CUBICINTERP: retString = "Cubic Interpolation"; break;
637  case LINESEARCH_BRENTS: retString = "Brents"; break;
638  case LINESEARCH_USERDEFINED: retString = "User Defined"; break;
639  case LINESEARCH_LAST: retString = "Last Type (Dummy)"; break;
640  default: retString = "INVALID ELineSearch";
641  }
642  return retString;
643  }
644 
651  return( (ls == LINESEARCH_BACKTRACKING) ||
652  (ls == LINESEARCH_ITERATIONSCALING) ||
654  (ls == LINESEARCH_BISECTION) ||
655  (ls == LINESEARCH_GOLDENSECTION) ||
656  (ls == LINESEARCH_CUBICINTERP) ||
657  (ls == LINESEARCH_BRENTS) ||
658  (ls == LINESEARCH_USERDEFINED)
659  );
660  }
661 
663  return type = static_cast<ELineSearch>(type+1);
664  }
665 
666  inline ELineSearch operator++(ELineSearch &type, int) {
667  ELineSearch oldval = type;
668  ++type;
669  return oldval;
670  }
671 
673  return type = static_cast<ELineSearch>(type-1);
674  }
675 
676  inline ELineSearch operator--(ELineSearch &type, int) {
677  ELineSearch oldval = type;
678  --type;
679  return oldval;
680  }
681 
682  inline ELineSearch StringToELineSearch(std::string s) {
683  s = removeStringFormat(s);
684  for ( ELineSearch ls = LINESEARCH_ITERATIONSCALING; ls < LINESEARCH_LAST; ls++ ) {
685  if ( !s.compare(removeStringFormat(ELineSearchToString(ls))) ) {
686  return ls;
687  }
688  }
690  }
691 
707  };
708 
710  std::string retString;
711  switch(ls) {
712  case CURVATURECONDITION_WOLFE: retString = "Wolfe Conditions"; break;
713  case CURVATURECONDITION_STRONGWOLFE: retString = "Strong Wolfe Conditions"; break;
714  case CURVATURECONDITION_GENERALIZEDWOLFE: retString = "Generalized Wolfe Conditions"; break;
715  case CURVATURECONDITION_APPROXIMATEWOLFE: retString = "Approximate Wolfe Conditions"; break;
716  case CURVATURECONDITION_GOLDSTEIN: retString = "Goldstein Conditions"; break;
717  case CURVATURECONDITION_NULL: retString = "Null Curvature Condition"; break;
718  case CURVATURECONDITION_LAST: retString = "Last Type (Dummy)"; break;
719  default: retString = "INVALID ECurvatureCondition";
720  }
721  return retString;
722  }
723 
730  return( (ls == CURVATURECONDITION_WOLFE) ||
736  );
737  }
738 
740  return type = static_cast<ECurvatureCondition>(type+1);
741  }
742 
744  ECurvatureCondition oldval = type;
745  ++type;
746  return oldval;
747  }
748 
750  return type = static_cast<ECurvatureCondition>(type-1);
751  }
752 
754  ECurvatureCondition oldval = type;
755  --type;
756  return oldval;
757  }
758 
760  s = removeStringFormat(s);
762  if ( !s.compare(removeStringFormat(ECurvatureConditionToString(cc))) ) {
763  return cc;
764  }
765  }
767  }
768 
783  };
784 
785  inline std::string ETrustRegionToString(ETrustRegion tr) {
786  std::string retString;
787  switch(tr) {
788  case TRUSTREGION_CAUCHYPOINT: retString = "Cauchy Point"; break;
789  case TRUSTREGION_TRUNCATEDCG: retString = "Truncated CG"; break;
790  case TRUSTREGION_DOGLEG: retString = "Dogleg"; break;
791  case TRUSTREGION_DOUBLEDOGLEG: retString = "Double Dogleg"; break;
792  case TRUSTREGION_LAST: retString = "Last Type (Dummy)"; break;
793  default: retString = "INVALID ETrustRegion";
794  }
795  return retString;
796  }
797 
804  return( (ls == TRUSTREGION_CAUCHYPOINT) ||
805  (ls == TRUSTREGION_TRUNCATEDCG) ||
806  (ls == TRUSTREGION_DOGLEG) ||
808  );
809  }
810 
812  return type = static_cast<ETrustRegion>(type+1);
813  }
814 
815  inline ETrustRegion operator++(ETrustRegion &type, int) {
816  ETrustRegion oldval = type;
817  ++type;
818  return oldval;
819  }
820 
822  return type = static_cast<ETrustRegion>(type-1);
823  }
824 
825  inline ETrustRegion operator--(ETrustRegion &type, int) {
826  ETrustRegion oldval = type;
827  --type;
828  return oldval;
829  }
830 
831  inline ETrustRegion StringToETrustRegion(std::string s) {
832  s = removeStringFormat(s);
833  for ( ETrustRegion tr = TRUSTREGION_CAUCHYPOINT; tr < TRUSTREGION_LAST; tr++ ) {
834  if ( !s.compare(removeStringFormat(ETrustRegionToString(tr))) ) {
835  return tr;
836  }
837  }
839  }
840 
861  };
862 
863  inline std::string ETestObjectivesToString(ETestObjectives to) {
864  std::string retString;
865  switch(to) {
866  case TESTOBJECTIVES_ROSENBROCK: retString = "Rosenbrock's Function"; break;
867  case TESTOBJECTIVES_FREUDENSTEINANDROTH: retString = "Freudenstein and Roth's Function"; break;
868  case TESTOBJECTIVES_BEALE: retString = "Beale's Function"; break;
869  case TESTOBJECTIVES_POWELL: retString = "Powell's Badly Scaled Function"; break;
870  case TESTOBJECTIVES_SUMOFSQUARES: retString = "Sum of Squares Function"; break;
871  case TESTOBJECTIVES_LEASTSQUARES: retString = "Least Squares Function"; break;
872  case TESTOBJECTIVES_POISSONCONTROL: retString = "Poisson Optimal Control"; break;
873  case TESTOBJECTIVES_POISSONINVERSION: retString = "Poisson Inversion Problem"; break;
874  case TESTOBJECTIVES_ZAKHAROV: retString = "Zakharov's Function"; break;
875  case TESTOBJECTIVES_LAST: retString = "Last Type (Dummy)"; break;
876  default: retString = "INVALID ETestObjectives";
877  }
878  return retString;
879  }
880 
887  return( (to == TESTOBJECTIVES_ROSENBROCK) ||
889  (to == TESTOBJECTIVES_BEALE) ||
890  (to == TESTOBJECTIVES_POWELL) ||
891  (to == TESTOBJECTIVES_SUMOFSQUARES) ||
892  (to == TESTOBJECTIVES_LEASTSQUARES) ||
896  );
897  }
898 
900  return type = static_cast<ETestObjectives>(type+1);
901  }
902 
904  ETestObjectives oldval = type;
905  ++type;
906  return oldval;
907  }
908 
910  return type = static_cast<ETestObjectives>(type-1);
911  }
912 
914  ETestObjectives oldval = type;
915  --type;
916  return oldval;
917  }
918 
919  inline ETestObjectives StringToETestObjectives(std::string s) {
920  s = removeStringFormat(s);
922  if ( !s.compare(removeStringFormat(ETestObjectivesToString(to))) ) {
923  return to;
924  }
925  }
927  }
928 
950  };
951 
952  inline std::string ETestOptProblemToString(ETestOptProblem to) {
953  std::string retString;
954  switch(to) {
955  case TESTOPTPROBLEM_HS1: retString = "Hock and Schittkowski Test Problem #1"; break;
956  case TESTOPTPROBLEM_HS2: retString = "Hock and Schittkowski Test Problem #2"; break;
957  case TESTOPTPROBLEM_HS3: retString = "Hock and Schittkowski Test Problem #3"; break;
958  case TESTOPTPROBLEM_HS4: retString = "Hock and Schittkowski Test Problem #4"; break;
959  case TESTOPTPROBLEM_HS5: retString = "Hock and Schittkowski Test Problem #5"; break;
960  case TESTOPTPROBLEM_HS25: retString = "Hock and Schittkowski Test Problem #25"; break;
961  case TESTOPTPROBLEM_HS38: retString = "Hock and Schittkowski Test Problem #38"; break;
962  case TESTOPTPROBLEM_HS45: retString = "Hock and Schittkowski Test Problem #45"; break;
963  case TESTOPTPROBLEM_BVP: retString = "Boundary Value Problem"; break;
964  case TESTOPTPROBLEM_LAST: retString = "Last Type (Dummy)"; break;
965  default: retString = "INVALID ETestOptProblem";
966  }
967  return retString;
968  }
969 
976  return( (to == TESTOPTPROBLEM_HS1) ||
977  (to == TESTOPTPROBLEM_HS2) ||
978  (to == TESTOPTPROBLEM_HS3) ||
979  (to == TESTOPTPROBLEM_HS4) ||
980  (to == TESTOPTPROBLEM_HS5) ||
981  (to == TESTOPTPROBLEM_HS25) ||
982  (to == TESTOPTPROBLEM_HS38) ||
983  (to == TESTOPTPROBLEM_HS45) ||
984  (to == TESTOPTPROBLEM_BVP) );
985  }
986 
988  return type = static_cast<ETestOptProblem>(type+1);
989  }
990 
992  ETestOptProblem oldval = type;
993  ++type;
994  return oldval;
995  }
996 
998  return type = static_cast<ETestOptProblem>(type-1);
999  }
1000 
1002  ETestOptProblem oldval = type;
1003  --type;
1004  return oldval;
1005  }
1006 
1008  s = removeStringFormat(s);
1009  for ( ETestOptProblem to = TESTOPTPROBLEM_HS1; to < TESTOPTPROBLEM_LAST; to++ ) {
1010  if ( !s.compare(removeStringFormat(ETestOptProblemToString(to))) ) {
1011  return to;
1012  }
1013  }
1014  return TESTOPTPROBLEM_HS1;
1015  }
1016 
1017 
1028  };
1029 
1030  inline std::string EConstraintToString(EConstraint c) {
1031  std::string retString;
1032  switch(c) {
1033  case CONSTRAINT_EQUALITY: retString = "Equality"; break;
1034  case CONSTRAINT_INEQUALITY: retString = "Inequality"; break;
1035  case CONSTRAINT_LAST: retString = "Last Type (Dummy)"; break;
1036  default: retString = "INVALID EConstraint";
1037  }
1038  return retString;
1039  }
1040 
1047  return( (c == CONSTRAINT_EQUALITY) ||
1048  (c == CONSTRAINT_INEQUALITY) );
1049  }
1050 
1052  return type = static_cast<EConstraint>(type+1);
1053  }
1054 
1055  inline EConstraint operator++(EConstraint &type, int) {
1056  EConstraint oldval = type;
1057  ++type;
1058  return oldval;
1059  }
1060 
1062  return type = static_cast<EConstraint>(type-1);
1063  }
1064 
1065  inline EConstraint operator--(EConstraint &type, int) {
1066  EConstraint oldval = type;
1067  --type;
1068  return oldval;
1069  }
1070 
1071  inline EConstraint StringToEConstraint(std::string s) {
1072  s = removeStringFormat(s);
1073  for ( EConstraint ctype = CONSTRAINT_EQUALITY; ctype < CONSTRAINT_LAST; ctype++ ) {
1074  if ( !s.compare(removeStringFormat(EConstraintToString(ctype))) ) {
1075  return ctype;
1076  }
1077  }
1078  return CONSTRAINT_EQUALITY;
1079  }
1080 
1081  // For use in gradient and Hessian checks
1082  namespace Finite_Difference_Arrays {
1083 
1084  // Finite difference steps in axpy form
1085  const int shifts[4][4] = { { 1, 0, 0, 0 }, // First order
1086  { -1, 2, 0, 0 }, // Second order
1087  { -1, 2, 1, 0 }, // Third order
1088  { -1, -1, 3, 1 } // Fourth order
1089  };
1090 
1091  // Finite difference weights
1092  const double weights[4][5] = { { -1.0, 1.0, 0.0, 0.0, 0.0 }, // First order
1093  { 0.0, -1.0/2.0, 1.0/2.0, 0.0, 0.0 }, // Second order
1094  { -1.0/2.0, -1.0/3.0, 1.0, -1.0/6.0, 0.0 }, // Third order
1095  { 0.0, -2.0/3.0, 1.0/12.0, 2.0/3.0, -1.0/12.0 } // Fourth order
1096  };
1097 
1098  }
1099 
1100 
1101 
1102 } // namespace ROL
1103 
1104 
1313 #endif
ETestOptProblem
Enumeration of test optimization problems.
Definition: ROL_Types.hpp:939
int isValidKrylov(EKrylov d)
Verifies validity of a Secant enum.
Definition: ROL_Types.hpp:478
EStep StringToEStep(std::string s)
Definition: ROL_Types.hpp:218
int isValidConstraint(EConstraint c)
Verifies validity of a Secant enum.
Definition: ROL_Types.hpp:1046
int isValidSecant(ESecant s)
Verifies validity of a Secant enum.
Definition: ROL_Types.hpp:409
EDistribution & operator--(EDistribution &type)
const double weights[4][5]
Definition: ROL_Types.hpp:1092
ELineSearch StringToELineSearch(std::string s)
Definition: ROL_Types.hpp:682
EBoundAlgorithm StringToEBoundAlgorithm(std::string s)
Definition: ROL_Types.hpp:286
EBoundAlgorithm
Enumeration of algorithms to handle bound constraints.
Definition: ROL_Types.hpp:235
int isValidBoundAlgorithm(EBoundAlgorithm d)
Verifies validity of a Bound Algorithm enum.
Definition: ROL_Types.hpp:259
std::string removeStringFormat(std::string s)
Definition: ROL_Types.hpp:138
ELineSearch
Enumeration of line-search types.
Definition: ROL_Types.hpp:616
static const double ROL_THRESHOLD
Tolerance for various equality tests.
Definition: ROL_Types.hpp:122
EConstraint StringToEConstraint(std::string s)
Definition: ROL_Types.hpp:1071
ESecant StringToESecant(std::string s)
Definition: ROL_Types.hpp:438
std::string EDescentToString(EDescent tr)
Definition: ROL_Types.hpp:315
int isValidTestOptProblem(ETestOptProblem to)
Verifies validity of a TestOptProblem enum.
Definition: ROL_Types.hpp:975
Teuchos::RCP< Vector< Real > > descentVec
Definition: ROL_Types.hpp:109
EKrylov
Enumeration of Krylov methods.
Definition: ROL_Types.hpp:454
int isValidTestObjectives(ETestObjectives to)
Verifies validity of a TestObjectives enum.
Definition: ROL_Types.hpp:886
int isValidTrustRegion(ETrustRegion ls)
Verifies validity of a TrustRegion enum.
Definition: ROL_Types.hpp:803
EKrylov StringToEKrylov(std::string s)
Definition: ROL_Types.hpp:504
EDescent StringToEDescent(std::string s)
Definition: ROL_Types.hpp:363
State for algorithm class. Will be used for restarts.
Definition: ROL_Types.hpp:77
ENonlinearCG
Enumeration of nonlinear CG algorithms.
Definition: ROL_Types.hpp:527
ETestObjectives StringToETestObjectives(std::string s)
Definition: ROL_Types.hpp:919
std::string ECurvatureConditionToString(ECurvatureCondition ls)
Definition: ROL_Types.hpp:709
std::string EConstraintToString(EConstraint c)
Definition: ROL_Types.hpp:1030
ESecant
Enumeration of secant update algorithms.
Definition: ROL_Types.hpp:381
std::string ETestOptProblemToString(ETestOptProblem to)
Definition: ROL_Types.hpp:952
EDistribution & operator++(EDistribution &type)
std::string ENonlinearCGToString(ENonlinearCG tr)
Definition: ROL_Types.hpp:540
ENonlinearCG StringToENonlinearCG(std::string s)
Definition: ROL_Types.hpp:596
int isValidDescent(EDescent d)
Verifies validity of a Secant enum.
Definition: ROL_Types.hpp:334
std::string ELineSearchToString(ELineSearch ls)
Definition: ROL_Types.hpp:628
int isValidLineSearch(ELineSearch ls)
Verifies validity of a LineSearch enum.
Definition: ROL_Types.hpp:650
State for step class. Will be used for restarts.
Definition: ROL_Types.hpp:107
int isValidStep(EStep ls)
Verifies validity of a TrustRegion enum.
Definition: ROL_Types.hpp:188
ETestObjectives
Enumeration of test objective functions.
Definition: ROL_Types.hpp:850
Teuchos::RCP< Vector< Real > > minIterVec
Definition: ROL_Types.hpp:93
std::string EKrylovToString(EKrylov tr)
Definition: ROL_Types.hpp:461
Teuchos::RCP< Vector< Real > > constraintVec
Definition: ROL_Types.hpp:110
int isValidCurvatureCondition(ECurvatureCondition ls)
Verifies validity of a CurvatureCondition enum.
Definition: ROL_Types.hpp:729
ETrustRegion StringToETrustRegion(std::string s)
Definition: ROL_Types.hpp:831
ECurvatureCondition
Enumeration of line-search curvature conditions.
Definition: ROL_Types.hpp:699
std::string ETestObjectivesToString(ETestObjectives to)
Definition: ROL_Types.hpp:863
Teuchos::RCP< Vector< Real > > lagmultVec
Definition: ROL_Types.hpp:92
Teuchos::RCP< Vector< Real > > iterateVec
Definition: ROL_Types.hpp:91
ECurvatureCondition StringToECurvatureCondition(std::string s)
Definition: ROL_Types.hpp:759
ETrustRegion
Enumeration of trust-region solver types.
Definition: ROL_Types.hpp:777
std::string ETrustRegionToString(ETrustRegion tr)
Definition: ROL_Types.hpp:785
std::string ESecantToString(ESecant tr)
Definition: ROL_Types.hpp:390
std::string EStepToString(EStep tr)
Definition: ROL_Types.hpp:167
EStep
Enumeration of step types.
Definition: ROL_Types.hpp:156
static const double ROL_OVERFLOW
Platform-dependent maximum double.
Definition: ROL_Types.hpp:126
EConstraint
Enumeration of constraint types.
Definition: ROL_Types.hpp:1024
ETestOptProblem StringToETestOptProblem(std::string s)
Definition: ROL_Types.hpp:1007
int isValidNonlinearCG(ENonlinearCG s)
Verifies validity of a NonlinearCG enum.
Definition: ROL_Types.hpp:563
std::string EBoundAlgorithmToString(EBoundAlgorithm tr)
Definition: ROL_Types.hpp:242
EDescent
Enumeration of descent direction types.
Definition: ROL_Types.hpp:306
Teuchos::RCP< Vector< Real > > gradientVec
Definition: ROL_Types.hpp:108
static const double ROL_UNDERFLOW
Platform-dependent minimum double.
Definition: ROL_Types.hpp:130
static const double ROL_EPSILON
Platform-dependent machine epsilon.
Definition: ROL_Types.hpp:118