//---------------------------------------------------------------------------
#ifndef boomH
  #define boomH
//---------------------------------------------------------------------------
#include "main.h"
#include "../modulemanager/imodule.h"
#include "../modulemanager/moduletype.h"
#include "../modulemanager/messageclass.h"
#include "../tk/gui/gui.h"

/* tracking: 1 = CD-S 2 = reduction 4 = Cover */
  #define trck 0
  #define mintrck 0



//---------------------------------------------------------------------------
struct DecompositionOptions;
//struct Notation;
//struct TGauge;
//---------------------------------------------------------------------------

struct CD_Opts;
struct Cov_Opts;

struct MinimizeOptions
{
  // CD-S
  CD_Opts * cdopts;
  Cov_Opts * covopts;

  // IE
  int IE_type;          // 0=SQ, 1=distrib_multi, 2=distrib_EXH, 3=multi, 4=EXH
  // dominance
  int DOM_type;         // 0=none, 1=duplicity, 2=dominance
  // IR
  int IR_no;            // 1=no IR
  int IR_mutations;     // mutations

  int OR_no;            // 1 = no OR
  // IC
  int IC_type;          // 0=compare, 1=tree
  int IC_memory;        // 1=implicant check memory

  // cover
  int COV_end;          // 1 = endcover only
  int COV_somin;        // 1 = single-output minimization



  int STOP_time;
  float STOP_maxtime;
  int STOP_iterations;
  int STOP_maxiterations;
  int STOP_improvement;
  int STOP_improvementint;
  int STOP_optimization;
  int STOP_optimizationval;

  int OPT_crit;

  int CD_no;            // 1=no CD-S
  
  // notation
  Notation notation;           // for saving as equations
  bool savevarnames;        //  generate names when none are specified (for PLA)

  int DECOMP_enable;    // 1 = enable decomposition
  DecompositionOptions * dopts;           // decomposition options

  int DFT_enable;

  int FC_DF_dir;        // 0 = 1:x, 1 = x:1, 2 = scatter
  int FC_DF;

  int CD_FC;            // 0 = CD-S only, 100 = FC-Min only
};
//---------------------------------------------------------------------------

struct MinInfo
{
  int cyc;
  float tm;
  float CPUtm;
  int F_hits;
  int tries;
};

//---------------------------------------------------------------------------
class TBuffers;
class TermTree;

class Boom:public IModule
{
public:
    MinimizeOptions * mo;
    TGauge gauge;
    MinInfo info;

	class TBoolFnct *srcf; // osve
	int of; //osve
	int op; //osve

	Ptr<TkTopLevel> window; //osve

    Boom();
    ~Boom();
    class TBoolFnct * Minimize( TBoolFnct * srcf );

	virtual void afterInstantiate(); // osve
	virtual void receiveMessage(TObject* mesg); // osve
	virtual void run(); // osve

private:
    TermTree * * i_buffer; // CD-search buffer for each output (hist)
    TBoolFnct * e_buffer; // CD/IE-phase buffer (shist)
    TBoolFnct * r_buffer; // IR-phase buffer (allf)
    TermTree * primes_ie; // primes after IE (PrHist)
    TermTree * * offtree; // offset tree
    TermTree * * imp_test; //

	// nasledujici 3 funkce jsou jen pro funkcionalitu GAUGES - casem asi odebrat
	static int NewGauge( char * name, int max, int context ) //osve
	{
		return 0;
	};
	static void CloseGauge() //osve
	{
	
	};
	static int GaugeStep( int val, int context ) //osve
	{
		return 0;
	};

    void InitBuffers( TBoolFnct * srcf );
    void DeleteBuffers( TBoolFnct * srcf );
    TBoolFnct * OneMinStep( TBoolFnct * srcf, TBoolFnct * allf );
    TBoolFnct * OneFCMinStep( TBoolFnct * srcf, TBoolFnct * allf );
};

class BoomLoader:public ModuleType
{
	static Ptr<VarDef> variables[]; // define variables which can be set from shell
	static Ptr<Command> commands[];

	static string name;
public:

	const string& getName() const
	{
		return name;
	}
	Ptr<Command>* getCommands() const
	{
		return commands;
	}

	// return array of variables which will module use in shell
	Ptr<VarDef>* getVariables() const
	{
		return variables;
	}
	IModule* newModule() const
	{
		return new Boom();
	}
};

#endif
