00001
00021 #include "aig.h"
00022
00026
00030
00043 static inline int Aig_NodeGetLeafCostOne( Aig_Obj_t * pNode, int nFanoutLimit )
00044 {
00045 int Cost;
00046
00047 assert( pNode->fMarkA );
00048
00049 if ( Aig_ObjIsPi(pNode) )
00050 return 999;
00051
00052 Cost = (!Aig_ObjFanin0(pNode)->fMarkA) + (!Aig_ObjFanin1(pNode)->fMarkA);
00053
00054 if ( Cost < 2 )
00055 return Cost;
00056
00057 if ( (int)pNode->nRefs > nFanoutLimit )
00058 return 999;
00059
00060 return Cost;
00061 }
00062
00077 int Aig_ManFindCut_int( Vec_Ptr_t * vFront, Vec_Ptr_t * vVisited, int nSizeLimit, int nFanoutLimit )
00078 {
00079 Aig_Obj_t * pNode, * pFaninBest, * pNext;
00080 int CostBest, CostCur, i;
00081
00082 CostBest = 100;
00083 pFaninBest = NULL;
00084
00085 Vec_PtrForEachEntry( vFront, pNode, i )
00086 {
00087 CostCur = Aig_NodeGetLeafCostOne( pNode, nFanoutLimit );
00088
00089 if ( CostBest > CostCur ||
00090 (CostBest == CostCur && pNode->Level > pFaninBest->Level) )
00091 {
00092 CostBest = CostCur;
00093 pFaninBest = pNode;
00094 }
00095 if ( CostBest == 0 )
00096 break;
00097 }
00098 if ( pFaninBest == NULL )
00099 return 0;
00100 assert( CostBest < 3 );
00101 if ( Vec_PtrSize(vFront) - 1 + CostBest > nSizeLimit )
00102 return 0;
00103 assert( Aig_ObjIsNode(pFaninBest) );
00104
00105 Vec_PtrRemove( vFront, pFaninBest );
00106
00107
00108
00109 pNext = Aig_ObjFanin0(pFaninBest);
00110 if ( !pNext->fMarkA )
00111 {
00112
00113 pNext->fMarkA = 1;
00114 Vec_PtrPush( vFront, pNext );
00115 Vec_PtrPush( vVisited, pNext );
00116 }
00117
00118 pNext = Aig_ObjFanin1(pFaninBest);
00119 if ( !pNext->fMarkA )
00120 {
00121
00122 pNext->fMarkA = 1;
00123 Vec_PtrPush( vFront, pNext );
00124 Vec_PtrPush( vVisited, pNext );
00125 }
00126 assert( Vec_PtrSize(vFront) <= nSizeLimit );
00127
00128 return 1;
00129 }
00130
00142 void Aig_ManFindCut( Aig_Obj_t * pRoot, Vec_Ptr_t * vFront, Vec_Ptr_t * vVisited, int nSizeLimit, int nFanoutLimit )
00143 {
00144 Aig_Obj_t * pNode;
00145 int i;
00146
00147 assert( !Aig_IsComplement(pRoot) );
00148 assert( Aig_ObjIsNode(pRoot) );
00149 assert( Aig_ObjChild0(pRoot) );
00150 assert( Aig_ObjChild1(pRoot) );
00151
00152
00153 Vec_PtrClear( vFront );
00154 Vec_PtrPush( vFront, Aig_ObjFanin0(pRoot) );
00155 Vec_PtrPush( vFront, Aig_ObjFanin1(pRoot) );
00156
00157
00158 Vec_PtrClear( vVisited );
00159 Vec_PtrPush( vVisited, pRoot );
00160 Vec_PtrPush( vVisited, Aig_ObjFanin0(pRoot) );
00161 Vec_PtrPush( vVisited, Aig_ObjFanin1(pRoot) );
00162
00163
00164 assert( !pRoot->fMarkA );
00165 assert( !Aig_ObjFanin0(pRoot)->fMarkA );
00166 assert( !Aig_ObjFanin1(pRoot)->fMarkA );
00167 pRoot->fMarkA = 1;
00168 Aig_ObjFanin0(pRoot)->fMarkA = 1;
00169 Aig_ObjFanin1(pRoot)->fMarkA = 1;
00170
00171
00172 while ( Aig_ManFindCut_int( vFront, vVisited, nSizeLimit, nFanoutLimit ) );
00173 assert( Vec_PtrSize(vFront) <= nSizeLimit );
00174
00175
00176 Vec_PtrForEachEntry( vVisited, pNode, i )
00177 pNode->fMarkA = 0;
00178 }
00179
00183
00184