/******************************************************************************
* NOMAD -  Nonlinear Optimization for Mixed vAriables and Derivatives.        *
* Copyright (C) 2001-2004  Gilles Couture - Ecole Polytechnique,              *
*                          Charles Audet - Ecole Polytechnique,               *
*		           John Dennis - Rice University.                     *
*                                                                             *
* Author: Gilles Couture                                                      *
* École Polytechnique de Montréal - GERAD                                     *
* C.P. 6079, Succ. Centre-ville, Montréal (Québec) H3C 3A7 Canada             *
* Tel:  (514) 340-6053 x6928                                                  *
* Email: Gilles.Couture@gerad.ca                                              *
* Fax: (514) 340-5665                                                         *
*                                                                             *
* This program is free software; you can redistribute it and/or               *
* modify it under the terms of the GNU General Public License                 *
* as published by the Free Software Foundation. You can find the              *
* GNU General Public License at:                                              *
*             http://www.gnu.org/copyleft/gpl.html                            *
*                                                                             *
* This program is distributed in the hope that it will be useful,             *
* but WITHOUT ANY WARRANTY; without even the implied warranty of              *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
* GNU General Public License for more details.                                *
*                                                                             *
* You should have received a copy of the GNU General Public License           *
* along with this program; if not, write to the Free Software                 *
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. *
*                                                                             *
* You can find information on the NOMAD software at:                          *
*             http://www.gerad.ca/NOMAD/                                      *
******************************************************************************/

// searchcontrol.h -- class definition for SearchControl, which is the context
// object between Solver and Searcher.

#ifndef _SEARCHCONTROL_H_
#define _SEARCHCONTROL_H_
#include <vector>
using namespace std;

class AugmentedPoint;
class Description;
class Evaluator;
class Parameters;
class Searcher;
class SurrogateControl;

class SearchControl
{
  // The SearchControl object has the following variables:
  // - The boolean 'initial' is used to know if we're in the first iteration.
  // - 'display_factor' is used for debugging.
  // - An STL container, 'list_of_points' contains the points generated by the
  //   search strategy in an iteration. 'a_point' is an iterator for the
  //   container.
  // - Constant pointers to the Description and Parameters objects.
  // - Pointers to Evaluator and SurrogateControl.
  // - Pointers to the different Searcher objects.
 private:
  bool initial;
  int display_factor;
  std::vector<AugmentedPoint *> trial_points;
  std::vector<AugmentedPoint *>::iterator a_point;
  const Description * const description;
  Evaluator * eval;
  const Parameters * const parameters;
  Searcher * initial_search, * iterative_search, * speculative_search;
  SurrogateControl * surr_control;

  // The methods are described in "searchcontrol.cpp"
  void cleanList();
  void deleteSearcherObjects();
  void initialize();
  void mesher(const double * incumbent, const double delta);
 public:
  SearchControl(const Description * const des, Evaluator & e,
								const Parameters * const par);
  ~SearchControl();
  int search(const double delta, const double * poll_center, int poll_success,
						 int & term_flag, ofstream & fout, ofstream & fgraph,
						 ofstream & history);
  void continueRun();
  void linkWithSurrogate(SurrogateControl & surr);
  void setDisplay(const int display);
  void showList();
  void update(const double delta, std::vector<double> & direction,
							const AugmentedPoint * new_incumbent);
};
#endif
