ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/SteepestDescent.cpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/SteepestDescent.cpp (file contents):
Revision 1011 by tim, Tue Feb 3 20:47:10 2004 UTC vs.
Revision 1015 by tim, Tue Feb 3 22:54:52 2004 UTC

# Line 1 | Line 1
1   #include "SteepestDescent.hpp"
2 + #include "Utility.hpp"
3 + void SteepestDescent::minimize(){
4 +  int maxIteration;
5 +  int nextRestIter;
6 +  int resetFrq;
7 +  int nextWriteIter;
8 +  int writeFrq;
9 +  
10 +  if (!isSolvable()){
11 +    cout << "ConjugateMinimizerBase Error: This nonlinear model can not be solved by " << methodName <<endl;
12  
13 +    exit(1);
14 +  }
15 +
16 +  printMinizerInfo();
17 +
18 +  resetFrq = paramSet->getResetFrq();
19 +  nextRestIter = resetFrq;
20 +
21 +  writeFrq = paramSet->getWriteFrq();
22 +  nextWriteIter = writeFrq;
23 +  
24 +  direction = model->calcGrad();
25 +  
26 +  maxIteration = paramSet->getMaxIteration();
27 +
28 +  for(currentIter = 0;currentIter < maxIteration; currentIter++){
29 +
30 +    // perform line search to minimize f(x + stepSize * direction) where stepSize > 0
31 +    lsMinimizer->minimize(direction, 0.0, 1.0);
32 +    
33 +    lsStatus = lsMinimizer->getMinimizationStatus();
34 +    
35 +    if(lsStatus ==MINSTATUS_ERROR){
36 +      minStatus = MINSTATUS_ERROR;
37 +      return;
38 +    }
39 +    
40 +    prevMinX = minX;
41 +    minX = minX + lsMinimizer->getMinVar() * direction;
42 +
43 +    //calculate the gradient
44 +    
45 +    direction = model->calcGrad(minX);
46 +
47 +    // stop if converge
48 +    if (checkConvergence() > 0){
49 +      writeOut(minX, currentIter);
50 +
51 +      minStatus = MINSTATUS_CONVERGE;
52 +      return;
53 +    }
54 +
55 +    //
56 +    if (currentIter == nextWriteIter){
57 +      nextWriteIter += writeFrq;
58 +      writeOut(minX, currentIter);
59 +    }
60 +
61 +    if (currentIter == nextResetIter){
62 +      reset();
63 +      nextResetIter += resetFrq;      
64 +    }
65 +
66 +  }
67 +
68 +  // if writeFrq is not a multipiler of maxIteration, we need to write the final result
69 +  // otherwise, we already write it inside the loop, just skip it
70 +  if(currentIter != (nextWriteIter - writeFrq))
71 +    writeOut(minX, currentIter);
72 +
73 +  minStatus = MINSTATUS_MAXITER;
74 +  return;
75 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines