| 1 |
< |
/* |
| 1 |
> |
/* |
| 2 |
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
| 3 |
|
* |
| 4 |
|
* The University of Notre Dame grants you ("Licensee") a |
| 39 |
|
* such damages. |
| 40 |
|
*/ |
| 41 |
|
|
| 42 |
< |
#ifndef MINIMIZERS_OOPSEMINIMIZER_HPP |
| 42 |
> |
#ifndef MINIMIZERS_OOPSEMINIMIZER_HPP |
| 43 |
|
#define MINIMIZERS_OOPSEMINIMIZER_HPP |
| 44 |
|
|
| 45 |
|
#include <iostream> |
| 53 |
|
|
| 54 |
|
namespace oopse { |
| 55 |
|
|
| 56 |
< |
/** @todo need refactorying */ |
| 57 |
< |
const int MIN_LSERROR = -1; |
| 58 |
< |
const int MIN_MAXITER = 0; |
| 59 |
< |
const int MIN_CONVERGE = 1; |
| 56 |
> |
/** @todo need refactorying */ |
| 57 |
> |
const int MIN_LSERROR = -1; |
| 58 |
> |
const int MIN_MAXITER = 0; |
| 59 |
> |
const int MIN_CONVERGE = 1; |
| 60 |
|
|
| 61 |
< |
const int CONVG_UNCONVG = 0; |
| 62 |
< |
const int CONVG_FTOL = 1; |
| 63 |
< |
const int CONVG_GTOL = 2; |
| 64 |
< |
const int CONVG_ABSGTOL = 3; |
| 65 |
< |
const int CONVG_STEPTOL = 4; |
| 61 |
> |
const int CONVG_UNCONVG = 0; |
| 62 |
> |
const int CONVG_FTOL = 1; |
| 63 |
> |
const int CONVG_GTOL = 2; |
| 64 |
> |
const int CONVG_ABSGTOL = 3; |
| 65 |
> |
const int CONVG_STEPTOL = 4; |
| 66 |
|
|
| 67 |
< |
const int LS_SUCCEED =1; |
| 68 |
< |
const int LS_ERROR = -1; |
| 67 |
> |
const int LS_SUCCEED =1; |
| 68 |
> |
const int LS_ERROR = -1; |
| 69 |
|
|
| 70 |
< |
/** @todo move to math module */ |
| 71 |
< |
double dotProduct(const std::vector<double>& v1, const std::vector<double>& v2); |
| 70 |
> |
/** @todo move to math module */ |
| 71 |
> |
double dotProduct(const std::vector<double>& v1, const std::vector<double>& v2); |
| 72 |
|
|
| 73 |
< |
/** |
| 74 |
< |
* @class Minimizer |
| 75 |
< |
* base minimizer class |
| 76 |
< |
*/ |
| 77 |
< |
class Minimizer { |
| 78 |
< |
public: |
| 73 |
> |
/** |
| 74 |
> |
* @class Minimizer |
| 75 |
> |
* base minimizer class |
| 76 |
> |
*/ |
| 77 |
> |
class Minimizer { |
| 78 |
> |
public: |
| 79 |
|
|
| 80 |
< |
Minimizer(SimInfo *rhs); |
| 80 |
> |
Minimizer(SimInfo *rhs); |
| 81 |
|
|
| 82 |
< |
virtual ~Minimizer(); |
| 82 |
> |
virtual ~Minimizer(); |
| 83 |
|
|
| 84 |
< |
// |
| 85 |
< |
virtual void init() {} |
| 84 |
> |
// |
| 85 |
> |
virtual void init() {} |
| 86 |
|
|
| 87 |
< |
//driver function of minimization method |
| 88 |
< |
virtual void minimize(); |
| 87 |
> |
//driver function of minimization method |
| 88 |
> |
virtual void minimize(); |
| 89 |
|
|
| 90 |
< |
// |
| 91 |
< |
virtual int step() = 0; |
| 90 |
> |
// |
| 91 |
> |
virtual int step() = 0; |
| 92 |
|
|
| 93 |
< |
// |
| 94 |
< |
virtual void prepareStep() {}; |
| 93 |
> |
// |
| 94 |
> |
virtual void prepareStep() {}; |
| 95 |
|
|
| 96 |
< |
//line search algorithm, for the time being, we use back track algorithm |
| 97 |
< |
virtual int doLineSearch(std::vector<double>& direction, double stepSize); |
| 96 |
> |
//line search algorithm, for the time being, we use back track algorithm |
| 97 |
> |
virtual int doLineSearch(std::vector<double>& direction, double stepSize); |
| 98 |
|
|
| 99 |
< |
virtual int checkConvg() = 0; |
| 99 |
> |
virtual int checkConvg() = 0; |
| 100 |
|
|
| 101 |
< |
//save the result when minimization method is done |
| 102 |
< |
virtual void saveResult(){} |
| 101 |
> |
//save the result when minimization method is done |
| 102 |
> |
virtual void saveResult(){} |
| 103 |
|
|
| 104 |
< |
//get the status of minimization |
| 105 |
< |
int getMinStatus() {return minStatus;} |
| 104 |
> |
//get the status of minimization |
| 105 |
> |
int getMinStatus() {return minStatus;} |
| 106 |
|
|
| 107 |
< |
// get the dimension of the model |
| 108 |
< |
int getDim() { return ndim; } |
| 107 |
> |
// get the dimension of the model |
| 108 |
> |
int getDim() { return ndim; } |
| 109 |
|
|
| 110 |
< |
//get the name of minimizer method |
| 111 |
< |
std::string getMinimizerName() { return minimizerName; } |
| 110 |
> |
//get the name of minimizer method |
| 111 |
> |
std::string getMinimizerName() { return minimizerName; } |
| 112 |
|
|
| 113 |
< |
//return number of current Iteration |
| 114 |
< |
int getCurIter() { return curIter; } |
| 113 |
> |
//return number of current Iteration |
| 114 |
> |
int getCurIter() { return curIter; } |
| 115 |
|
|
| 116 |
< |
// set the verbose mode of minimizer |
| 117 |
< |
void setVerbose(bool verbose) { bVerbose = verbose;} |
| 116 |
> |
// set the verbose mode of minimizer |
| 117 |
> |
void setVerbose(bool verbose) { bVerbose = verbose;} |
| 118 |
|
|
| 119 |
< |
//get and set the coordinate |
| 120 |
< |
std::vector<double> getX() { return curX; } |
| 121 |
< |
void setX(std::vector<double>& x); |
| 119 |
> |
//get and set the coordinate |
| 120 |
> |
std::vector<double> getX() { return curX; } |
| 121 |
> |
void setX(std::vector<double>& x); |
| 122 |
|
|
| 123 |
< |
//get and set the value of object function |
| 124 |
< |
double getF() { return curF; } |
| 125 |
< |
void setF(double f) { curF = f; } |
| 123 |
> |
//get and set the value of object function |
| 124 |
> |
double getF() { return curF; } |
| 125 |
> |
void setF(double f) { curF = f; } |
| 126 |
|
|
| 127 |
< |
std::vector<double> getG() { return curG; } |
| 128 |
< |
void setG(std::vector<double>& g); |
| 127 |
> |
std::vector<double> getG() { return curG; } |
| 128 |
> |
void setG(std::vector<double>& g); |
| 129 |
|
|
| 130 |
< |
//get and set the gradient |
| 131 |
< |
std::vector<double> getGrad() { return curG; } |
| 132 |
< |
void setGrad(std::vector<double>& g) { curG = g; } |
| 130 |
> |
//get and set the gradient |
| 131 |
> |
std::vector<double> getGrad() { return curG; } |
| 132 |
> |
void setGrad(std::vector<double>& g) { curG = g; } |
| 133 |
|
|
| 134 |
< |
//interal function to evaluate the energy and gradient in OOPSE |
| 135 |
< |
void calcEnergyGradient(std::vector<double>& x, std::vector<double>& grad, double& |
| 136 |
< |
energy, int& status); |
| 134 |
> |
//interal function to evaluate the energy and gradient in OOPSE |
| 135 |
> |
void calcEnergyGradient(std::vector<double>& x, std::vector<double>& grad, double& |
| 136 |
> |
energy, int& status); |
| 137 |
|
|
| 138 |
< |
//calculate the value of object function |
| 139 |
< |
virtual void calcF(); |
| 140 |
< |
virtual void calcF(std::vector<double>& x, double&f, int& status); |
| 138 |
> |
//calculate the value of object function |
| 139 |
> |
virtual void calcF(); |
| 140 |
> |
virtual void calcF(std::vector<double>& x, double&f, int& status); |
| 141 |
|
|
| 142 |
< |
//calculate the gradient |
| 143 |
< |
virtual void calcG(); |
| 144 |
< |
virtual void calcG(std::vector<double>& x, std::vector<double>& g, double& f, int& status); |
| 142 |
> |
//calculate the gradient |
| 143 |
> |
virtual void calcG(); |
| 144 |
> |
virtual void calcG(std::vector<double>& x, std::vector<double>& g, double& f, int& status); |
| 145 |
|
|
| 146 |
< |
//calculate the hessian |
| 147 |
< |
//virtual void calcH(int& status); |
| 148 |
< |
//virtual void calcH(vector<double>& x, std::vector<dobule>& g, SymMatrix& h, int& status); |
| 146 |
> |
//calculate the hessian |
| 147 |
> |
//virtual void calcH(int& status); |
| 148 |
> |
//virtual void calcH(vector<double>& x, std::vector<dobule>& g, SymMatrix& h, int& status); |
| 149 |
|
|
| 150 |
< |
friend std::ostream& operator<<(std::ostream& os, const Minimizer& minimizer); |
| 150 |
> |
friend std::ostream& operator<<(std::ostream& os, const Minimizer& minimizer); |
| 151 |
|
|
| 152 |
< |
protected: |
| 152 |
> |
protected: |
| 153 |
|
|
| 154 |
< |
// transfrom cartesian and rotational coordinates into minimization coordinates |
| 155 |
< |
std::vector<double> getCoor(); |
| 154 |
> |
// transfrom cartesian and rotational coordinates into minimization coordinates |
| 155 |
> |
std::vector<double> getCoor(); |
| 156 |
|
|
| 157 |
< |
// transfrom minimization coordinates into cartesian and rotational coordinates |
| 158 |
< |
void setCoor(std::vector<double>& x); |
| 157 |
> |
// transfrom minimization coordinates into cartesian and rotational coordinates |
| 158 |
> |
void setCoor(std::vector<double>& x); |
| 159 |
|
|
| 160 |
|
|
| 161 |
|
|
| 162 |
< |
//constraint the bonds; |
| 163 |
< |
int shakeR() { return 0;} |
| 162 |
> |
//constraint the bonds; |
| 163 |
> |
int shakeR() { return 0;} |
| 164 |
|
|
| 165 |
< |
//remove the force component along the bond direction |
| 166 |
< |
int shakeF() { return 0;} |
| 165 |
> |
//remove the force component along the bond direction |
| 166 |
> |
int shakeF() { return 0;} |
| 167 |
|
|
| 168 |
< |
double calcPotential(); |
| 168 |
> |
double calcPotential(); |
| 169 |
|
|
| 170 |
< |
SimInfo* info; |
| 170 |
> |
SimInfo* info; |
| 171 |
|
|
| 172 |
< |
ForceManager* forceMan; |
| 172 |
> |
ForceManager* forceMan; |
| 173 |
|
|
| 174 |
< |
//parameter set of minimization method |
| 175 |
< |
MinimizerParameterSet* paramSet; |
| 174 |
> |
//parameter set of minimization method |
| 175 |
> |
MinimizerParameterSet* paramSet; |
| 176 |
|
|
| 177 |
< |
//flag of turning on shake algorithm |
| 178 |
< |
bool usingShake; |
| 177 |
> |
//flag of turning on shake algorithm |
| 178 |
> |
bool usingShake; |
| 179 |
|
|
| 180 |
< |
// dimension of the model |
| 181 |
< |
int ndim; |
| 180 |
> |
// dimension of the model |
| 181 |
> |
int ndim; |
| 182 |
|
|
| 183 |
< |
//name of the minimizer |
| 184 |
< |
std::string minimizerName; |
| 183 |
> |
//name of the minimizer |
| 184 |
> |
std::string minimizerName; |
| 185 |
|
|
| 186 |
< |
// current iteration number |
| 187 |
< |
int curIter; |
| 188 |
< |
//status of minimization |
| 189 |
< |
int minStatus; |
| 186 |
> |
// current iteration number |
| 187 |
> |
int curIter; |
| 188 |
> |
//status of minimization |
| 189 |
> |
int minStatus; |
| 190 |
|
|
| 191 |
< |
//flag of verbose mode |
| 192 |
< |
bool bVerbose; |
| 191 |
> |
//flag of verbose mode |
| 192 |
> |
bool bVerbose; |
| 193 |
|
|
| 194 |
< |
//status of energy and gradient evaluation |
| 195 |
< |
int egEvalStatus; |
| 194 |
> |
//status of energy and gradient evaluation |
| 195 |
> |
int egEvalStatus; |
| 196 |
|
|
| 197 |
< |
//initial coordinates |
| 198 |
< |
//vector<double> initX; |
| 197 |
> |
//initial coordinates |
| 198 |
> |
//vector<double> initX; |
| 199 |
|
|
| 200 |
< |
//current value of the function |
| 201 |
< |
double curF; |
| 200 |
> |
//current value of the function |
| 201 |
> |
double curF; |
| 202 |
|
|
| 203 |
< |
// current coordinates |
| 204 |
< |
std::vector<double> curX; |
| 203 |
> |
// current coordinates |
| 204 |
> |
std::vector<double> curX; |
| 205 |
|
|
| 206 |
< |
//gradient at curent coordinates |
| 207 |
< |
std::vector<double> curG; |
| 206 |
> |
//gradient at curent coordinates |
| 207 |
> |
std::vector<double> curG; |
| 208 |
|
|
| 209 |
< |
//hessian at current coordinates |
| 210 |
< |
//SymMatrix curH; |
| 209 |
> |
//hessian at current coordinates |
| 210 |
> |
//SymMatrix curH; |
| 211 |
|
|
| 212 |
< |
private: |
| 212 |
> |
private: |
| 213 |
|
|
| 214 |
< |
//calculate the dimension od the model for minimization |
| 215 |
< |
void calcDim(); |
| 214 |
> |
//calculate the dimension od the model for minimization |
| 215 |
> |
void calcDim(); |
| 216 |
|
|
| 217 |
< |
}; |
| 217 |
> |
}; |
| 218 |
|
|
| 219 |
|
} |
| 220 |
|
#endif |