00001
00019 #include "abc.h"
00020 #include "dec.h"
00021
00025
00029
00041 DdNode * Dec_GraphDeriveBdd( DdManager * dd, Dec_Graph_t * pGraph )
00042 {
00043 DdNode * bFunc, * bFunc0, * bFunc1;
00044 Dec_Node_t * pNode;
00045 int i;
00046
00047
00048 assert( Dec_GraphLeaveNum(pGraph) >= 0 );
00049 assert( Dec_GraphLeaveNum(pGraph) <= pGraph->nSize );
00050
00051
00052 if ( Dec_GraphIsConst(pGraph) )
00053 return Cudd_NotCond( b1, Dec_GraphIsComplement(pGraph) );
00054
00055 if ( Dec_GraphIsVar(pGraph) )
00056 return Cudd_NotCond( Cudd_bddIthVar(dd, Dec_GraphVarInt(pGraph)), Dec_GraphIsComplement(pGraph) );
00057
00058
00059 Dec_GraphForEachLeaf( pGraph, pNode, i )
00060 pNode->pFunc = Cudd_bddIthVar( dd, i );
00061
00062
00063 Dec_GraphForEachNode( pGraph, pNode, i )
00064 {
00065 bFunc0 = Cudd_NotCond( Dec_GraphNode(pGraph, pNode->eEdge0.Node)->pFunc, pNode->eEdge0.fCompl );
00066 bFunc1 = Cudd_NotCond( Dec_GraphNode(pGraph, pNode->eEdge1.Node)->pFunc, pNode->eEdge1.fCompl );
00067 pNode->pFunc = Cudd_bddAnd( dd, bFunc0, bFunc1 ); Cudd_Ref( pNode->pFunc );
00068 }
00069
00070
00071 bFunc = pNode->pFunc; Cudd_Ref( bFunc );
00072 Dec_GraphForEachNode( pGraph, pNode, i )
00073 Cudd_RecursiveDeref( dd, pNode->pFunc );
00074 Cudd_Deref( bFunc );
00075
00076
00077 return Cudd_NotCond( bFunc, Dec_GraphIsComplement(pGraph) );
00078 }
00079
00091 unsigned Dec_GraphDeriveTruth( Dec_Graph_t * pGraph )
00092 {
00093 unsigned uTruths[5] = { 0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0, 0xFF00FF00, 0xFFFF0000 };
00094 unsigned uTruth, uTruth0, uTruth1;
00095 Dec_Node_t * pNode;
00096 int i;
00097
00098
00099 assert( Dec_GraphLeaveNum(pGraph) >= 0 );
00100 assert( Dec_GraphLeaveNum(pGraph) <= pGraph->nSize );
00101 assert( Dec_GraphLeaveNum(pGraph) <= 5 );
00102
00103
00104 if ( Dec_GraphIsConst(pGraph) )
00105 return Dec_GraphIsComplement(pGraph)? 0 : ~((unsigned)0);
00106
00107 if ( Dec_GraphIsVar(pGraph) )
00108 return Dec_GraphIsComplement(pGraph)? ~uTruths[Dec_GraphVarInt(pGraph)] : uTruths[Dec_GraphVarInt(pGraph)];
00109
00110
00111 Dec_GraphForEachLeaf( pGraph, pNode, i )
00112 pNode->pFunc = (void *)uTruths[i];
00113
00114
00115 Dec_GraphForEachNode( pGraph, pNode, i )
00116 {
00117 uTruth0 = (unsigned)Dec_GraphNode(pGraph, pNode->eEdge0.Node)->pFunc;
00118 uTruth1 = (unsigned)Dec_GraphNode(pGraph, pNode->eEdge1.Node)->pFunc;
00119 uTruth0 = pNode->eEdge0.fCompl? ~uTruth0 : uTruth0;
00120 uTruth1 = pNode->eEdge1.fCompl? ~uTruth1 : uTruth1;
00121 uTruth = uTruth0 & uTruth1;
00122 pNode->pFunc = (void *)uTruth;
00123 }
00124
00125
00126 return Dec_GraphIsComplement(pGraph)? ~uTruth : uTruth;
00127 }
00128
00129
00133
00134