// BuddyPlaLoad.cpp : Defines the entry point for the console application.
//

#include "bdd.h"
#include "bvec.h"
#include "fdd.h"
#include "PlaFile.h"

typedef struct{
	bdd *fRoot;
	int i;
	int o;
} BddArray;


int BuddyPlaLoad(char *path, BddArray *result){
	bdd tmp,var,fAdd;
	PlaData data;	
	PlaOpen(path, &data);	
	result->fRoot = new bdd[data.o];
	
	fAdd=bdd_true();
	result->i = data.i;
	result->o = data.o;
	bdd_setvarnum(result->i+10);

	for(int i=0;i<data.o;i++) {
		result->fRoot[i] = bdd_false();			
	}
	for (i=0; i<data.p;i++){
		fAdd = bdd_true();
		for (int j=0;j<data.i;j++){			
			var = bdd_ithvarpp(j);
			if (data.iArray[i][j]==1) tmp= var &fAdd;
			else if (data.iArray[i][j]==0) tmp=bdd_not(var) & fAdd;			
			fAdd = tmp;
		}
		for(j=0;j<data.o;j++){
			if(data.oArray[i][j] == 1)  result->fRoot[j] |= fAdd;		
		}
	}
	return true;
}




