/* 
   main_arb.cc
   example main program using an NMSearch,
   reading in an arbitrary simplex from a file.
   
   Anne Shepherd, 5/2001 at
   The College of William and Mary, Williamsburg, Virginia,
   under advisor Dr. Virginia Torczon   
   
   to compile use:
   g++ -g -Wall main_arb.cc objective.cc DirectSearch.cc \
     SimplexSearch.cc SMDSearch.cc NMSearch.cc SHHSearch.cc -lm -o main_arb

*/

#include "objective.h"    
//#include "SMDSearch.h"     
#include "NMSearch.h"   
//#include "SHHSearch.h" 
#include <iostream>              // for cout, file i/o

using namespace std;
int main()
{    
  long n = 4;                      // number of variables (dimension of
                                   //             the search)
  double startstep = 1.0;          // starting step length
  double endstep = 10e-8;          // ending step length
                                   
  double mysigma = 0.5;            // these are the defaults, actually
  double myalpha = 1.0;
  double mybeta = 0.5;
  double mygamma = 2.0;

  double startVal = 5.0;           // starting point for x
  ifstream in;                     // file pointer
  char fname[] = "arbitrary.dat";  // file name
  
  Vector<double> Sminimum(n);      // to store the minimum point later

  /* we'll initialize a one-entry Vector whose value is startVal,
   * and use it as our dummy starting point. The actual start point will
   * be the first point of the simplex we read in from file.
   */
  Vector<double>minVec(n, startVal);

  /* now construct search objects */
  // SMDSearch SMD(n, minVec);
  NMSearch nelder(n, minVec, mysigma, myalpha, mybeta, mygamma, startstep,
              endstep, powell, NULL);


  double SMinVal;
  long Scalls;

  // open the file stream
  in.open(fname);
  assert(in);
  
  // read in the simplex file.
  nelder.ReadInFile(in);
  
  // close the file
  in.close();

  // let's have a look.
  nelder.PrintDesign();

  /* start searching */
  //SMD.BeginSearch();
  nelder.BeginSearch();


  /* recover information about the search */
  // SMD.GetMinPoint(Sminimum);
  // SMD.GetMinVal(SMinVal);
  //Scalls = SMD.GetFunctionCalls();
  
  /* recover information about the search */
  nelder.GetMinPoint(Sminimum);
  nelder.GetMinVal(SMinVal);
  //Scalls = SMD.GetFunctionCalls();
  Scalls = nelder.GetFunctionCalls();
  
  cout << "\nMinimum point found: \n" << Sminimum;
  cout << "\nValue: \n" << SMinVal <<  " in ";
  cout << Scalls << " function calls.\n" << endl<< "\n\n";

  return 0;

}//main
