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_RCP.hpp>
62 #include <Teuchos_ScalarTraits.hpp>
63 #include <Teuchos_TestForException.hpp>
64 #include <ROL_Vector.hpp>
65 
69 #define ROL_NUM_CHECKDERIV_STEPS 13
70 
71 namespace ROL {
72 
75  template<class Real>
76  struct AlgorithmState {
77  int iter;
78  int minIter;
79  int nfval;
80  int ncval;
81  int ngrad;
82  Real value;
83  Real minValue;
84  Real gnorm;
85  Real cnorm;
86  Real snorm;
89  bool flag;
90  Teuchos::RCP<Vector<Real> > iterateVec;
91  Teuchos::RCP<Vector<Real> > lagmultVec;
92  Teuchos::RCP<Vector<Real> > minIterVec;
93  AlgorithmState(void) : iter(0), minIter(0), nfval(0), ngrad(0), value(0), minValue(0),
94  gnorm(std::numeric_limits<Real>::max()),
95  cnorm(std::numeric_limits<Real>::max()),
96  snorm(std::numeric_limits<Real>::max()),
97  aggregateGradientNorm(std::numeric_limits<Real>::max()),
98  aggregateModelError(std::numeric_limits<Real>::max()),
99  flag(false),
100  iterateVec(Teuchos::null), lagmultVec(Teuchos::null), minIterVec(Teuchos::null) {}
101  };
102 
105  template<class Real>
106  struct StepState {
107  Teuchos::RCP<Vector<Real> > gradientVec;
108  Teuchos::RCP<Vector<Real> > descentVec;
109  Real searchSize; // line search parameter (alpha) or trust-region radius (delta)
110  StepState(void) : gradientVec(Teuchos::null), descentVec(Teuchos::null), searchSize(0) {}
111  };
112 
115  static const double ROL_EPSILON = std::abs(Teuchos::ScalarTraits<double>::eps());
116 
119  static const double ROL_THRESHOLD = 10.0 * ROL_EPSILON;
120 
123  static const double ROL_OVERFLOW = std::abs(Teuchos::ScalarTraits<double>::rmax());
124 
127  static const double ROL_UNDERFLOW = std::abs(Teuchos::ScalarTraits<double>::rmin());
128 
130  bool operator()(char c) {
131  return (c ==' ' || c =='-' || c == '(' || c == ')' || c=='\'' || c=='\r' || c=='\n' || c=='\t');
132  }
133  };
134 
135  inline std::string removeStringFormat( std::string s ) {
136  std::string output = s;
137  output.erase( std::remove_if( output.begin(), output.end(), removeSpecialCharacters()), output.end() );
138  std::transform( output.begin(), output.end(), output.begin(), ::tolower );
139  return output;
140  }
141 
154  };
155 
156  inline std::string EBoundAlgorithmToString(EBoundAlgorithm tr) {
157  std::string retString;
158  switch(tr) {
159  case BOUNDALGORITHM_PROJECTED: retString = "Projected"; break;
160  case BOUNDALGORITHM_PRIMALDUALACTIVESET: retString = "Primal Dual Active Set"; break;
161  case BOUNDALGORITHM_INTERIORPOINTS: retString = "Interior Points"; break;
162  case BOUNDALGORITHM_LAST: retString = "Last Type (Dummy)"; break;
163  default: retString = "INVALID EBoundAlgorithm";
164  }
165  return retString;
166  }
167 
174  return( (d == BOUNDALGORITHM_PROJECTED) ||
177  );
178  }
179 
181  return type = static_cast<EBoundAlgorithm>(type+1);
182  }
183 
185  EBoundAlgorithm oldval = type;
186  ++type;
187  return oldval;
188  }
189 
191  return type = static_cast<EBoundAlgorithm>(type-1);
192  }
193 
195  EBoundAlgorithm oldval = type;
196  --type;
197  return oldval;
198  }
199 
200  inline EBoundAlgorithm StringToEBoundAlgorithm(std::string s) {
201  s = removeStringFormat(s);
202  for ( EBoundAlgorithm des = BOUNDALGORITHM_PROJECTED; des < BOUNDALGORITHM_LAST; des++ ) {
203  if ( !s.compare(removeStringFormat(EBoundAlgorithmToString(des))) ) {
204  return des;
205  }
206  }
208  }
209 
220  enum EDescent{
227  };
228 
229  inline std::string EDescentToString(EDescent tr) {
230  std::string retString;
231  switch(tr) {
232  case DESCENT_STEEPEST: retString = "Steepest Descent"; break;
233  case DESCENT_NONLINEARCG: retString = "Nonlinear CG"; break;
234  case DESCENT_SECANT: retString = "Quasi-Newton Method"; break;
235  case DESCENT_NEWTON: retString = "Newton's Method"; break;
236  case DESCENT_NEWTONKRYLOV: retString = "Newton-Krylov"; break;
237  case DESCENT_LAST: retString = "Last Type (Dummy)"; break;
238  default: retString = "INVALID ESecant";
239  }
240  return retString;
241  }
242 
248  inline int isValidDescent(EDescent d){
249  return( (d == DESCENT_STEEPEST) ||
250  (d == DESCENT_NONLINEARCG) ||
251  (d == DESCENT_SECANT) ||
252  (d == DESCENT_NEWTON) ||
253  (d == DESCENT_NEWTONKRYLOV)
254  );
255  }
256 
257  inline EDescent & operator++(EDescent &type) {
258  return type = static_cast<EDescent>(type+1);
259  }
260 
261  inline EDescent operator++(EDescent &type, int) {
262  EDescent oldval = type;
263  ++type;
264  return oldval;
265  }
266 
267  inline EDescent & operator--(EDescent &type) {
268  return type = static_cast<EDescent>(type-1);
269  }
270 
271  inline EDescent operator--(EDescent &type, int) {
272  EDescent oldval = type;
273  --type;
274  return oldval;
275  }
276 
277  inline EDescent StringToEDescent(std::string s) {
278  s = removeStringFormat(s);
279  for ( EDescent des = DESCENT_STEEPEST; des < DESCENT_LAST; des++ ) {
280  if ( !s.compare(removeStringFormat(EDescentToString(des))) ) {
281  return des;
282  }
283  }
284  return DESCENT_SECANT;
285  }
286 
295  enum ESecant{
302  };
303 
304  inline std::string ESecantToString(ESecant tr) {
305  std::string retString;
306  switch(tr) {
307  case SECANT_LBFGS: retString = "Limited-Memory BFGS"; break;
308  case SECANT_LDFP: retString = "Limited-Memory DFP"; break;
309  case SECANT_LSR1: retString = "Limited-Memory SR1"; break;
310  case SECANT_BARZILAIBORWEIN: retString = "Barzilai-Borwein"; break;
311  case SECANT_USERDEFINED: retString = "User-Defined"; break;
312  case SECANT_LAST: retString = "Last Type (Dummy)"; break;
313  default: retString = "INVALID ESecant";
314  }
315  return retString;
316  }
317 
323  inline int isValidSecant(ESecant s) {
324  return( (s == SECANT_LBFGS) ||
325  (s == SECANT_LDFP) ||
326  (s == SECANT_LSR1) ||
327  (s == SECANT_BARZILAIBORWEIN) ||
328  (s == SECANT_USERDEFINED)
329  );
330  }
331 
332  inline ESecant & operator++(ESecant &type) {
333  return type = static_cast<ESecant>(type+1);
334  }
335 
336  inline ESecant operator++(ESecant &type, int) {
337  ESecant oldval = type;
338  ++type;
339  return oldval;
340  }
341 
342  inline ESecant & operator--(ESecant &type) {
343  return type = static_cast<ESecant>(type-1);
344  }
345 
346  inline ESecant operator--(ESecant &type, int) {
347  ESecant oldval = type;
348  --type;
349  return oldval;
350  }
351 
352  inline ESecant StringToESecant(std::string s) {
353  s = removeStringFormat(s);
354  for ( ESecant sec = SECANT_LBFGS; sec < SECANT_LAST; sec++ ) {
355  if ( !s.compare(removeStringFormat(ESecantToString(sec))) ) {
356  return sec;
357  }
358  }
359  return SECANT_LBFGS;
360  }
361 
368  enum EKrylov{
372  };
373 
374  inline std::string EKrylovToString(EKrylov tr) {
375  std::string retString;
376  switch(tr) {
377  case KRYLOV_CG: retString = "Conjugate Gradients"; break;
378  case KRYLOV_CR: retString = "Conjugate Residuals"; break;
379  case KRYLOV_LAST: retString = "Last Type (Dummy)"; break;
380  default: retString = "INVALID EKrylov";
381  }
382  return retString;
383  }
384 
390  inline int isValidKrylov(EKrylov d){
391  return( (d == KRYLOV_CG) ||
392  (d == KRYLOV_CR) );
393  }
394 
395  inline EKrylov & operator++(EKrylov &type) {
396  return type = static_cast<EKrylov>(type+1);
397  }
398 
399  inline EKrylov operator++(EKrylov &type, int) {
400  EKrylov oldval = type;
401  ++type;
402  return oldval;
403  }
404 
405  inline EKrylov & operator--(EKrylov &type) {
406  return type = static_cast<EKrylov>(type-1);
407  }
408 
409  inline EKrylov operator--(EKrylov &type, int) {
410  EKrylov oldval = type;
411  --type;
412  return oldval;
413  }
414 
415  inline EKrylov StringToEKrylov(std::string s) {
416  s = removeStringFormat(s);
417  for ( EKrylov des = KRYLOV_CG; des < KRYLOV_LAST; des++ ) {
418  if ( !s.compare(removeStringFormat(EKrylovToString(des))) ) {
419  return des;
420  }
421  }
422  return KRYLOV_CG;
423  }
424 
449  };
450 
451  inline std::string ENonlinearCGToString(ENonlinearCG tr) {
452  std::string retString;
453  switch(tr) {
454  case NONLINEARCG_HESTENES_STIEFEL: retString = "Hestenes-Stiefel"; break;
455  case NONLINEARCG_FLETCHER_REEVES: retString = "Fletcher-Reeves"; break;
456  case NONLINEARCG_DANIEL: retString = "Daniel (uses Hessian)"; break;
457  case NONLINEARCG_POLAK_RIBIERE: retString = "Polak-Ribiere"; break;
458  case NONLINEARCG_FLETCHER_CONJDESC: retString = "Fletcher Conjugate Descent"; break;
459  case NONLINEARCG_LIU_STOREY: retString = "Liu-Storey"; break;
460  case NONLINEARCG_DAI_YUAN: retString = "Dai-Yuan"; break;
461  case NONLINEARCG_HAGAR_ZHANG: retString = "Hagar-Zhang"; break;
462  case NONLINEARCG_OREN_LUENBERGER: retString = "Oren-Luenberger"; break;
463  case NONLINEARCG_LAST: retString = "Last Type (Dummy)"; break;
464  default: retString = "INVALID ENonlinearCG";
465  }
466  return retString;
467  }
468 
475  return( (s == NONLINEARCG_HESTENES_STIEFEL) ||
477  (s == NONLINEARCG_DANIEL) ||
478  (s == NONLINEARCG_POLAK_RIBIERE) ||
480  (s == NONLINEARCG_LIU_STOREY) ||
481  (s == NONLINEARCG_DAI_YUAN) ||
482  (s == NONLINEARCG_HAGAR_ZHANG) ||
484  );
485  }
486 
488  return type = static_cast<ENonlinearCG>(type+1);
489  }
490 
491  inline ENonlinearCG operator++(ENonlinearCG &type, int) {
492  ENonlinearCG oldval = type;
493  ++type;
494  return oldval;
495  }
496 
498  return type = static_cast<ENonlinearCG>(type-1);
499  }
500 
501  inline ENonlinearCG operator--(ENonlinearCG &type, int) {
502  ENonlinearCG oldval = type;
503  --type;
504  return oldval;
505  }
506 
507  inline ENonlinearCG StringToENonlinearCG(std::string s) {
508  s = removeStringFormat(s);
509  for ( ENonlinearCG nlcg = NONLINEARCG_HESTENES_STIEFEL; nlcg < NONLINEARCG_LAST; nlcg++ ) {
510  if ( !s.compare(removeStringFormat(ENonlinearCGToString(nlcg))) ) {
511  return nlcg;
512  }
513  }
515  }
516 
537  };
538 
539  inline std::string ELineSearchToString(ELineSearch ls) {
540  std::string retString;
541  switch(ls) {
542  case LINESEARCH_ITERATIONSCALING: retString = "Iteration Scaling"; break;
543  case LINESEARCH_PATHBASEDTARGETLEVEL: retString = "Path-Based Target Level"; break;
544  case LINESEARCH_BACKTRACKING: retString = "Backtracking"; break;
545  case LINESEARCH_BISECTION: retString = "Bisection"; break;
546  case LINESEARCH_GOLDENSECTION: retString = "Golden Section"; break;
547  case LINESEARCH_CUBICINTERP: retString = "Cubic Interpolation"; break;
548  case LINESEARCH_BRENTS: retString = "Brents"; break;
549  case LINESEARCH_USERDEFINED: retString = "User Defined"; break;
550  case LINESEARCH_LAST: retString = "Last Type (Dummy)"; break;
551  default: retString = "INVALID ELineSearch";
552  }
553  return retString;
554  }
555 
562  return( (ls == LINESEARCH_BACKTRACKING) ||
563  (ls == LINESEARCH_ITERATIONSCALING) ||
565  (ls == LINESEARCH_BISECTION) ||
566  (ls == LINESEARCH_GOLDENSECTION) ||
567  (ls == LINESEARCH_CUBICINTERP) ||
568  (ls == LINESEARCH_BRENTS) ||
569  (ls == LINESEARCH_USERDEFINED)
570  );
571  }
572 
574  return type = static_cast<ELineSearch>(type+1);
575  }
576 
577  inline ELineSearch operator++(ELineSearch &type, int) {
578  ELineSearch oldval = type;
579  ++type;
580  return oldval;
581  }
582 
584  return type = static_cast<ELineSearch>(type-1);
585  }
586 
587  inline ELineSearch operator--(ELineSearch &type, int) {
588  ELineSearch oldval = type;
589  --type;
590  return oldval;
591  }
592 
593  inline ELineSearch StringToELineSearch(std::string s) {
594  s = removeStringFormat(s);
595  for ( ELineSearch ls = LINESEARCH_ITERATIONSCALING; ls < LINESEARCH_LAST; ls++ ) {
596  if ( !s.compare(removeStringFormat(ELineSearchToString(ls))) ) {
597  return ls;
598  }
599  }
601  }
602 
618  };
619 
621  std::string retString;
622  switch(ls) {
623  case CURVATURECONDITION_WOLFE: retString = "Wolfe Conditions"; break;
624  case CURVATURECONDITION_STRONGWOLFE: retString = "Strong Wolfe Conditions"; break;
625  case CURVATURECONDITION_GENERALIZEDWOLFE: retString = "Generalized Wolfe Conditions"; break;
626  case CURVATURECONDITION_APPROXIMATEWOLFE: retString = "Approximate Wolfe Conditions"; break;
627  case CURVATURECONDITION_GOLDSTEIN: retString = "Goldstein Conditions"; break;
628  case CURVATURECONDITION_NULL: retString = "Null Curvature Condition"; break;
629  case CURVATURECONDITION_LAST: retString = "Last Type (Dummy)"; break;
630  default: retString = "INVALID ECurvatureCondition";
631  }
632  return retString;
633  }
634 
641  return( (ls == CURVATURECONDITION_WOLFE) ||
647  );
648  }
649 
651  return type = static_cast<ECurvatureCondition>(type+1);
652  }
653 
655  ECurvatureCondition oldval = type;
656  ++type;
657  return oldval;
658  }
659 
661  return type = static_cast<ECurvatureCondition>(type-1);
662  }
663 
665  ECurvatureCondition oldval = type;
666  --type;
667  return oldval;
668  }
669 
671  s = removeStringFormat(s);
673  if ( !s.compare(removeStringFormat(ECurvatureConditionToString(cc))) ) {
674  return cc;
675  }
676  }
678  }
679 
694  };
695 
696  inline std::string ETrustRegionToString(ETrustRegion tr) {
697  std::string retString;
698  switch(tr) {
699  case TRUSTREGION_CAUCHYPOINT: retString = "Cauchy Point"; break;
700  case TRUSTREGION_TRUNCATEDCG: retString = "Truncated CG"; break;
701  case TRUSTREGION_DOGLEG: retString = "Dogleg"; break;
702  case TRUSTREGION_DOUBLEDOGLEG: retString = "Double Dogleg"; break;
703  case TRUSTREGION_LAST: retString = "Last Type (Dummy)"; break;
704  default: retString = "INVALID ETrustRegion";
705  }
706  return retString;
707  }
708 
715  return( (ls == TRUSTREGION_CAUCHYPOINT) ||
716  (ls == TRUSTREGION_TRUNCATEDCG) ||
717  (ls == TRUSTREGION_DOGLEG) ||
719  );
720  }
721 
723  return type = static_cast<ETrustRegion>(type+1);
724  }
725 
726  inline ETrustRegion operator++(ETrustRegion &type, int) {
727  ETrustRegion oldval = type;
728  ++type;
729  return oldval;
730  }
731 
733  return type = static_cast<ETrustRegion>(type-1);
734  }
735 
736  inline ETrustRegion operator--(ETrustRegion &type, int) {
737  ETrustRegion oldval = type;
738  --type;
739  return oldval;
740  }
741 
742  inline ETrustRegion StringToETrustRegion(std::string s) {
743  s = removeStringFormat(s);
744  for ( ETrustRegion tr = TRUSTREGION_CAUCHYPOINT; tr < TRUSTREGION_LAST; tr++ ) {
745  if ( !s.compare(removeStringFormat(ETrustRegionToString(tr))) ) {
746  return tr;
747  }
748  }
750  }
751 
772  };
773 
774  inline std::string ETestObjectivesToString(ETestObjectives to) {
775  std::string retString;
776  switch(to) {
777  case TESTOBJECTIVES_ROSENBROCK: retString = "Rosenbrock's Function"; break;
778  case TESTOBJECTIVES_FREUDENSTEINANDROTH: retString = "Freudenstein and Roth's Function"; break;
779  case TESTOBJECTIVES_BEALE: retString = "Beale's Function"; break;
780  case TESTOBJECTIVES_POWELL: retString = "Powell's Badly Scaled Function"; break;
781  case TESTOBJECTIVES_SUMOFSQUARES: retString = "Sum of Squares Function"; break;
782  case TESTOBJECTIVES_LEASTSQUARES: retString = "Least Squares Function"; break;
783  case TESTOBJECTIVES_POISSONCONTROL: retString = "Poisson Optimal Control"; break;
784  case TESTOBJECTIVES_POISSONINVERSION: retString = "Poisson Inversion Problem"; break;
785  case TESTOBJECTIVES_LAST: retString = "Last Type (Dummy)"; break;
786  default: retString = "INVALID ETestObjectives";
787  }
788  return retString;
789  }
790 
797  return( (to == TESTOBJECTIVES_ROSENBROCK) ||
799  (to == TESTOBJECTIVES_BEALE) ||
800  (to == TESTOBJECTIVES_POWELL) ||
801  (to == TESTOBJECTIVES_SUMOFSQUARES) ||
802  (to == TESTOBJECTIVES_LEASTSQUARES) ||
805  );
806  }
807 
809  return type = static_cast<ETestObjectives>(type+1);
810  }
811 
813  ETestObjectives oldval = type;
814  ++type;
815  return oldval;
816  }
817 
819  return type = static_cast<ETestObjectives>(type-1);
820  }
821 
823  ETestObjectives oldval = type;
824  --type;
825  return oldval;
826  }
827 
828  inline ETestObjectives StringToETestObjectives(std::string s) {
829  s = removeStringFormat(s);
831  if ( !s.compare(removeStringFormat(ETestObjectivesToString(to))) ) {
832  return to;
833  }
834  }
836  }
837 
859  };
860 
861  inline std::string ETestOptProblemToString(ETestOptProblem to) {
862  std::string retString;
863  switch(to) {
864  case TESTOPTPROBLEM_HS1: retString = "Hock and Schittkowski Test Problem #1"; break;
865  case TESTOPTPROBLEM_HS2: retString = "Hock and Schittkowski Test Problem #2"; break;
866  case TESTOPTPROBLEM_HS3: retString = "Hock and Schittkowski Test Problem #3"; break;
867  case TESTOPTPROBLEM_HS4: retString = "Hock and Schittkowski Test Problem #4"; break;
868  case TESTOPTPROBLEM_HS5: retString = "Hock and Schittkowski Test Problem #5"; break;
869  case TESTOPTPROBLEM_HS25: retString = "Hock and Schittkowski Test Problem #25"; break;
870  case TESTOPTPROBLEM_HS38: retString = "Hock and Schittkowski Test Problem #38"; break;
871  case TESTOPTPROBLEM_HS45: retString = "Hock and Schittkowski Test Problem #45"; break;
872  case TESTOPTPROBLEM_BVP: retString = "Boundary Value Problem"; break;
873  case TESTOPTPROBLEM_LAST: retString = "Last Type (Dummy)"; break;
874  default: retString = "INVALID ETestOptProblem";
875  }
876  return retString;
877  }
878 
885  return( (to == TESTOPTPROBLEM_HS1) ||
886  (to == TESTOPTPROBLEM_HS2) ||
887  (to == TESTOPTPROBLEM_HS3) ||
888  (to == TESTOPTPROBLEM_HS4) ||
889  (to == TESTOPTPROBLEM_HS5) ||
890  (to == TESTOPTPROBLEM_HS25) ||
891  (to == TESTOPTPROBLEM_HS38) ||
892  (to == TESTOPTPROBLEM_HS45) ||
893  (to == TESTOPTPROBLEM_BVP) );
894  }
895 
897  return type = static_cast<ETestOptProblem>(type+1);
898  }
899 
901  ETestOptProblem oldval = type;
902  ++type;
903  return oldval;
904  }
905 
907  return type = static_cast<ETestOptProblem>(type-1);
908  }
909 
911  ETestOptProblem oldval = type;
912  --type;
913  return oldval;
914  }
915 
916  inline ETestOptProblem StringToETestOptProblem(std::string s) {
917  s = removeStringFormat(s);
918  for ( ETestOptProblem to = TESTOPTPROBLEM_HS1; to < TESTOPTPROBLEM_LAST; to++ ) {
919  if ( !s.compare(removeStringFormat(ETestOptProblemToString(to))) ) {
920  return to;
921  }
922  }
923  return TESTOPTPROBLEM_HS1;
924  }
925 
926 
937  };
938 
939  inline std::string EConstraintToString(EConstraint c) {
940  std::string retString;
941  switch(c) {
942  case CONSTRAINT_EQUALITY: retString = "Equality"; break;
943  case CONSTRAINT_INEQUALITY: retString = "Inequality"; break;
944  case CONSTRAINT_LAST: retString = "Last Type (Dummy)"; break;
945  default: retString = "INVALID EConstraint";
946  }
947  return retString;
948  }
949 
956  return( (c == CONSTRAINT_EQUALITY) ||
957  (c == CONSTRAINT_INEQUALITY) );
958  }
959 
961  return type = static_cast<EConstraint>(type+1);
962  }
963 
964  inline EConstraint operator++(EConstraint &type, int) {
965  EConstraint oldval = type;
966  ++type;
967  return oldval;
968  }
969 
971  return type = static_cast<EConstraint>(type-1);
972  }
973 
974  inline EConstraint operator--(EConstraint &type, int) {
975  EConstraint oldval = type;
976  --type;
977  return oldval;
978  }
979 
980  inline EConstraint StringToEConstraint(std::string s) {
981  s = removeStringFormat(s);
982  for ( EConstraint ctype = CONSTRAINT_EQUALITY; ctype < CONSTRAINT_LAST; ctype++ ) {
983  if ( !s.compare(removeStringFormat(EConstraintToString(ctype))) ) {
984  return ctype;
985  }
986  }
987  return CONSTRAINT_EQUALITY;
988  }
989 
990  // For use in gradient and Hessian checks
991  namespace Finite_Difference_Arrays {
992 
993  // Finite difference steps in axpy form
994  const int shifts[4][4] = { { 1, 0, 0, 0 }, // First order
995  { -1, 2, 0, 0 }, // Second order
996  { -1, 2, 1, 0 }, // Third order
997  { -1, -1, 3, 1 } // Fourth order
998  };
999 
1000  // Finite difference weights
1001  const double weights[4][5] = { { -1.0, 1.0, 0.0, 0.0, 0.0 }, // First order
1002  { 0.0, -1.0/2.0, 1.0/2.0, 0.0, 0.0 }, // Second order
1003  { -1.0/2.0, -1.0/3.0, 1.0, -1.0/6.0, 0.0 }, // Third order
1004  { 0.0, -2.0/3.0, 1.0/12.0, 2.0/3.0, -1.0/12.0 } // Fourth order
1005  };
1006 
1007  }
1008 
1009 
1010 
1011 } // namespace ROL
1012 
1013 
1216 #endif
ETestOptProblem
Enumeration of test optimization problems.
Definition: ROL_Types.hpp:848
int isValidKrylov(EKrylov d)
Verifies validity of a Secant enum.
Definition: ROL_Types.hpp:390
int isValidConstraint(EConstraint c)
Verifies validity of a Secant enum.
Definition: ROL_Types.hpp:955
int isValidSecant(ESecant s)
Verifies validity of a Secant enum.
Definition: ROL_Types.hpp:323
const double weights[4][5]
Definition: ROL_Types.hpp:1001
ELineSearch StringToELineSearch(std::string s)
Definition: ROL_Types.hpp:593
EBoundAlgorithm StringToEBoundAlgorithm(std::string s)
Definition: ROL_Types.hpp:200
EBoundAlgorithm
Enumeration of algorithms to handle bound constraints.
Definition: ROL_Types.hpp:149
int isValidBoundAlgorithm(EBoundAlgorithm d)
Verifies validity of a Bound Algorithm enum.
Definition: ROL_Types.hpp:173
std::string removeStringFormat(std::string s)
Definition: ROL_Types.hpp:135
ELineSearch
Enumeration of line-search types.
Definition: ROL_Types.hpp:527
static const double ROL_THRESHOLD
Tolerance for various equality tests.
Definition: ROL_Types.hpp:119
EConstraint StringToEConstraint(std::string s)
Definition: ROL_Types.hpp:980
ESecant StringToESecant(std::string s)
Definition: ROL_Types.hpp:352
std::string EDescentToString(EDescent tr)
Definition: ROL_Types.hpp:229
EROLBurkardt & operator++(EROLBurkardt &type)
int isValidTestOptProblem(ETestOptProblem to)
Verifies validity of a TestOptProblem enum.
Definition: ROL_Types.hpp:884
Teuchos::RCP< Vector< Real > > descentVec
Definition: ROL_Types.hpp:108
EKrylov
Enumeration of Krylov methods.
Definition: ROL_Types.hpp:368
int isValidTestObjectives(ETestObjectives to)
Verifies validity of a TestObjectives enum.
Definition: ROL_Types.hpp:796
int isValidTrustRegion(ETrustRegion ls)
Verifies validity of a TrustRegion enum.
Definition: ROL_Types.hpp:714
EKrylov StringToEKrylov(std::string s)
Definition: ROL_Types.hpp:415
EDescent StringToEDescent(std::string s)
Definition: ROL_Types.hpp:277
State for algorithm class. Will be used for restarts.
Definition: ROL_Types.hpp:76
EBoundAlgorithm & operator--(EBoundAlgorithm &type)
Definition: ROL_Types.hpp:190
ENonlinearCG
Enumeration of nonlinear CG algorithms.
Definition: ROL_Types.hpp:438
ETestObjectives StringToETestObjectives(std::string s)
Definition: ROL_Types.hpp:828
std::string ECurvatureConditionToString(ECurvatureCondition ls)
Definition: ROL_Types.hpp:620
std::string EConstraintToString(EConstraint c)
Definition: ROL_Types.hpp:939
ESecant
Enumeration of secant update algorithms.
Definition: ROL_Types.hpp:295
std::string ETestOptProblemToString(ETestOptProblem to)
Definition: ROL_Types.hpp:861
std::string ENonlinearCGToString(ENonlinearCG tr)
Definition: ROL_Types.hpp:451
ENonlinearCG StringToENonlinearCG(std::string s)
Definition: ROL_Types.hpp:507
int isValidDescent(EDescent d)
Verifies validity of a Secant enum.
Definition: ROL_Types.hpp:248
std::string ELineSearchToString(ELineSearch ls)
Definition: ROL_Types.hpp:539
int isValidLineSearch(ELineSearch ls)
Verifies validity of a LineSearch enum.
Definition: ROL_Types.hpp:561
State for step class. Will be used for restarts.
Definition: ROL_Types.hpp:106
ETestObjectives
Enumeration of test objective functions.
Definition: ROL_Types.hpp:761
Teuchos::RCP< Vector< Real > > minIterVec
Definition: ROL_Types.hpp:92
std::string EKrylovToString(EKrylov tr)
Definition: ROL_Types.hpp:374
int isValidCurvatureCondition(ECurvatureCondition ls)
Verifies validity of a CurvatureCondition enum.
Definition: ROL_Types.hpp:640
ETrustRegion StringToETrustRegion(std::string s)
Definition: ROL_Types.hpp:742
ECurvatureCondition
Enumeration of line-search curvature conditions.
Definition: ROL_Types.hpp:610
std::string ETestObjectivesToString(ETestObjectives to)
Definition: ROL_Types.hpp:774
Teuchos::RCP< Vector< Real > > lagmultVec
Definition: ROL_Types.hpp:91
Teuchos::RCP< Vector< Real > > iterateVec
Definition: ROL_Types.hpp:90
ECurvatureCondition StringToECurvatureCondition(std::string s)
Definition: ROL_Types.hpp:670
ETrustRegion
Enumeration of trust-region solver types.
Definition: ROL_Types.hpp:688
std::string ETrustRegionToString(ETrustRegion tr)
Definition: ROL_Types.hpp:696
std::string ESecantToString(ESecant tr)
Definition: ROL_Types.hpp:304
static const double ROL_OVERFLOW
Platform-dependent maximum double.
Definition: ROL_Types.hpp:123
EConstraint
Enumeration of constraint types.
Definition: ROL_Types.hpp:933
ETestOptProblem StringToETestOptProblem(std::string s)
Definition: ROL_Types.hpp:916
int isValidNonlinearCG(ENonlinearCG s)
Verifies validity of a NonlinearCG enum.
Definition: ROL_Types.hpp:474
std::string EBoundAlgorithmToString(EBoundAlgorithm tr)
Definition: ROL_Types.hpp:156
EDescent
Enumeration of descent direction types.
Definition: ROL_Types.hpp:220
Teuchos::RCP< Vector< Real > > gradientVec
Definition: ROL_Types.hpp:107
static const double ROL_UNDERFLOW
Platform-dependent minimum double.
Definition: ROL_Types.hpp:127
static const double ROL_EPSILON
Platform-dependent machine epsilon.
Definition: ROL_Types.hpp:115