/*
   main_fail.cc
   example main program using an SHHSearch. This search will terminate
   prematurely.
   
   P.L. (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_fail.cc objective.cc DirectSearch.cc \
         SimplexSearch.cc SHHSearch.cc  -lm -o main_fail

*/

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

using namespace std;

int main()
{    
  long n = 2;                      // number of variables (dimension of
                                   //                      the search)

  /* terminates prematurely with startval = 1, 3, 5, 7, 9 ...
     finds true min with startval = 2, 4, 6, 8, 10 ...
   */
  double startVal = 3.0;          // starting point for x

  /* if we change this to 2.01 it doesn't hang up. */
  double startstep = 2.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, startVal);
  cout << "Starting point is: " << minVec << endl;

  
  /* now construct a Search object. we need to set the last
   * parameter to NULL, because we won't be using it.
   *
   * Note that parab_fcn is a
   *  wrapper for the function  (x^2 + 3y^2). */
  SHHSearch SHH(n, minVec, startstep, endstep, parab_fcn, NULL);

  double SMinVal;
  long Scalls;
  SHH.SetMaxCalls(250);

  /* If this flag is set, the search will hang on (1,1).
   * The true min is of course at the origin. */
  SHH.Set_Stop_on_std();
  

  /* start searching */
  SHH.BeginSearch();
  SHH.PrintDesign();
  
  SHH.GetMinPoint(Sminimum);
  SHH.GetMinVal(SMinVal);
  Scalls = SHH.GetFunctionCalls();
  
  cout << "\nMinimum point found: " << Sminimum;
  cout << "\nValue: \n" << SMinVal <<  " \nin ";
  cout << Scalls << " function calls.\n" << endl<< "\n\n";
  cout << "delta = " << SHH.GetDelta() << endl;

  return 0;

}//main



