00001 #ifndef OptGSS_h
00002 #define OptGSS_h
00003
00004
00005
00006
00007
00014 #ifdef HAVE_CONFIG_H
00015 #include "OPT++_config.h"
00016 #endif
00017
00018 #ifdef WITH_MPI
00019 #include "mpi.h"
00020 #endif
00021
00022 #include "OptDirect.h"
00023 #include "GenSet.h"
00024 #include "Opt_PARAMS.h"
00025
00026 using std::cerr;
00027
00028 namespace OPTPP {
00029
00030 class OptGSS : public OptDirect {
00031
00032 protected:
00033
00034 NLP0* nlp;
00036
00037 NLP1* nlp1;
00039
00040 NEWMAT::ColumnVector X;
00042
00043 double fX;
00045
00046 NEWMAT::ColumnVector gX;
00048
00049 double fprev;
00051
00052 double Delta;
00054
00055 double Phi;
00057
00058 double Theta;
00060
00061 double Delta_tol;
00063
00064 int Iter_max;
00066
00067 bool SearchAll;
00069
00070 bool computeGrad;
00072
00073 GenSetBase* gset;
00075
00076 NEWMAT::Matrix extras;
00078
00079 bool extras_srched;
00081
00082 bool printCOPYRIGHT;
00084
00085 void printHeader();
00087
00088 bool printXiter;
00090
00091 bool printGiter;
00093
00094 int mpi_rank;
00095
00096 #ifdef WITH_MPI
00097 int mpi_size;
00098
00099 void setpid() {
00100
00101 MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
00102 MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
00103
00104
00105
00106 }
00107 #endif
00108
00109 public:
00110
00111 void setParams();
00113
00114 void setParams(OptGSS_params op);
00116
00117
00118
00119
00120
00121 OptGSS() : nlp(0), nlp1(0), gset(0)
00122 { strcpy(method, "Generating Set Search"); setParams(); }
00123
00128 OptGSS(NLP0* p, GenSetBase* g) : nlp(p), nlp1(0), gset(g)
00129 { strcpy(method, "Generating Set Search with an NLP0"); setParams(); }
00130
00135 OptGSS(NLP1* p, GenSetBase* g) : nlp(p), nlp1(p), gset(g)
00136 { strcpy(method, "Generating Set Search with an NLP1"); setParams(); }
00137
00143 OptGSS(NLP0* p, GenSetBase* g, NEWMAT::Matrix& M) :
00144 nlp(p), nlp1(0), gset(g), extras(M)
00145 {
00146 strcpy(method, "Generating Set Search with an NLP0 & extra directions");
00147 setParams();
00148 }
00149
00155 OptGSS(NLP1* p, GenSetBase* g, NEWMAT::Matrix& M) :
00156 nlp(p), nlp1(p), Delta(0.0), computeGrad(true), gset(g), extras(M) {
00157 strcpy(method, "Generating Set Search with an NLP1 & extra directions");
00158 setParams();
00159 }
00160
00161
00162
00168 OptGSS(NLP0* p, GenSetBase* g, OptGSS_params op) : nlp(p), nlp1(0), gset(g)
00169 { strcpy(method, "Generating Set Search with an NLP0"); setParams(op); }
00170
00176 OptGSS(NLP1* p, GenSetBase* g, OptGSS_params op) : nlp(p), nlp1(p), gset(g)
00177 { strcpy(method, "Generating Set Search with an NLP1"); setParams(op); }
00178
00185 OptGSS(NLP0* p, GenSetBase* g, NEWMAT::Matrix& M, OptGSS_params op) :
00186 nlp(p), nlp1(0), gset(g), extras(M)
00187 {
00188 strcpy(method, "Generating Set Search with an NLP0 & extra directions");
00189 setParams(op);
00190 }
00191
00198 OptGSS(NLP1* p, GenSetBase* g, NEWMAT::Matrix& M, OptGSS_params op) :
00199 nlp(p), nlp1(p), Delta(0.0), computeGrad(true), gset(g), extras(M) {
00200 strcpy(method, "Generating Set Search with an NLP1 & extra directions");
00201 setParams(op);
00202 }
00203
00204
00205
00206
00207 ~OptGSS(){;}
00208
00209
00210
00211
00212
00216 void setStepSize(double s) {Delta = s;}
00217
00221 void setStepTol(double s) {Delta_tol = s;}
00222
00226 void setStepInc(double s) {
00227 if (s>1) {Phi = s; return;}
00228 cerr << "Step increment factor must exceed 1.0\n";
00229 }
00230
00234 void setStepDec(double s) {
00235 if (0<s && s<1) {Theta = s; return;}
00236 cerr << "Step decrement factor must be in interval (0,1)\n";
00237 }
00238
00242 void setMaxIter(int s) { Iter_max = s;}
00243
00247 void setFullSearch(bool s) { SearchAll = s;}
00248
00249 bool extras_searched() { return extras_srched; }
00250
00251 void setPrintX(bool s) {printXiter = s;}
00252 void setPrintG(bool s) {printGiter = s;}
00253 void printCopyright(bool doit) { printCOPYRIGHT = doit; }
00254
00255 void setComputeGrad(bool s) {computeGrad = s;}
00256
00257
00258
00259
00260
00261
00265 void expandStep() { Delta *= Phi;}
00266
00270 void contractStep() { Delta *= Theta; }
00271
00275 void updateX(double& newfX, NEWMAT::ColumnVector& newX) {
00276 fX = newfX;
00277 X << newX;
00278 }
00279
00283 bool StopCondition() { return Delta_tol > Delta;}
00284 int StepCondition();
00285
00289 int search();
00290
00291
00292
00293
00294
00298 virtual void reset();
00299
00300
00301
00302
00303
00304
00305 virtual void initOpt();
00306 virtual void optimize();
00307 virtual int checkConvg();
00308 int checkConvg_fcn();
00309 int checkConvg_grad();
00310
00311 #ifdef DAKOTA_OPTPP
00312 virtual void printStatus(char * msg) { printStatus(msg, true);}
00313 #else
00314 virtual void printStatus(char * msg) { printStatus(msg, false);}
00316 #endif
00317
00318 void printStatus(char * msg, bool printXc);
00320
00321
00322
00323
00324 NEWMAT::ColumnVector computeSearch(NEWMAT::SymmetricMatrix& )
00325 {return NEWMAT::ColumnVector();}
00326
00327 virtual void acceptStep(int k, int step_type)
00328 {OptimizeClass::defaultAcceptStep(k, step_type);}
00329
00330 virtual void updateModel(int k, int ndim, NEWMAT::ColumnVector x)
00331 {OptimizeClass::defaultUpdateModel(k, ndim, x);}
00332
00333 virtual void readOptInput() {;}
00334
00335 void printIter(int iter, int bp);
00336
00337 #ifdef WITH_MPI
00338 int getMPIRank() { return mpi_rank; }
00339 int getMPISize() { return mpi_size; }
00340
00341 #endif
00342
00343 };
00344
00345 }
00346 #endif