/* 
 *  main_eval.cc
 *  example main program using a CompassSearch and a toy
 *      objective-function program, "standalone" (compiled from
 *      "standalone.cc")      (alternatively,
 *      the test function "shekel5.lin", compiled from shekel.cc,
 *      with m = 5)
 *  Note that this presumes that the file whose name is sent in to
 *      the constructor is a binary executable that reports the function
 *      value on its standard output.  See user's manual.
 *  
 *  Liz Dolan, 1999 and Anne Shepherd, 8/2000 at
 *  The College of William and Mary, Williamsburg, Virginia,
 *  under advisor Dr. Virginia Torczon.
 *      Revised, pls, 1/2001
 *  
 *  to compile use:
 *  g++ -g -Wall main_eval.cc objective.cc DirectSearch.cc \
 *      PatternSearch.cc CompassSearch.cc -lm -o meval
 * 
*/

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


using namespace std;
int main(void)

{ 
  //long n = 4;                    // for shekel5.lin function, use n = 4
        
  long n = 1;                      // number of variables (dimension of
                                   //             the search)-- for standalone.cc
  double startVal = 2.0;           // starting point for x
  double startstep = 1.0;          // starting step length
  double endstep = 10e-8;          // ending step length

  double SMinVal;                  // to hold the min value
  long Scalls;                     // to hold the number of calls
  
  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;

  // We'll send the filename in to the fcn_eval function, declared in
  // objective.h. 
  
  //char * filename = "shekel5.lin";
  char * filename = "standalone";
  
  // now we construct a Search object.  Note that we must cast the filename
  // to a void * 
  CompassSearch CS(n, minVec, startstep,endstep, fcn_eval, (void *)filename);

  // we're not using a function call budget here.
  CS.SetMaxCalls(CompassSearch::NO_MAX);
  cout << "\ndelta = " << CS.GetDelta() << endl;

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

}//main








