00001 
00021 #include "kit.h"
00022 #include "hop.h"
00023 
00027 
00031 
00043 Hop_Obj_t * Kit_GraphToHopInternal( Hop_Man_t * pMan, Kit_Graph_t * pGraph )
00044 {
00045     Kit_Node_t * pNode = NULL;
00046     Hop_Obj_t * pAnd0, * pAnd1;
00047     int i;
00048     
00049     if ( Kit_GraphIsConst(pGraph) )
00050         return Hop_NotCond( Hop_ManConst1(pMan), Kit_GraphIsComplement(pGraph) );
00051     
00052     if ( Kit_GraphIsVar(pGraph) )
00053         return Hop_NotCond( Kit_GraphVar(pGraph)->pFunc, Kit_GraphIsComplement(pGraph) );
00054     
00055     Kit_GraphForEachNode( pGraph, pNode, i )
00056     {
00057         pAnd0 = Hop_NotCond( Kit_GraphNode(pGraph, pNode->eEdge0.Node)->pFunc, pNode->eEdge0.fCompl ); 
00058         pAnd1 = Hop_NotCond( Kit_GraphNode(pGraph, pNode->eEdge1.Node)->pFunc, pNode->eEdge1.fCompl ); 
00059         pNode->pFunc = Hop_And( pMan, pAnd0, pAnd1 );
00060     }
00061     
00062     return Hop_NotCond( pNode->pFunc, Kit_GraphIsComplement(pGraph) );
00063 }
00064 
00076 Hop_Obj_t * Kit_GraphToHop( Hop_Man_t * pMan, Kit_Graph_t * pGraph )
00077 {
00078     Kit_Node_t * pNode = NULL;
00079     int i;
00080     
00081     Kit_GraphForEachLeaf( pGraph, pNode, i )
00082         pNode->pFunc = Hop_IthVar( pMan, i );
00083     
00084     return Kit_GraphToHopInternal( pMan, pGraph );
00085 }
00086 
00098 Hop_Obj_t * Kit_TruthToHop( Hop_Man_t * pMan, unsigned * pTruth, int nVars, Vec_Int_t * vMemory )
00099 {
00100     Hop_Obj_t * pObj;
00101     Kit_Graph_t * pGraph;
00102     
00103     if ( vMemory == NULL )
00104     {
00105         vMemory = Vec_IntAlloc( 0 );
00106         pGraph = Kit_TruthToGraph( pTruth, nVars, vMemory );
00107         Vec_IntFree( vMemory );
00108     }
00109     else
00110         pGraph = Kit_TruthToGraph( pTruth, nVars, vMemory );
00111     
00112     pObj = Kit_GraphToHop( pMan, pGraph );
00113     Kit_GraphFree( pGraph );
00114     return pObj;
00115 }
00116 
00128 Hop_Obj_t * Kit_CoverToHop( Hop_Man_t * pMan, Vec_Int_t * vCover, int nVars, Vec_Int_t * vMemory )
00129 {
00130     Kit_Graph_t * pGraph;
00131     Hop_Obj_t * pFunc;
00132     
00133     pGraph = Kit_SopFactor( vCover, 0, nVars, vMemory );
00134     
00135     pFunc = Kit_GraphToHop( pMan, pGraph );
00136     Kit_GraphFree( pGraph );
00137     return pFunc;
00138 }
00139 
00143 
00144