/* 
   main_hy.cc
   example main program using a Hybrid_NMSearch.
   
   Liz Dolan, 1999 and Anne Shepherd, 8/2000 at
   The College of William and Mary, Williamsburg, Virginia,
   under advisor Dr. Virginia Torczon   
   
   to compile use:
   g++ -g -Wall main_hy.cc objective.cc DirectSearch.cc \
       SimplexSearch.cc NMSearch.cc Hybrid_NMSearch.cc \
       PatternSearch.cc EdHJSearch.cc  -lm -o main_hy

   ---or, if you want it to tell you what it's doing, 

   g++ -g -Wall -DVERB main_hy.cc objective.cc DirectSearch.cc \
       SimplexSearch.cc NMSearch.cc Hybrid_NMSearch.cc \
       PatternSearch.cc EdHJSearch.cc  -lm -o main_hy

*/

#include "objective.h"    
#include "Hybrid_NMSearch.h" 
#include <iostream>              // for cout
#include "vec.h"

using namespace std;

int main(void)
{    
  long n = 4;                      // number of variables (dimension of
                                   //       the search)
  //s.v. = 3, s.s. = 2.5
  double startVals[] =  {3, -1, 0, 1};  
   
  double mysigma = 0.5;            // these are the NMSearch defaults.
  double myalpha = 1.0;
  double mybeta = 0.5;
  double mygamma = 2.0;

  double startstep = 1.0;          // starting step length
  double endstep = 10e-8;          // ending step length for NM part
  double end_Estep = 10e-8;        // ending step length for EdHJ part
  
  Vector<double> Sminimum(n);      // to store the minimum point later

  /* we'll initialize an n-entry Vector whose value is startVal,
   * and use it as our starting point.
   */
  Vector<double>minVec(n, startVals);
  cout << "Starting point is: " << minVec << endl;
     
  
  /* now construct a Search object  
   * in order to use the long constructor, we need to 
   * send a NULL in as the last parameter, because we won't be
   * using that parameter here.
   * 
   *  Note that Powell's quartic is noisy near the minimum, and 
   * therefore it usually takes the Pattern Searches a while to 
   * settle down and declare victory.  
   */
  Hybrid_NMSearch HNM(n, minVec, mysigma, myalpha, mybeta, mygamma, startstep,
              endstep, end_Estep, powell, NULL);

  double SMinVal;
  long Scalls;

  // If you don't want a function call budget, remove commenting on the
  //  line below, and comment the following line out.
  // HNM.SetMaxCalls(Hybrid_NMSearch.NO_MAX);
  HNM.SetMaxCalls(300);

  HNM.ChooseRegularSimplex();
  // cout << "\ndelta = " << HNM.GetDelta() << endl;
  
  /* start searching */
  HNM.BeginSearch();

  
  HNM.GetMinPoint(Sminimum);
  HNM.GetMinVal(SMinVal);
  Scalls = HNM.GetFunctionCalls();
  
  cout << "\nMinimum point found: " << Sminimum;
  cout << "Value: \n" << SMinVal <<  " in ";
  cout << Scalls << " function calls.\n" << endl<< "\n\n";
  
  return 0;

}//main



