OptPDS.h

00001 #ifndef Optpds_h
00002 #define Optpds_h
00003 
00004 /*------------------------------------------------------------------------
00005  Copyright (c) 2001, Sandia Corporation 
00006  J.C. Meza, Sandia National Laboratories meza@california.sandia.gov
00007  ------------------------------------------------------------------------*/
00008 
00009 #ifdef HAVE_CONFIG_H
00010 #include "OPT++_config.h"
00011 #endif
00012 
00013 #ifdef HAVE_STD
00014 #include <cstdio>
00015 #else
00016 #include <stdio.h>
00017 #endif
00018 
00019 #include "Opt.h"
00020 #include "NLP0.h"
00021 #include "NLP.h"
00022 
00023 using std::ofstream;
00024 using std::ostream;
00025 
00026 namespace OPTPP {
00027 
00034 class OptDirect: public OptimizeClass {
00035  protected:
00036  public:
00037   OptDirect(){}
00038   OptDirect(int n): OptimizeClass(n){}
00039   OptDirect(int n, TOLS t): OptimizeClass(n,t){}
00040   virtual ~OptDirect(){}
00041   virtual void acceptStep(int, int) = 0;
00042   virtual void updateModel(int, int, NEWMAT::ColumnVector) = 0;
00043 
00044   virtual int checkConvg() {return 0;}
00045   virtual void optimize() {}
00046   virtual void readOptInput() {}
00047   virtual void reset() {}
00048 };
00049 
00050 //----------------------------------------------------------------------
00051 // Parallel Direct Search Method
00052 //----------------------------------------------------------------------
00053 
00069 class OptPDS: public OptDirect {
00070 
00071 protected:
00072   NLP0* nlp;                    
00073   NEWMAT::Matrix simplex;               
00074   NEWMAT::ColumnVector vscales; 
00075 
00076 
00077   int search_scheme_size;       
00078   int simplex_type;             
00079   int reset_param;
00080   double tr_size;               
00081   double simplex_size;
00082 
00083   bool create_scheme_flag, first, trpds;
00084   char schemefile_name[80];
00085 
00086 public:
00087   OptPDS(){}
00088   OptPDS(NLP0* p): OptDirect(p->getDim()), nlp(p),  
00089       simplex(p->getDim(),p->getDim()+1), vscales(p->getDim()),
00090       search_scheme_size(64), simplex_type(2), 
00091       reset_param(0), tr_size(0.0), simplex_size(0.0), create_scheme_flag(true),
00092       trpds(false) { strcpy(method,"PDS");
00093       strcpy(schemefile_name,"SCHEME");  vscales = 1.0; NEWMAT::ColumnVector x
00094                                                           = p->getXc();
00095       double perturb;
00096       for (int i=1; i <= p->getDim(); i++) {
00097         for (int j=1; j <= p->getDim()+1; j++) {
00098           simplex(i,j) = x(i);
00099         }
00100       }
00101       for (int i=1; i<= p->getDim(); i++) {
00102         perturb = x(i)*.01;
00103         simplex(i,i+1) = x(i) + perturb;
00104       }
00105   }
00106   
00107   OptPDS(NLP0* p, TOLS t): OptDirect(p->getDim(), t), nlp(p),  
00108       simplex(p->getDim(),p->getDim()+1), vscales(p->getDim()),
00109       search_scheme_size(64), simplex_type(2),
00110       reset_param(0), tr_size(0.0), simplex_size(0.0), create_scheme_flag(true),
00111       trpds(false) { strcpy(method,"PDS");
00112       strcpy(schemefile_name,"SCHEME"); vscales = 1.0; NEWMAT::ColumnVector x
00113                                                          = p->getXc();
00114       double perturb;
00115       for (int i=1; i <= p->getDim(); i++) {
00116         for (int j=1; j <= p->getDim()+1; j++) {
00117           simplex(i,j) = x(i);
00118         }
00119       }
00120       for (int i=1; i<=p->getDim(); i++) {
00121         perturb = x(i)*.01;
00122         simplex(i,i+1) = x(i) + perturb;
00123       }
00124   }
00125 
00126   virtual ~OptPDS(){}
00127   virtual NEWMAT::ColumnVector computeSearch(NEWMAT::SymmetricMatrix& ) 
00128       {return NEWMAT::ColumnVector();}
00129 
00130   virtual void acceptStep(int k, int step_type)
00131     {defaultAcceptStep(k, step_type);}
00132 
00133   virtual void updateModel(int k, int ndim, NEWMAT::ColumnVector x)
00134     {OptimizeClass::defaultUpdateModel(k, ndim, x);}
00135 
00136   virtual void reset() 
00137     {int ndim = nlp->getDim(); OptimizeClass::defaultReset(ndim);}
00138 
00139 //-------------------------------------------------------------------------
00140 // Accessor Methods
00141 //-------------------------------------------------------------------------
00142 
00144   void setSSS(int s)                 {search_scheme_size = s;}
00145 
00147   void setSimplexType(int t)         {simplex_type = t;}
00148 
00150   void setScale(NEWMAT::ColumnVector x)      {vscales = x;};
00151 
00153   void setSimplex(NEWMAT::Matrix &m)         {simplex = m;};
00154 
00155   void setCreateFlag(bool flag=true) {create_scheme_flag = flag;};
00156 
00158   void setSchemeFileName(char *s)    {strcpy(schemefile_name,s);};
00159 
00161   void setTRSize(double tr=0)        {tr_size = tr;}
00162 
00164   void setSimplexSize(double len)    {simplex_size = len;}
00165 
00167   void setNonIter(bool init=false)   {first = init;}
00168   void setTRPDS(bool trcon=false)   {trpds = trcon;}
00169 
00170   int getSimplexType()      const {return simplex_type;}
00171   int getSSS()              const {return search_scheme_size;}
00172   NEWMAT::ColumnVector& getScale()  {return vscales;};
00173   bool getCreateFlag()      const {return create_scheme_flag;};
00174   char *getSchemeFileName() {return schemefile_name;};
00175   double getTRSize()        {return tr_size;}
00176   double getSimplexSize()   {return simplex_size;}
00177   bool getNonIter()         {return first;}
00178   bool getMethod()          {return trpds;}
00179 
00180 // These are defined elsewhere
00181 
00182   void initOpt();               
00183   void optimize();              
00184   void readOptInput();          
00185   int checkConvg();     
00186   void printStatus(char *);     
00187 };
00188 
00189 int pdsinit(NLP0 *, ostream *, int, int, int *, int *, double,
00190             double *, double *, double *, int *, double *, double *,
00191             double *, double *, double *, char *, double, int, int,
00192             double);
00193 
00194 int pdsopt(NLP0 *, ostream *, double *, int *, int, char *, int, int,
00195            double, int, int, double, double *, double, int, double *,
00196            int *, char *, double, double, double *, int, int, int,
00197            double);
00198 
00199 int pdswork(NLP0 *, ostream *, ofstream *, int, double, int, int, int *, 
00200             double, int, double *, double *, int *, double *, double *,
00201             int *, int, double, double *, char *, double, double, int,
00202             int, int, double, FILE *);
00203 
00204 int pdschk(NLP0 *,int, double *, double *, double, double *, int, double);  
00205 
00206 } // namespace OPTPP
00207 #endif
Generated on Mon Jan 24 12:04:37 2011 for FASTlib by  doxygen 1.6.3