/******************************************************************************
* 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/                                      *
******************************************************************************/

// pollcontrol.h -- class definition for PollControl. This class controls
// the poll algorithm.

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

class AugmentedPoint;
class Description;
class DirectionSet;
class Evaluator;
class Parameters;
class Pollster;
class SurrogateControl;

class PollControl
{
  // The PollControl object has the following variables:
  // - 'display_factor' is used for debugging.
  // - 'prox_array' is a vector telling us if a trial point is near the bounds.
  //   It's used only for GPS (MADS directions don't need it).
  // - An STL container, 'trial_points' contains the points generated by the
  //   poll in an iteration. 'a_point' is an iterator for the container.
  // - Constant pointers to the Description and Parameters objects.
  // - Pointers to DirectionSet, Evaluator, Pollster and SurrogateControl.
 private:
  int display_factor;
  int * prox_array;
  std::vector<AugmentedPoint *> trial_points;
  std::vector<AugmentedPoint *>::iterator a_point;
  const Description * const description;
  DirectionSet * direction_set;
  Evaluator * eval;
  const Parameters * const parameters;
  Pollster * pollster;
  SurrogateControl * surr_control;

  // The class methods are described in "pollcontrol.cpp".
  bool equal(int * old, int * _new) const;
  void cleanList();
  void copy(int * a, int * b) const;
  void initialize();
  void showList();
  void success(const int index);

 public:
  PollControl(const Description * const des, Evaluator & e,
	      const Parameters * const par);
  ~PollControl();
  bool updateDirectionSet();
  std::vector<double> & getSuccessfulDirection(const int polldir_index);
  int poll(const double delta, const double * primary_poll_center,
	   const double * secondary_poll_center, int & term_flag,
	   ofstream & fout, ofstream & fgraph, ofstream & history);
  void continueRun();
  void linkWithSurrogate(SurrogateControl & surr);
  void setDisplay(const int display);
};
#endif
