1 #ifndef Optpds_h 2 #define Optpds_h 3 4 /*------------------------------------------------------------------------ 5 Copyright (c) 2001, Sandia Corporation 6 J.C. Meza, Sandia National Laboratories meza@california.sandia.gov 7 ------------------------------------------------------------------------*/ 8 9 #ifdef HAVE_CONFIG_H 10 #include "OPT++_config.h" 11 #endif 12 13 #ifdef HAVE_STD 14 #include <cstdio> 15 #else 16 #include <stdio.h> 17 #endif 18 19 #include "Opt.h" 20 #include "NLP0.h" 21 #include "NLP.h" 22 #include "Teuchos_SerialDenseMatrix.hpp" 23 #include "Teuchos_SerialDenseVector.hpp" 24 #include "Teuchos_SerialSymDenseMatrix.hpp" 25 26 namespace OPTPP { 27 28 /** 29 * OptDirect is a derived class of OptimizeClass and the base class for direct 30 * search methods. In OPT++, OptGA, a genetic algorithm, and OptPDS, 31 * a parallel direct search method, are examples of direct search methods. 32 */ 33 34 class OptDirect: public OptimizeClass { 35 protected: 36 public: OptDirect()37 OptDirect(){} OptDirect(int n)38 OptDirect(int n): OptimizeClass(n){} OptDirect(int n,TOLS t)39 OptDirect(int n, TOLS t): OptimizeClass(n,t){} ~OptDirect()40 virtual ~OptDirect(){} 41 virtual void acceptStep(int, int) = 0; 42 virtual void updateModel(int, int, Teuchos::SerialDenseVector<int,double>) = 0; 43 checkConvg()44 virtual int checkConvg() {return 0;} optimize()45 virtual void optimize() {} readOptInput()46 virtual void readOptInput() {} reset()47 virtual void reset() {} 48 }; 49 50 //---------------------------------------------------------------------- 51 // Parallel Direct Search Method 52 //---------------------------------------------------------------------- 53 54 /** 55 * OptPDS is an implementation of a derivative-free algorithm for 56 * unconstrained optimization. The search direction is driven solely 57 * by the function information. OptPDS is easy to implement on parallel 58 * machines. A special feature of this approach is the ease with which 59 * algorithms can be generated to take advantage of any number of 60 * processors and to addapt to any cost ratio of communication to function 61 * evaluation. 62 * 63 * For a further description of the parallel direct search methods see 64 * J. E. Dennis, Jr. and Virginia Torczon, "Direct Search Methods on 65 * Parallel Machines," SIAM J. Optimization, Vol. 1, No. 4, 66 * pp. 448--474, November 1991. 67 */ 68 69 class OptPDS: public OptDirect { 70 71 protected: 72 NLP0* nlp; ///< Pointer to an NLP0 object 73 Teuchos::SerialDenseMatrix<int,double> simplex; ///< Convex hull of dimension+1 points 74 Teuchos::SerialDenseVector<int,double> vscales; ///< Vector of scale factors to multiply vertices 75 76 77 int search_scheme_size; ///< Number of points used in search scheme 78 int simplex_type; ///< Type of simplex chosen by the user 79 int reset_param; 80 double tr_size; ///< Trust-region radius 81 double simplex_size; 82 83 bool create_scheme_flag, first, trpds; 84 char schemefile_name[80]; 85 86 public: OptPDS()87 OptPDS(){} OptPDS(NLP0 * p)88 OptPDS(NLP0* p): OptDirect(p->getDim()), nlp(p), 89 simplex(p->getDim(),p->getDim()+1), vscales(p->getDim()), 90 search_scheme_size(64), simplex_type(2), 91 reset_param(0), tr_size(0.0), simplex_size(0.0), create_scheme_flag(true), 92 trpds(false) { strcpy(method,"PDS"); 93 strcpy(schemefile_name,"SCHEME"); vscales = 1.0; Teuchos::SerialDenseVector<int,double> x 94 = p->getXc(); 95 double perturb; 96 for (int i=0; i<p->getDim(); i++) { 97 for (int j=0; j<p->getDim()+1; j++) { 98 simplex(i,j) = x(i); 99 } 100 } 101 for (int i=0; i<p->getDim(); i++) { 102 perturb = x(i)*.01; 103 simplex(i,i+1) = x(i) + perturb; 104 } 105 } 106 OptPDS(NLP0 * p,TOLS t)107 OptPDS(NLP0* p, TOLS t): OptDirect(p->getDim(), t), nlp(p), 108 simplex(p->getDim(),p->getDim()+1), vscales(p->getDim()), 109 search_scheme_size(64), simplex_type(2), 110 reset_param(0), tr_size(0.0), simplex_size(0.0), create_scheme_flag(true), 111 trpds(false) { strcpy(method,"PDS"); 112 strcpy(schemefile_name,"SCHEME"); vscales = 1.0; Teuchos::SerialDenseVector<int,double> x 113 = p->getXc(); 114 double perturb; 115 for (int i=0; i<p->getDim(); i++) { 116 for (int j=0; j<p->getDim()+1; j++) { 117 simplex(i,j) = x(i); 118 } 119 } 120 for (int i=0; i<p->getDim(); i++) { 121 perturb = x(i)*.01; 122 simplex(i,i+1) = x(i) + perturb; 123 } 124 } 125 ~OptPDS()126 virtual ~OptPDS(){} computeSearch(Teuchos::SerialSymDenseMatrix<int,double> &)127 virtual Teuchos::SerialDenseVector<int,double> computeSearch(Teuchos::SerialSymDenseMatrix<int,double>& ) 128 {return Teuchos::SerialDenseVector<int,double>();} 129 acceptStep(int k,int step_type)130 virtual void acceptStep(int k, int step_type) 131 {defaultAcceptStep(k, step_type);} 132 updateModel(int k,int ndim,Teuchos::SerialDenseVector<int,double> x)133 virtual void updateModel(int k, int ndim, Teuchos::SerialDenseVector<int,double> x) 134 {OptimizeClass::defaultUpdateModel(k, ndim, x);} 135 reset()136 virtual void reset() 137 {int ndim = nlp->getDim(); OptimizeClass::defaultReset(ndim);} 138 139 //------------------------------------------------------------------------- 140 // Accessor Methods 141 //------------------------------------------------------------------------- 142 143 /// Set number of points in the search scheme setSSS(int s)144 void setSSS(int s) {search_scheme_size = s;} 145 146 /// Set type of simplex used by the algorithm setSimplexType(int t)147 void setSimplexType(int t) {simplex_type = t;} 148 149 /// Set vertex scale factor setScale(Teuchos::SerialDenseVector<int,double> x)150 void setScale(Teuchos::SerialDenseVector<int,double> x) {vscales = x;}; 151 152 /// Set simplex used by the algorithm setSimplex(Teuchos::SerialDenseMatrix<int,double> & m)153 void setSimplex(Teuchos::SerialDenseMatrix<int,double> &m) {simplex = m;}; 154 155 void setCreateFlag(bool flag=true) {create_scheme_flag = flag;}; 156 157 /// Override the default value of filename setSchemeFileName(char * s)158 void setSchemeFileName(char *s) {strcpy(schemefile_name,s);}; 159 160 /// Set trust-region size 161 void setTRSize(double tr=0) {tr_size = tr;} 162 163 /// Set simplex size setSimplexSize(double len)164 void setSimplexSize(double len) {simplex_size = len;} 165 166 /// Set first nonlinear iteration to either true or false 167 void setNonIter(bool init=false) {first = init;} 168 void setTRPDS(bool trcon=false) {trpds = trcon;} 169 getSimplexType()170 int getSimplexType() const {return simplex_type;} getSSS()171 int getSSS() const {return search_scheme_size;} getScale()172 Teuchos::SerialDenseVector<int,double>& getScale() {return vscales;}; getCreateFlag()173 bool getCreateFlag() const {return create_scheme_flag;}; getSchemeFileName()174 char *getSchemeFileName() {return schemefile_name;}; getTRSize()175 double getTRSize() {return tr_size;} getSimplexSize()176 double getSimplexSize() {return simplex_size;} getNonIter()177 bool getNonIter() {return first;} getMethod()178 bool getMethod() {return trpds;} 179 180 // These are defined elsewhere 181 182 void initOpt(); ///< Initialize algorithmic parameters 183 void optimize(); ///< Call the optimization method 184 void readOptInput(); ///< Read user-specificed input options 185 int checkConvg(); ///< Check to see if algorithm satisfies conv. criteria 186 void printStatus(char *); ///< Print status of PDS method 187 }; 188 189 int pdsinit(NLP0 *, std::ostream *, int, int, int *, int *, double, 190 double *, double *, double *, int *, double *, double *, 191 double *, double *, double *, char *, double, int, int, 192 double); 193 194 int pdsopt(NLP0 *, std::ostream *, double *, int *, int, char *, int, int, 195 double, int, int, double, double *, double, int, double *, 196 int *, char *, double, double, double *, int, int, int, 197 double); 198 199 int pdswork(NLP0 *, std::ostream *, std::ofstream *, int, double, int, int, int *, 200 double, int, double *, double *, int *, double *, double *, 201 int *, int, double, double *, char *, double, double, int, 202 int, int, double, std::FILE *); 203 204 int pdschk(NLP0 *,int, double *, double *, double, double *, int, double); 205 206 } // namespace OPTPP 207 #endif 208