/*-------------------------------------------------------------------------------------*/
/*  NOMAD - Nonsmooth Optimization by Mesh Adaptive Direct search - version 3.0.0      */
/*                                                                                     */
/*  Copyright (C) 2001-2008  Mark Abramson        - the Boeing Company, Seattle        */
/*                           Charles Audet        - Ecole Polytechnique, Montreal      */
/*                           Gilles Couture       - Ecole Polytechnique, Montreal      */
/*                           John Dennis          - Rice University, Houston           */
/*                           Sebastien Le Digabel - Ecole Polytechnique, Montreal      */
/*                                                                                     */
/*  funded in part by AFOSR and Exxon Mobil                                            */
/*                                                                                     */
/*  Author: Sebastien Le Digabel                                                       */
/*                                                                                     */
/*  Contact information:                                                               */
/*    Ecole Polytechnique de Montreal - GERAD                                          */
/*    C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada                  */
/*    e-mail: Sebastien.Le.Digabel@gerad.ca                                            */
/*    phone : 1-514-340-6053 #6673                                                     */
/*    fax   : 1-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, either version 3 of the License, or (at your option) any later         */
/*  version.                                                                           */
/*                                                                                     */
/*  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, see <http://www.gnu.org/licenses/>.                               */
/*                                                                                     */
/*  You can find information on the NOMAD software at www.gerad.ca/nomad               */
/*-------------------------------------------------------------------------------------*/

// . class to represent Eval_Point's in binary files
// . all point coordinates are saved
// . only defined black-box outputs are saved

// . to get all bb_outputs:
//
//   Point bbo(_m);
//   for ( int i = 0 ; i < _m_def ; ++i )
//     bbo [ _bbo_index[i] ] = _bbo_def[i];

#ifndef __CACHE_FILE_POINT__
#define __CACHE_FILE_POINT__

#include "Uncopyable.hpp"
#include "Exception.hpp"
#include <fstream>

// forward declarations:
class Point;
class Eval_Point;

// the class:
class Cache_File_Point : private Uncopyable {

private:
  
#ifdef DEBUG
  static int    _cardinality;      // number of Cache_File_Point's in memory.
  static int    _max_cardinality;  // max number of Cache_File_Point's in memory.
#endif

  int           _n;                // point's dimension
  int           _m;                // number of black-box outputs (both defined and !defined)
  int           _m_def;            // number of defined black-box outputs
  unsigned char _eval_ok;          // if the evaluation did'nt fail (0 or 1)
  double      * _coords;           // the _n coordinates
  double      * _bbo_def;          // the _m_def defined bb outputs values
  int         * _bbo_index;        // the index for these values

  // reset:
  void reset ( void );

public:

  // constructor 1:
  explicit Cache_File_Point ( void );

  // constructor 2:
  explicit Cache_File_Point ( const Eval_Point & x );

  // destructor:
  ~Cache_File_Point ( void );

  // display:
  void display ( std::ostream & out ) const;

  // GET methods:
  int           get_n        ( void  ) const { return _n; }
  int           get_m        ( void  ) const { return _m; }
  unsigned char get_eval_ok  ( void  ) const { return _eval_ok; }
  double        get_coord    ( int i ) const;
  const Point   get_bbo      ( void  ) const;

  // write in binary file:
  bool write ( std::ofstream & out ) const;

  // read in binary file:
  bool read  ( std::ifstream & in );

#ifdef DEBUG
  static int get_cardinality     ( void ) { return Cache_File_Point::_cardinality;     }
  static int get_max_cardinality ( void ) { return Cache_File_Point::_max_cardinality; }
#endif
};

// display:
inline std::ostream & operator << ( std::ostream & out , const Cache_File_Point & x ) {
  x.display(out); return out;
}

#endif
