LSQNLF.h

00001 #ifndef LSQNLF_h
00002 #define LSQNLF_h
00003 /*----------------------------------------------------------------------
00004  Copyright (c) 2001, Sandia Corporation.   Under the terms of Contract 
00005  DE-AC04-94AL85000, there is a non-exclusive license for use of this 
00006  work by or on behalf of the U.S. Government.
00007 
00008  J. C. Meza, Sandia National Laboratories, meza@ca.sandia.gov
00009  ----------------------------------------------------------------------*/
00010 
00011 #ifdef HAVE_CONFIG_H
00012 #include "OPT++_config.h"
00013 #endif
00014 
00015 #include "NLP2.h"
00016 
00017 extern "C" {
00018   double get_cpu_time();
00019   double get_wall_clock_time();
00020 }
00021 
00022 namespace OPTPP {
00023 
00024 typedef void (*INITFCN)(int, NEWMAT::ColumnVector&);
00025 
00026 typedef CompoundConstraint* (*INITCONFCN)(int);
00027 
00028 typedef void (*USERFCNLSQ0)(int, const NEWMAT::ColumnVector&, 
00029   NEWMAT::ColumnVector&, int&);
00030 
00031 typedef void (*USERFCNLSQ0V)(int, const NEWMAT::ColumnVector&, 
00032   NEWMAT::ColumnVector&, int&, void* v);
00033 
00034 typedef void (*USERFCNLSQ1)(int, int, const NEWMAT::ColumnVector&, 
00035   NEWMAT::ColumnVector&, NEWMAT::Matrix&, int&);
00036 
00037 typedef void (*USERFCNLSQ1V)(int, int, const NEWMAT::ColumnVector&, 
00038   NEWMAT::ColumnVector&, NEWMAT::Matrix&, int&, void* v);
00039 
00040 typedef void (*USERNLNCON0)(int, const NEWMAT::ColumnVector&, 
00041   NEWMAT::ColumnVector&, int&);
00042 
00043 typedef void (*USERNLNCON1)(int, int, const NEWMAT::ColumnVector&, 
00044   NEWMAT::ColumnVector&, NEWMAT::Matrix&, int&);
00045 
00046 typedef void (*USERNLNCON2)(int, int, const NEWMAT::ColumnVector&, 
00047   NEWMAT::ColumnVector&, NEWMAT::Matrix&, 
00048   OptppArray<NEWMAT::SymmetricMatrix>&, int&);
00049 
00050 
00060 class LSQNLF: public NLP2 {
00061 
00062 protected:
00063   USERFCNLSQ0  fcn0;            
00064   USERFCNLSQ0V fcn0_v;          
00065   USERFCNLSQ1  fcn1;            
00066   USERFCNLSQ1V fcn1_v;          
00067   USERNLNCON1 confcn;           
00068   INITFCN init_fcn;             
00069   INITCONFCN init_confcn;       
00070   bool init_flag;               
00071   bool Jacobian_current;        
00072   int lsqterms_;                
00073   NEWMAT::ColumnVector fvector; 
00074   NEWMAT::Matrix Jacobian_;     
00075   NEWMAT::Matrix partial_jac;
00076   void* vptr;                   
00077 
00078   static void f0_helper(int n, const NEWMAT::ColumnVector& xc, NEWMAT::ColumnVector& f, 
00079          int& result, void *v) 
00080         {LSQNLF *o = (LSQNLF*)v; (*o->fcn0)(n,xc,f,result);}
00081   static void f1_helper(int m, int n, const NEWMAT::ColumnVector& xc, 
00082          NEWMAT::ColumnVector& f, NEWMAT::Matrix& g, int& result, void *v) 
00083         {LSQNLF *o = (LSQNLF*)v; (*o->fcn1)(m,n,xc,f,g,result);}
00084 
00085 private:
00086   NEWMAT::ColumnVector tempF;   
00087   NEWMAT::ColumnVector specLSQF;
00088 
00089 public:
00090   // Constructor
00091 
00092 #ifdef WITH_MPI
00093 
00094   LSQNLF(): 
00095      NLP2(){;}
00096   LSQNLF(int ndim, int lsqterms): 
00097     NLP2(ndim), fcn0(0), fcn0_v(0), fcn1(0), fcn1_v(0), confcn(0),
00098     init_fcn(0), init_confcn(0), init_flag(false), Jacobian_current(false), 
00099     lsqterms_(lsqterms), fvector(lsqterms), 
00100     Jacobian_(lsqterms,ndim), partial_jac(lsqterms,ndim), vptr(this),
00101     tempF(lsqterms), specLSQF(lsqterms)
00102      {
00103          fvector = 1.0e30;  Jacobian_ = 1.0e30; tempF = 1.0e30;
00104          SpecFlag = Spec1;
00105      }
00106   LSQNLF(int ndim, int lsqterms, USERFCNLSQ0 f, INITFCN i, 
00107           CompoundConstraint* constraint = 0): 
00108     NLP2(ndim, constraint), fcn0(f), fcn0_v(f0_helper), fcn1(0), fcn1_v(0), 
00109     confcn(0), init_fcn(i), init_confcn(0), init_flag(false), 
00110     Jacobian_current(false), lsqterms_(lsqterms), fvector(lsqterms),
00111     Jacobian_(lsqterms,ndim), partial_jac(lsqterms,ndim), vptr(this),
00112     tempF(lsqterms), specLSQF(lsqterms)
00113     { 
00114         fvector = 1.0e30;  Jacobian_ = 1.0e30; tempF = 1.0e30;
00115         SpecFlag = Spec1;
00116     }
00117   LSQNLF(int ndim, int lsqterms, USERFCNLSQ1 f, INITFCN i, 
00118           CompoundConstraint* constraint = 0): 
00119     NLP2(ndim, constraint), fcn0(0), fcn0_v(0), fcn1(f), fcn1_v(f1_helper), 
00120     confcn(0), init_fcn(i), init_confcn(0), init_flag(false), 
00121     Jacobian_current(false), lsqterms_(lsqterms), fvector(lsqterms),
00122     Jacobian_(lsqterms,ndim), partial_jac(lsqterms,ndim), vptr(this),
00123     tempF(lsqterms), specLSQF(lsqterms)
00124     { 
00125         fvector = 1.0e30;  Jacobian_ = 1.0e30; tempF = 1.0e30;
00126         SpecFlag = Spec1;
00127     }
00128   LSQNLF(int ndim, int lsqterms, USERFCNLSQ0 f, INITFCN i, INITCONFCN c): 
00129     NLP2(ndim), fcn0(f), fcn0_v(f0_helper), fcn1(0), fcn1_v(0), 
00130     confcn(0), init_fcn(i), init_confcn(c), init_flag(false), 
00131     Jacobian_current(false), lsqterms_(lsqterms), fvector(lsqterms),
00132     Jacobian_(lsqterms,ndim), partial_jac(lsqterms,ndim), vptr(this),
00133     tempF(lsqterms), specLSQF(lsqterms)
00134     { 
00135         fvector = 1.0e30;  Jacobian_ = 1.0e30; tempF = 1.0e30;
00136         SpecFlag = Spec1;
00137     }
00138   LSQNLF(int ndim, int lsqterms, USERFCNLSQ1 f, INITFCN i, INITCONFCN c): 
00139     NLP2(ndim), fcn0(0), fcn0_v(0), fcn1(f), fcn1_v(f1_helper), 
00140     confcn(0), init_fcn(i), init_confcn(c), init_flag(false), 
00141     Jacobian_current(false), lsqterms_(lsqterms), fvector(lsqterms),
00142     Jacobian_(lsqterms,ndim), partial_jac(lsqterms,ndim), vptr(this),
00143     tempF(lsqterms), specLSQF(lsqterms)
00144     { 
00145         fvector = 1.0e30;  Jacobian_ = 1.0e30; tempF = 1.0e30;
00146         SpecFlag = Spec1;
00147     }
00149   LSQNLF(int ndim, int lsqterms, USERFCNLSQ0V f, INITFCN i, INITCONFCN c, void* v): 
00150     NLP2(ndim), fcn0(0), fcn0_v(f), fcn1(0), fcn1_v(0), 
00151     confcn(0), init_fcn(i), init_confcn(c), init_flag(false), 
00152     Jacobian_current(false), lsqterms_(lsqterms), fvector(lsqterms),
00153     Jacobian_(lsqterms,ndim), partial_jac(lsqterms,ndim), vptr(v),
00154     tempF(lsqterms), specLSQF(lsqterms)
00155     { 
00156         fvector = 1.0e30;  Jacobian_ = 1.0e30; tempF = 1.0e30;
00157         SpecFlag = Spec1;
00158     }
00159   LSQNLF(int ndim, int lsqterms, USERFCNLSQ1V f, INITFCN i, INITCONFCN c, void* v): 
00160     NLP2(ndim), fcn0(0), fcn0_v(0), fcn1(0), fcn1_v(f), 
00161     confcn(0), init_fcn(i), init_confcn(c), init_flag(false), 
00162     Jacobian_current(false), lsqterms_(lsqterms), fvector(lsqterms),
00163     Jacobian_(lsqterms,ndim), partial_jac(lsqterms,ndim), vptr(v),
00164     tempF(lsqterms), specLSQF(lsqterms)
00165     { 
00166         fvector = 1.0e30;  Jacobian_ = 1.0e30; tempF = 1.0e30;
00167         SpecFlag = Spec1;
00168     }
00169 
00170 #else
00171 
00172   LSQNLF(): 
00173      NLP2(){;}
00174   LSQNLF(int ndim, int lsqterms): 
00175     NLP2(ndim), fcn0(0), fcn0_v(0), fcn1(0), fcn1_v(0), confcn(0),
00176     init_fcn(0), init_confcn(0), init_flag(false), Jacobian_current(false), 
00177     lsqterms_(lsqterms), fvector(lsqterms), 
00178     Jacobian_(lsqterms,ndim), partial_jac(lsqterms,ndim), vptr(this),
00179     tempF(lsqterms), specLSQF(lsqterms)
00180      {
00181          fvector = 1.0e30;  Jacobian_ = 1.0e30; tempF = 1.0e30;
00182          SpecFlag = NoSpec;
00183      }
00184   LSQNLF(int ndim, int lsqterms, USERFCNLSQ0 f, INITFCN i, 
00185           CompoundConstraint* constraint = 0): 
00186     NLP2(ndim, constraint), fcn0(f), fcn0_v(f0_helper), fcn1(0), fcn1_v(0), 
00187     confcn(0), init_fcn(i), init_confcn(0), init_flag(false), 
00188     Jacobian_current(false), lsqterms_(lsqterms), fvector(lsqterms),
00189     Jacobian_(lsqterms,ndim), partial_jac(lsqterms,ndim), vptr(this),
00190     tempF(lsqterms), specLSQF(lsqterms)
00191     { 
00192         fvector = 1.0e30;  Jacobian_ = 1.0e30; tempF = 1.0e30;
00193         SpecFlag = NoSpec;
00194     }
00195   LSQNLF(int ndim, int lsqterms, USERFCNLSQ1 f, INITFCN i, 
00196           CompoundConstraint* constraint = 0): 
00197     NLP2(ndim, constraint), fcn0(0), fcn0_v(0), fcn1(f), fcn1_v(f1_helper), 
00198     confcn(0), init_fcn(i), init_confcn(0), init_flag(false), 
00199     Jacobian_current(false), lsqterms_(lsqterms), fvector(lsqterms),
00200     Jacobian_(lsqterms,ndim), partial_jac(lsqterms,ndim), vptr(this),
00201     tempF(lsqterms), specLSQF(lsqterms)
00202     { 
00203         fvector = 1.0e30;  Jacobian_ = 1.0e30; tempF = 1.0e30;
00204         SpecFlag = NoSpec;
00205     }
00206   LSQNLF(int ndim, int lsqterms, USERFCNLSQ0 f, INITFCN i, INITCONFCN c): 
00207     NLP2(ndim), fcn0(f), fcn0_v(f0_helper), fcn1(0), fcn1_v(0), 
00208     confcn(0), init_fcn(i), init_confcn(c), init_flag(false), 
00209     Jacobian_current(false), lsqterms_(lsqterms), fvector(lsqterms),
00210     Jacobian_(lsqterms,ndim), partial_jac(lsqterms,ndim), vptr(this),
00211     tempF(lsqterms), specLSQF(lsqterms)
00212     { 
00213         fvector = 1.0e30;  Jacobian_ = 1.0e30; tempF = 1.0e30;
00214         SpecFlag = NoSpec;
00215     }
00216   LSQNLF(int ndim, int lsqterms, USERFCNLSQ1 f, INITFCN i, INITCONFCN c): 
00217     NLP2(ndim), fcn0(0), fcn0_v(0), fcn1(f), fcn1_v(f1_helper), 
00218     confcn(0), init_fcn(i), init_confcn(c), init_flag(false), 
00219     Jacobian_current(false), lsqterms_(lsqterms), fvector(lsqterms),
00220     Jacobian_(lsqterms,ndim), partial_jac(lsqterms,ndim), vptr(this),
00221     tempF(lsqterms), specLSQF(lsqterms)
00222     { 
00223         fvector = 1.0e30;  Jacobian_ = 1.0e30; tempF = 1.0e30;
00224         SpecFlag = NoSpec;
00225     }
00227   LSQNLF(int ndim, int lsqterms, USERFCNLSQ0V f, INITFCN i, INITCONFCN c, void* v): 
00228     NLP2(ndim), fcn0(0), fcn0_v(f), fcn1(0), fcn1_v(0), 
00229     confcn(0), init_fcn(i), init_confcn(c), init_flag(false), 
00230     Jacobian_current(false), lsqterms_(lsqterms), fvector(lsqterms),
00231     Jacobian_(lsqterms,ndim), partial_jac(lsqterms,ndim), vptr(v),
00232     tempF(lsqterms), specLSQF(lsqterms)
00233     { 
00234         fvector = 1.0e30;  Jacobian_ = 1.0e30; tempF = 1.0e30;
00235         SpecFlag = NoSpec;
00236     }
00237   LSQNLF(int ndim, int lsqterms, USERFCNLSQ1V f, INITFCN i, INITCONFCN c, void* v): 
00238     NLP2(ndim), fcn0(0), fcn0_v(0), fcn1(0), fcn1_v(f), 
00239     confcn(0), init_fcn(i), init_confcn(c), init_flag(false), 
00240     Jacobian_current(false), lsqterms_(lsqterms), fvector(lsqterms),
00241     Jacobian_(lsqterms,ndim), partial_jac(lsqterms,ndim), vptr(v),
00242     tempF(lsqterms), specLSQF(lsqterms)
00243     { 
00244         fvector = 1.0e30;  Jacobian_ = 1.0e30; tempF = 1.0e30;
00245         SpecFlag = NoSpec;
00246     }
00247 
00248 #endif
00249 
00250   // Destructor
00251   virtual ~LSQNLF() {;}                     
00252 
00253   void setFcnResidual(NEWMAT::ColumnVector& f) {tempF = f;}
00254   NEWMAT::ColumnVector getFcnResidual() const {return tempF;}
00255 
00257   virtual void reset();          
00259   virtual void initFcn();          
00261   virtual void eval();            
00263   virtual real evalF();                                 
00265   virtual real evalF(const NEWMAT::ColumnVector& x);            
00267   virtual NEWMAT::ColumnVector evalG();                         
00269   virtual NEWMAT::ColumnVector evalG(const NEWMAT::ColumnVector& x);    
00271   virtual NEWMAT::SymmetricMatrix evalH();                      
00272 
00274   virtual real evalLagrangian(const NEWMAT::ColumnVector& x, 
00275     NEWMAT::ColumnVector& mult, const NEWMAT::ColumnVector& type) ;
00277   virtual NEWMAT::ColumnVector evalLagrangianGradient(const NEWMAT::ColumnVector& x, const NEWMAT::ColumnVector& mult, const NEWMAT::ColumnVector& type) ;
00278 
00280   virtual NEWMAT::ColumnVector evalCF(const NEWMAT::ColumnVector& x);   
00282   virtual NEWMAT::Matrix evalCG(const NEWMAT::ColumnVector& x);         
00283 private:
00285   virtual NEWMAT::SymmetricMatrix evalH(NEWMAT::ColumnVector& x);       
00287   virtual NEWMAT::SymmetricMatrix evalCH(NEWMAT::ColumnVector &x);      
00288   virtual OptppArray<NEWMAT::SymmetricMatrix> evalCH(NEWMAT::ColumnVector &x,
00289     int darg);
00290   virtual void evalC(const NEWMAT::ColumnVector& x);    
00291 
00293   NEWMAT::Matrix LSQFDJac(const NEWMAT::ColumnVector& sx, 
00294     const NEWMAT::ColumnVector& xc, NEWMAT::ColumnVector& fx, 
00295     NEWMAT::Matrix& partial_jac);
00297   NEWMAT::Matrix LSQBDJac(const NEWMAT::ColumnVector& sx, 
00298     const NEWMAT::ColumnVector& xc, NEWMAT::ColumnVector& fx, 
00299     NEWMAT::Matrix& partial_jac);
00301   NEWMAT::Matrix LSQCDJac(const NEWMAT::ColumnVector& sx, 
00302     const NEWMAT::ColumnVector& xc, NEWMAT::ColumnVector& fx, 
00303     NEWMAT::Matrix& partial_jac);
00304 };
00305 
00306 } // namespace OPTPP
00307 #endif
Generated on Mon Jan 24 12:04:37 2011 for FASTlib by  doxygen 1.6.3