//    module ProjectB.h                                                       //
//                                                                            //
//    Class TProjectB encapsulates settings for usage of the batch interface  //
//    of the PNC2 algorithm, derived from TProject                            //
//                                                                            //
//    copyright (c) 2001-2003 by Lars Haendel                                 //
//    mail: lore17@newty.de                                                   //
//    home: www.newty.de                                                      //
//                                                                            //
//    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 as version 2 of the License.               //
//                                                                            //
//    This program is distributed in the hope that it will be useful,         //
//    but WITHOUT ANY WARRANTY; without even the implied warranty of          //
//    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., 675 Mass Ave, Cambridge, MA 02139, USA.               //
//                                                                            //

#ifndef PROJECT_B_H
#define PROJECT_B_H

#include "kernel\project.h"      // due to:  base class TProject

// default values section '[Batch]'
#define DEF_SAVE_MEMORY          (bool)  true

// default values section '[Show]'
#define DEF_SHOW_DEVIATION       (bool)  false
#define DEF_SHOW_CRITERION       (bool)  false

// encapsulates settings for usage of the PNC2 algorithm for the batch interface
class TProjectB : public TProject

   // constructor

   // a) load/save and data association

   // load and save settings from/to file
   void Load(ifstream& file, const char*const& _szProjectFilePath);
   void Save(ofstream& file, const bool& f_WriteTuningAnyway=false);

   // check project parameters against constraints and given data file, set output column and variable types,
   // set dependant variables and associate data  -  WARNING: caller has to release returned TParaSetList !!
   TParaSetList* /*cr*/ Synchronize(TData*const& _data1, const bool& f_CheckTuningAnyway=false);

   // b) dependant variables
   const bool& NeedLossOnLearnData() const { return f_LossOnLearnData; };     // loss on learn data is needed
   const bool* GetCriterionsToCalculate() const { return *&f_CritToCalc; };   // return criterions to calculate

   // c) section [Tuning]

   // get tuning results and base filenames
   const char* GetTuningFileName() const { return GetPrefixedPath(szTuningFile, GetOutputDir()); };
   const char* GetTuneDataBaseFile() const { return szTuneDataBaseFile; };
   const char* GetTuneModelBaseFile() const { return szTuneModelBaseFile; };
   const char* GetTuneSimulationBaseFile() const { return szTuneSimulationBaseFile; };

   void SetTuneDataBaseFile(const char* szFilename) { strcpy(szTuneDataBaseFile, szFilename); };
   void SetTuneModelBaseFile(const char* szFilename) { strcpy(szTuneModelBaseFile, szFilename); };
   void SetTuneSimulationBaseFile(const char* szFilename) { strcpy(szTuneSimulationBaseFile, szFilename); };

   int& Ranking() { return ranking; };       // ranking criterion and objective for parameter tuning
   int& Objective() { return objective; };

   int Max_N_R_Tune();       // maximum tuning repetition/cross-validation

   // d) section [Batch]

   bool& SaveMemory() { return f_SaveMemory; };                               // save memory flag
   const bool& SaveMemory() const { return f_SaveMemory; };

   // flag -> true:  use data1 to generate learn and test data
   //         false: use data1 as learn and data2 as test data
   const bool MakeStudy() const { return f_Study; };

   // get study type ('Repetition'/'Cross-Validation'/'Loocv')
   const TTestType& StudyType() const { return studyType; };

   // get repetition/cross-validation count and # learn and test data tuples
   const int& Get_N_R() const { return N_R; };
   const int& Get_N_L() const { return N_L; };
   const int& Get_N_T() const { return N_T; };

   // get name to result filename and base filenames
   const char* GetResultFileName() const { return GetPrefixedPath(szResultFile, GetOutputDir()); };
   const char* GetDataBaseFileName() const { return szDataBaseFileName; };
   const char* GetModelBaseFileName() const { return szModelBaseFileName; };
   const char* GetSimulationBaseFileName() const { return szSimulationBaseFileName; };
   const char* GetOutputDir() const;                                          // output directory for result files

   // e) section [Show]
   const bool* GetCriterionsToShow() const { return f_Criterion; };
   const bool& ShowDev() const { return f_ShowDev; };


   // section [Tuning]
   char szRanking[STS], szObjective[STS];
   int ranking, objective;                   // criterion to rank parameter sets and tuning objective

   char szTuningFile[STS];                   // name of tuning result file
   char szTuneDataBaseFile[STS];             // base filename for generated learn and test data sets during tuning
   char szTuneModelBaseFile[STS];            // base filename model
   char szTuneSimulationBaseFile[STS];       // base filename simulation output
   int Peek_N_L();                           // peek learn data tuple count

   // section [Batch]
   char szResultFile[STS];                   // name of (overall) result file
   char szDataBaseFileName[STS];             // (base) filename for generated data
   char szModelBaseFileName[STS];            // (base) filename simulation output
   char szSimulationBaseFileName[STS];       // (base) filename model
   char szOutputDir[STS];                    // output directory

   char szStudyType[STS];
   TTestType studyType;                      // study type ('Repetition', 'Cross-Validation' or 'Loocv')
   int N_R, N_L, N_T;                        // # repetitions, # learn and test data tuples

   bool f_SaveMemory;                        // flag: save memory (do not store predicted values)
   int f_Study;                              // flag -> true:  use data1 to generate learn and test data
                                             //         false: use data1 as learn and data2 as test data

   // initialize learn and test data tuple counts (N_L and N_R) and repetition/cross-validation count (N_R) with respect
   // to study flag (f_Study) and study type.
   void IniStudyCounts();

   // section [Show]
   bool f_ShowDev;                           // show/write deviation of results
   bool f_Criterion[nCriterion];             // flags: calculate and log corresponding error criterion

   // dependant variables
   bool f_CritToCalc[nCriterion];            // criterions which must be calculated
   bool f_LossOnLearnData;                   // flag: loss on learn data is needed

   // initialize flag arrays with the criterions that need to be calculated according to section '[Show]' , objective etc.
   void IniCriterionFlags();