#pragma once

using namespace std;

#define PLA_TABLE_ERROR___OK					0
#define PLA_TABLE_ERROR___CANT_OPEN_FILE		1
#define PLA_TABLE_ERROR___INCORRECT_DATA		2
#define PLA_TABLE_ERROR___TOO_MANY_VARS			3
#define PLA_TABLE_ERROR___UNSUPPORTED_FORMAT	4

struct PLA_Row
{
	vector<char>	outputs;
	vector<char>	inputs;

	PLA_Row(){};
	PLA_Row(uint i, uint o)
	{
		for (uint n=0; n<i; n++)
			inputs.push_back(TERM_X);
		for (uint n=0; n<o; n++)
			outputs.push_back(TERM_1);
	}

};

struct PLA_Input_Var_Histogram_Item
{
	uint	id;
	uint	num;
	uint	bngb;

	PLA_Input_Var_Histogram_Item(uint i,uint n):id(i),num(n){bngb=0;};
	bool operator < (const PLA_Input_Var_Histogram_Item& x)
	{
		return num > x.num;
	}
};

typedef vector<PLA_Input_Var_Histogram_Item> PLA_Input_Var_Histogram;
typedef vector<uint> MBD_VAR_ORDERING;


struct PLA_Stats
{
	uint	term_num;
	uint	x_term_num;
	uint	lit_num;
};


class PLA
{
public:
	uint i_num, o_num;

	vector<PLA_Row> rows;

	PLA(){i_num=o_num=0;};
	PLA(uint i,uint o):i_num(i),o_num(o){};
	
	uint load(char* filename);
	uint save(char* filename);
	uint get_histogram(PLA_Input_Var_Histogram& hst);
	uint get_stats(PLA_Stats&);
	uint print_histogram(PLA_Input_Var_Histogram& hst);
	void clear(){rows.clear();};

	void or_pla(PLA& pla);
	void and_var(uint var, uint val);

};