OptCG.h

00001 #ifndef OptCG_h
00002 #define OptCG_h
00003 
00004 /*----------------------------------------------------------------------
00005   Copyright (c) 2001, Sandia Corporation.
00006   J.C. Meza, Sandia National Laboratories, meza@ca.sandia.gov
00007  ----------------------------------------------------------------------*/
00008 
00009 #ifndef Opt_h
00010 #include "Opt.h"
00011 #endif
00012 
00013 namespace OPTPP {
00014 
00025 class OptCGLike: public OptimizeClass {
00026  protected:
00027   virtual NLP1 *nlprob() const = 0;
00029   NEWMAT::ColumnVector gprev;           
00031   int grad_evals;               
00033   SearchStrategy strategy;      
00034 
00035  public:
00041   OptCGLike(){}
00046   OptCGLike(int n): OptimizeClass(n), 
00047                     gprev(n), grad_evals(0), strategy(LineSearch){}
00053   OptCGLike(int n, TOLS t): OptimizeClass(n,t),
00054                             gprev(n),grad_evals(0), strategy(LineSearch){}
00055 
00059   virtual ~OptCGLike(){}
00060 
00062   void setSearchStrategy(SearchStrategy s) {strategy = s;}
00063 
00067   SearchStrategy getSearchStrategy() const {return strategy;}
00068 
00069   virtual void acceptStep(int, int) = 0;
00070   virtual int checkConvg();
00071   virtual int checkDeriv();
00072   virtual void optimize() {} 
00073   virtual void readOptInput() {}
00074   virtual void updateModel(int, int, NEWMAT::ColumnVector) = 0;
00075 
00076 };
00077 
00088 class OptCG: public OptCGLike {
00089 private:
00090   NLP1* nlp;    
00091   
00092 protected:
00096   NLP1* nlprob() const { return nlp; }
00097 
00098 public:
00104   OptCG(){strcpy(method,"Nonlinear CG");}
00109   OptCG(NLP1* p): OptCGLike(p->getDim()),nlp(p)
00110     {strcpy(method,"Nonlinear CG");}
00116   OptCG(NLP1* p, TOLS t): OptCGLike(p->getDim(), t),nlp(p)
00117     {strcpy(method,"Nonlinear CG");}
00118 
00122   virtual ~OptCG(){}
00123 
00124   virtual NEWMAT::ColumnVector computeSearch(NEWMAT::SymmetricMatrix& ) 
00125     {return NEWMAT::ColumnVector();}
00126 
00127   virtual void acceptStep(int k, int step_type)
00128     {OptimizeClass::defaultAcceptStep(k, step_type);}
00129 
00130   virtual void updateModel(int k, int ndim, NEWMAT::ColumnVector x)
00131     {OptimizeClass::defaultUpdateModel(k, ndim, x);}
00132 
00133 // These are defined elsewhere
00135   virtual int checkDeriv();
00137   virtual int computeStep(NEWMAT::ColumnVector sk);
00139   virtual void reset();
00141   virtual void initOpt();
00143   virtual void optimize();
00145   virtual real stepTolNorm() const;
00147   virtual void printStatus(char *);
00148 };
00149 
00150 } // namespace OPTPP
00151 #endif
Generated on Mon Jan 24 12:04:37 2011 for FASTlib by  doxygen 1.6.3