#include <bdd.h>
#include <iostream>
#include <bitset>
#include "bag.h"
#include "set.h"

using namespace std;


bdd bag2set(bdd bag){

    bdd u;	
    bdd temp1;
    int member;
    //cout << " ^.^ levels = " << levels << endl;
	for (int i =0; i<levels;i++)
    {
    	
    	
    	if (bagIsMember(bdd_ithvar(i),bag))
    	{   
			if (getOcc(bdd_ithvar(i), bag) > 0){
				
				temp1 = bdd_ithvar(i);
				cout << i << "'s occ greater than zero " << endl;
			
				}
			else {
				temp1 = bdd_nithvar(i);    
				cout << i << "'s occ is zero " << endl;
				
				}
			
     	}
     	else {
     		   continue;
     		   
     		 }
	
      	for (int k=0 ; k<levels; k++){
      		
      		if (k != i)
      		{ 
      		  temp1 = temp1 & bdd_nithvar(k);
      		}
		}
      	

	   u = u | temp1;
	}	
	
	return u;
	
	
}

   




bdd set2bag(bdd set){


    bdd u;	
    bdd temp1;
    int member;
    //cout << " ^.^ levels = " << levels << endl;
	for (int i =0; i<levels;i++)
    {
    	
    	
    	if (setIsMember(bdd_ithvar(i),set)){
    	    member =1;
    	    //cout << i << ": is a member in this set" << endl;
    	    
    		}
      else {
    	    member =0;  
        	//cout << i << ": is ***NOT***  a member in this set" << endl;  
        		
        	}
        bitset<3> bs(member); 	
		//for (int j=0; j<bs.size(); j++) { cout << "bs[ " << j << " ]= " << bs[j] << endl;  }  

    	
      	temp1 = bdd_ithvar(i);
      	
      	for (int k=0 ; k<levels; k++){
      		
      		if (k != i)
      		{ 
      		  temp1 = temp1 & bdd_nithvar(k);
      		}
		}
      	
      	//bdd_printdot(temp1);
      	
		for (int j=0; j<bs.size(); j++)
		{
				
				//cout << "bs at  " << j << " is: " << bs[j] << endl;
				if (bs[j] == 1)
				 { 
				  //cout << "true" << endl;
				  temp1 = temp1 & bdd_ithvar(j+3);
				 }
				else
				 { 
				  //cout << "false" << endl;
				  temp1 = temp1  & bdd_nithvar(j+3);
				 }
	   }
	   u = u | temp1;
	}	
	
	return u;
}
