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

// solver.h -- class definition for Solver. This class acts as a control box
// for the program. It receives all system operation messages from the user
// interface, and dispatches the tasks to the program objects. The Solver
// object is the heart of the optimization part of Nomad, with the
// "solveProblem(...)" function.

#ifndef _SOLVER_H_
#define _SOLVER_H_

class Description;
class Evaluator;
class Mesh;
class Parameters;
class PollControl;
class SearchControl;
class SurrogateControl;

class Solver
{
  // The Solver object has the following variables:
  // - 'display_factor' is used for debugging.
  // - 'iteration_count' is an iteration counter.
  // - 'termination_flag' holds which termination criterion stops the run.
  // - Constant pointers to the Description and Parameters objects.
  // - Pointers to Evaluator, Mesh, PollControl, SearchControl,
  //   SurrogateControl.
 private:
  int display_factor, iteration_count, termination_flag;
  const Description * const description;
  Evaluator * evaluator;
  Mesh * mesh;
  const Parameters * const parameters;
  PollControl * pollcontrol;
  SearchControl * searchcontrol;
  SurrogateControl * surr_control;

// The class methods are described in "solver.cpp".
  bool update(const int search_success, const int poll_success);
  void prepareOutputFiles(ofstream & fout, ofstream & fgraph,
			  ofstream & history);
 public:
  Solver(const Description * const des, const Parameters * const par);
  ~Solver();
  double getMeshSize() const;
  double getTruth() const;
  int returnNewTruthEvaluations() const;
  int returnPermCacheHits() const;
  int returnTempCacheHits() const;
  int returnTruthEvaluations() const;
  void continueRun();
  void endProgram();
  void evaluateStartingPoint();
  void fillWithBestPoint(double * coord) const;
  void setDisplay(const int display);
  void showInput(ofstream & fout) const;
  void showOutput(ofstream & fout) const;
  void solveProblem(ofstream & fout);

  // Inline methods.
  // ---------------

  // This method returns the termination flag.
  int returnTerminationFlag() const {return termination_flag;}
};
#endif
