/* 
   main_spec.cc
   example main program using an NMSearch. In this example, we
     specify the function name, having included it in our
     objective file.
   
   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_spec.cc objective.cc DirectSearch.cc \
        SimplexSearch.cc NMSearch.cc -lm -o main_spec

*/

#include "objective.h"    
#include "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)
  /* Starting point for x.  We use the starting point used by Nelder and
   * Mead.
   */
  double startVals[] =  {3, -1, 0, 1};         
  double startstep = 1.0;          // starting step length
  double endstep = 10e-8;          // ending step length
  
  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 in a NULL as the last parameter, because we won't be using
   *  that parameter here. 
   */        
  
  NMSearch NM(n, minVec, 0.5, 1.0, 0.5, 2.0, startstep,
              endstep, powell, NULL);

  double SMinVal;
  long Scalls;
  //NM.SetMaxCalls(-1);
  NM.SetMaxCalls(350);
  NM.ChooseRightSimplex();

  /* If you wish to use the Stop_on_delta() option, comment this back
   * in.
   */
  //NM.Set_Stop_on_delta();
  
  /* start searching */
  NM.BeginSearch();

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

}//main




