/* 
   main_obj.cc
   example main program using an HJSearch and long constructor
   
   Use with trigclass.h
    
   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_obj.cc objective.cc trigclass.cc \
      DirectSearch.cc PatternSearch.cc  HJSearch.cc  -lm -o main_obj

*/

#include "objective.h"    
#include "HJSearch.h"
#include "trigclass.h"
#include <iostream>              // for cout

using namespace std;

int main(void)
{    
  long n = 1;                      // number of variables (dimension of
                                   //                      the search)
  double startVal = 1.0;           // starting point for x
  double startstep = .25;          // starting step length
  double endstep = 10e-8;          // ending step length

  /* here, we declare and initialize a pointer to  an object of
   * type trigclass.
   */
   
  trigclass* t_ptr = new trigclass(0);
  
  Vector<double> Hminimum_1(n);      // to store the first minimum point later

  /* we'll initialize a one-entry Vector whose value is startVal,
   * and use it as our starting point.
   */
  Vector<double>minVec(n, startVal);
  
  /* now construct an HJSearch object with the long
   * constructor. 
   *
   * In this example we minimize the cosine.
   */
  HJSearch HJ_1(n, minVec, startstep, endstep, find_Cos, (void *)t_ptr);

  double HMinVal_1;
  long Hcalls_1;
  double step_1;
  

  /* start searching */
  HJ_1.BeginSearch();

  /* retrieve information about HJ_1 */
  HJ_1.GetMinPoint(Hminimum_1);
  HJ_1.GetMinVal(HMinVal_1);
  Hcalls_1 = HJ_1.GetFunctionCalls();
  step_1 = HJ_1.GetDelta();
  
  cout << "\nMinimum point found: \n" << Hminimum_1;
  cout << "Value: \n" << HMinVal_1 << "\n\n";
  cout << "Last used step length:\n" << step_1 * 2 << " in "
       << Hcalls_1 << " function calls.\n" << endl;

  delete t_ptr;
  return 0;

}//main



