ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-2.0/src/minimizers/OOPSEMinimizer.hpp
(Generate patch)

Comparing branches/new_design/OOPSE-2.0/src/minimizers/OOPSEMinimizer.hpp (file contents):
Revision 1883 by tim, Thu Dec 2 05:14:58 2004 UTC vs.
Revision 1884 by tim, Tue Dec 14 19:08:44 2004 UTC

# Line 1 | Line 1
1 < #ifndef _OOPSEMINIMIZER_H_
2 < #define _OOPSEMINIMIZER_H_
1 > /*
2 > * Copyright (C) 2000-2004  Object Oriented Parallel Simulation Engine (OOPSE) project
3 > *
4 > * Contact: oopse@oopse.org
5 > *
6 > * This program is free software; you can redistribute it and/or
7 > * modify it under the terms of the GNU Lesser General Public License
8 > * as published by the Free Software Foundation; either version 2.1
9 > * of the License, or (at your option) any later version.
10 > * All we ask is that proper credit is given for our work, which includes
11 > * - but is not limited to - adding the above copyright notice to the beginning
12 > * of your source code files, and to any copyright notice that you may distribute
13 > * with programs based on this work.
14 > *
15 > * This program is distributed in the hope that it will be useful,
16 > * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 > * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 > * GNU Lesser General Public License for more details.
19 > *
20 > * You should have received a copy of the GNU Lesser General Public License
21 > * along with this program; if not, write to the Free Software
22 > * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23 > *
24 > */
25  
26 + #ifndef MINIMIZERS_OOPSEMINIMIZER_HPP
27 + #define MINIMIZERS_OOPSEMINIMIZER_HPP
28 +
29   #include <iostream>
30  
31   #include "integrators/Integrator.hpp"
# Line 9 | Line 34 | const int MIN_LSERROR = -1;
34  
35  
36  
37 +
38 + // base class of minimizer
39 +
40 + namespace oopse {
41 +
42 + /** @todo need refactorying */
43   const int MIN_LSERROR = -1;
44   const int MIN_MAXITER = 0;
45   const int MIN_CONVERGE = 1;
# Line 22 | Line 53 | const int LS_ERROR  = -1;
53   const int LS_SUCCEED =1;
54   const int LS_ERROR  = -1;
55  
25 // base class of minimizer
56  
57 < class OOPSEMinimizer : public RealIntegrator{
58 <  public:
57 > class OOPSEMinimizer {
58 >    public:
59  
60 <    OOPSEMinimizer(SimInfo *theInfo, ForceFields* the_ff,
31 <                                     MinimizerParameterSet* param);
60 >        OOPSEMinimizer(SimInfo *theInfo, MinimizerParameterSet* param);
61  
62 <    virtual ~OOPSEMinimizer();
62 >        virtual ~OOPSEMinimizer();
63  
64 <    //
65 <    virtual void init() {}
37 <    
38 <    //driver function of minimization method
39 <    virtual void minimize();
64 >        //
65 >        virtual void init() {}
66  
67 <    //
68 <    virtual int step() = 0;
67 >        //driver function of minimization method
68 >        virtual void minimize();
69  
70 <    //
71 <    virtual void prepareStep() {};
70 >        //
71 >        virtual int step() = 0;
72  
73 <    //line search algorithm, for the time being, we use back track algorithm
74 <    virtual int doLineSearch(vector<double>& direction, double stepSize);
73 >        //
74 >        virtual void prepareStep() {};
75  
76 <    virtual int checkConvg() = 0;
76 >        //line search algorithm, for the time being, we use back track algorithm
77 >        virtual int doLineSearch(std::vector<double>& direction, double stepSize);
78  
79 <    //print detail information of the minimization method
53 <    virtual void printMinimizerInfo();
54 <    
55 <    //save the result when minimization method is done
56 <    virtual void saveResult(){}
79 >        virtual int checkConvg() = 0;
80  
81 <    //write out the trajectory
82 <    virtual void writeOut(vector<double>&x, double curIter);
81 >        //print detail information of the minimization method
82 >        virtual void printMinimizerInfo();
83  
84 +        //save the result when minimization method is done
85 +        virtual void saveResult(){}
86  
87 <    //get the status of minimization
88 <    int getMinStatus() {return minStatus;}
87 >        //write out the trajectory
88 >        virtual void writeOut(std::vector<double>&x, double curIter);
89  
65    // get the dimension of the model
66    int getDim() {  return ndim;  }
90  
91 <    //get the name of minimizer method
92 <     std::string getMinimizerName() {  return minimizerName;  }
91 >        //get the status of minimization
92 >        int getMinStatus() {return minStatus;}
93  
94 <    //return number of  current Iteration  
95 <    int getCurIter() {  return curIter;  }
94 >        // get the dimension of the model
95 >        int getDim() {  return ndim;  }
96  
97 <    // set the verbose mode of minimizer
98 <    void setVerbose(bool verbose) {  bVerbose = verbose;}
97 >        //get the name of minimizer method
98 >        std::string getMinimizerName() {  return minimizerName;  }
99  
100 <    //get and set the coordinate
101 <     std::vector<double> getX() {  return curX;  }
79 <    void setX(vector<double>& x);
100 >        //return number of  current Iteration  
101 >        int getCurIter() {  return curIter;  }
102  
103 <     //get and set the value of object function
104 <    double getF() {  return curF;  }
83 <    void setF(double f)  { curF = f;  }
103 >        // set the verbose mode of minimizer
104 >        void setVerbose(bool verbose) {  bVerbose = verbose;}
105  
106 <     std::vector<double> getG() {  return curG;  }
107 <    void setG(vector<double>& g);
108 <    
88 <    //get and set the gradient
89 <     std::vector<double> getGrad() {  return curG;  }
90 <    void setGrad(vector<double>& g) {  curG = g;  }
106 >        //get and set the coordinate
107 >        std::vector<double> getX() {  return curX;  }
108 >        void setX(std::vector<double>& x);
109  
110 <    //interal function to evaluate the energy and gradient in OOPSE
111 <    void calcEnergyGradient(vector<double>& x,  std::vector<double>& grad, double&
112 <                                                 energy, int& status);
110 >        //get and set the value of object function
111 >        double getF() {  return curF;  }
112 >        void setF(double f)  { curF = f;  }
113  
114 <    //calculate the value of object function
115 <    virtual void calcF();
98 <    virtual void calcF(vector<double>& x, double&f, int& status);
114 >        std::vector<double> getG() {  return curG;  }
115 >        void setG(std::vector<double>& g);
116  
117 <    //calculate the gradient
118 <    virtual void calcG();
119 <    virtual void calcG(vector<double>& x,  std::vector<double>& g, double& f, int& status);
117 >        //get and set the gradient
118 >        std::vector<double> getGrad() {  return curG;  }
119 >        void setGrad(std::vector<double>& g) {  curG = g;  }
120  
121 <    //calculate the hessian
122 <    //virtual void calcH(int& status);
123 <    //virtual void calcH(vector<double>& x,  std::vector<dobule>& g, SymMatrix& h, int& status);
121 >        //interal function to evaluate the energy and gradient in OOPSE
122 >        void calcEnergyGradient(vector<double>& x,  std::vector<double>& grad, double&
123 >                                                 energy, int& status);
124  
125 +        //calculate the value of object function
126 +        virtual void calcF();
127 +        virtual void calcF(std::vector<double>& x, double&f, int& status);
128  
129 <  protected:
129 >        //calculate the gradient
130 >        virtual void calcG();
131 >        virtual void calcG(std::vector<double>& x,  std::vector<double>& g, double& f, int& status);
132  
133 <    // transfrom cartesian and rotational coordinates into minimization coordinates
134 <     std::vector<double> getCoor();
135 <    
114 <    // transfrom minimization coordinates into cartesian and rotational coordinates  
115 <    void setCoor(vector<double>& x);
133 >        //calculate the hessian
134 >        //virtual void calcH(int& status);
135 >        //virtual void calcH(vector<double>& x,  std::vector<dobule>& g, SymMatrix& h, int& status);
136  
117    //flag of turning on shake algorithm
118    bool bShake;
137  
138 <    //constraint the bonds;
121 <    int shakeR();
122 <    
123 <    //remove the force component along the bond direction
124 <    int shakeF();
125 <  
126 <    // dimension of the model
127 <    int ndim;
138 >    protected:
139  
140 <    //name of the minimizer
141 <     std::string minimizerName;
140 >        // transfrom cartesian and rotational coordinates into minimization coordinates
141 >        std::vector<double> getCoor();
142  
143 <    // current iteration number
144 <    int curIter;
134 <    //status of minimization
135 <    int minStatus;
143 >        // transfrom minimization coordinates into cartesian and rotational coordinates  
144 >        void setCoor(std::vector<double>& x);
145  
146 <    //flag of verbose mode
147 <    bool bVerbose;
146 >        //flag of turning on shake algorithm
147 >        bool bShake;
148  
149 +        //constraint the bonds;
150 +        int shakeR();
151  
152 <    //parameter set of minimization method
153 <    MinimizerParameterSet* paramSet;
152 >        //remove the force component along the bond direction
153 >        int shakeF();
154  
144    //status of energy and gradient evaluation
145    int egEvalStatus;
155  
156 <    //initial coordinates
157 <    //vector<double> initX;
158 <    
159 <    //current value  of the function
151 <    double curF;
152 <    // current coordinates
153 <     std::vector<double> curX;
154 <    //gradient at curent coordinates
155 <     std::vector<double> curG;
156 >        SimInfo* info;
157 >        
158 >        //parameter set of minimization method
159 >        MinimizerParameterSet* paramSet;
160  
161 <    //hessian at current coordinates
162 <    //SymMatrix curH;
161 >        // dimension of the model
162 >        int ndim;
163  
164 <  private:
164 >        //name of the minimizer
165 >        std::string minimizerName;
166  
167 <    //calculate the dimension od the model for minimization
168 <    void calcDim();
167 >        // current iteration number
168 >        int curIter;
169 >        //status of minimization
170 >        int minStatus;
171  
172 < };
172 >        //flag of verbose mode
173 >        bool bVerbose;
174  
167 // steepest descent minimizer
168 class SDMinimizer : public OOPSEMinimizer{
169  public:
170    SDMinimizer(SimInfo *theInfo, ForceFields* the_ff,
171                             MinimizerParameterSet* param);
175  
176 <    virtual void init();    
177 <    virtual int step();
175 <    virtual void prepareStep();
176 <    virtual int checkConvg();
177 <  protected:
176 >        //status of energy and gradient evaluation
177 >        int egEvalStatus;
178  
179 <     std::vector<double> direction;
180 <    double prevF;
181 <    double stepSize;
179 >        //initial coordinates
180 >        //vector<double> initX;
181  
182 < };
182 >        //current value  of the function
183 >        double curF;
184 >        // current coordinates
185 >        std::vector<double> curX;
186 >        //gradient at curent coordinates
187 >        std::vector<double> curG;
188  
189 < // conjugate gradient famlily minimzier
190 < class CGFamilyMinmizer : public OOPSEMinimizer{
187 <  public:
188 <    CGFamilyMinmizer(SimInfo *theInfo, ForceFields* the_ff,
189 <                                          MinimizerParameterSet* param);
189 >        //hessian at current coordinates
190 >        //SymMatrix curH;
191  
192 <    //check the convergence
192 <    virtual int checkConvg();
192 >    private:
193  
194 <    
195 <  protected:
194 >        //calculate the dimension od the model for minimization
195 >        void calcDim();
196  
197     std::vector<double> direction;
198     std::vector<double> prevX;
199     std::vector<double> prevG;
200    double prevF;
201    double stepSize;
197   };
198  
199 < //Polak-Ribiere  Conjugate Gradient Method
205 < class PRCGMinimizer : public CGFamilyMinmizer{
206 <  public:
207 <      PRCGMinimizer(SimInfo *theInfo, ForceFields* the_ff,  
208 <                                    MinimizerParameterSet* param)
209 <                                   :CGFamilyMinmizer(theInfo, the_ff, param) {}
210 <    virtual int step();
211 <    virtual void init();
212 <    virtual void prepareStep();
213 < };
214 <
199 > }
200   #endif
201 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines