abc/src/aig/ivy/ivyCut.c
/**Function*************************************************************

  Synopsis    [Builds reconvergence-driven cut by changing one leaf at a time.]

  Description [This procedure looks at the current leaves and tries to change 
  one leaf at a time in such a way that the cut grows as little as possible.
  In evaluating the fanins, this procedure looks only at their immediate 
  predecessors (this is why it is called a one-level construction procedure).]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Function
Synopsis    [Builds reconvergence-driven cut by changing one leaf at a time.]

Description [This procedure looks at the current leaves and tries to change
one leaf at a time in such a way that the cut grows as little as possible.
In evaluating the fanins, this procedure looks only at their immediate
predecessors (this is why it is called a one-level construction procedure).]




Function Synopsis [ Builds reconvergence - driven cut by changing one leaf at a time . ] Description [ This procedure looks at the current leaves and tries to change one leaf at a time in such a way that the cut grows as little as possible . In evaluating the fanins this procedure looks only at their immediate predecessors ( this is why it is called a one - level construction procedure ) . ]
int Ivy_ManSeqFindCut_int( Ivy_Man_t * p, Vec_Int_t * vFront, Vec_Int_t * vInside, int nSizeLimit )
{
    Ivy_Obj_t * pNode;
    int CostBest, CostCur, Leaf, LeafBest, Next, nLatches, i;
    int LeavesBest[10];
    int Counter;
    CostBest = 99;
    LeafBest = -1;
    Counter = -1;
    Vec_IntForEachEntry( vFront, Leaf, i )
    {
        CostCur = Ivy_NodeGetLeafCostOne( p, Leaf, vInside );
        if ( CostBest > CostCur )
        {
            CostBest = CostCur;
            LeafBest = Leaf;
            LeavesBest[0] = Leaf;
            Counter = 1;
        }
        else if ( CostBest == CostCur )
            LeavesBest[Counter++] = Leaf;
        if ( CostBest <= 1 ) 
            break;
    }
    if ( CostBest == 99 )
        return 0;
    assert( CostBest < 3 );
    if ( Vec_IntSize(vFront) - 1 + CostBest > nSizeLimit )
        return 0;
    assert( Counter > 0 );
printf( "%d", Counter );
    LeafBest = LeavesBest[rand() % Counter];
    assert( LeafBest >= 0 );
    Vec_IntRemove( vFront, LeafBest );
    pNode = Ivy_ManObj( p, Ivy_LeafId(LeafBest) );
    nLatches = Ivy_LeafLat(LeafBest) + Ivy_ObjIsLatch(pNode);
    assert( Ivy_ObjIsNode(pNode) || Ivy_ObjIsLatch(pNode) || Ivy_ObjIsBuf(pNode) );
    Next = Ivy_LeafCreate( Ivy_ObjFaninId0(pNode), nLatches );
    if ( Next && Vec_IntFind(vInside, Next) == -1 )
    {
        Vec_IntPush( vFront, Next );
        Vec_IntPush( vInside, Next );
    }
    if ( Ivy_ObjIsLatch(pNode) || Ivy_ObjIsBuf(pNode) )
        return 1;
    assert( Ivy_ObjIsNode(pNode) );
    Next = Ivy_LeafCreate( Ivy_ObjFaninId1(pNode), nLatches );
    if ( Next && Vec_IntFind(vInside, Next) == -1 )
    {
        Vec_IntPush( vFront, Next );
        Vec_IntPush( vInside, Next );
    }
    assert( Vec_IntSize(vFront) <= nSizeLimit );
    return 1;
}
int Ivy_ManSeqFindCut_int ( Ivy_Man_t * p , Vec_Int_t * vFront , Vec_Int_t * vInside , int nSizeLimit ) { Ivy_Obj_t * pNode ; int CostBest , CostCur , Leaf , LeafBest , Next , nLatches , i ; int LeavesBest [ 10 ] ; int Counter ; CostBest = 99 ; LeafBest = -1 ; Counter = -1 ; Vec_IntForEachEntry ( vFront , Leaf , i ) { CostCur = Ivy_NodeGetLeafCostOne ( p , Leaf , vInside ) ; if ( CostBest > CostCur ) { CostBest = CostCur ; LeafBest = Leaf ; LeavesBest [ 0 ] = Leaf ; Counter = 1 ; } else if ( CostBest == CostCur ) LeavesBest [ Counter ++ ] = Leaf ; if ( CostBest <= 1 ) break ; } if ( CostBest == 99 ) return 0 ; assert ( CostBest < 3 ) ; if ( Vec_IntSize ( vFront ) - 1 + CostBest > nSizeLimit ) return 0 ; assert ( Counter > 0 ) ; printf ( " " , Counter ) ; LeafBest = LeavesBest [ rand ( ) % Counter ] ; assert ( LeafBest >= 0 ) ; Vec_IntRemove ( vFront , LeafBest ) ; pNode = Ivy_ManObj ( p , Ivy_LeafId ( LeafBest ) ) ; nLatches = Ivy_LeafLat ( LeafBest ) + Ivy_ObjIsLatch ( pNode ) ; assert ( Ivy_ObjIsNode ( pNode ) || Ivy_ObjIsLatch ( pNode ) || Ivy_ObjIsBuf ( pNode ) ) ; Next = Ivy_LeafCreate ( Ivy_ObjFaninId0 ( pNode ) , nLatches ) ; if ( Next && Vec_IntFind ( vInside , Next ) == -1 ) { Vec_IntPush ( vFront , Next ) ; Vec_IntPush ( vInside , Next ) ; } if ( Ivy_ObjIsLatch ( pNode ) || Ivy_ObjIsBuf ( pNode ) ) return 1 ; assert ( Ivy_ObjIsNode ( pNode ) ) ; Next = Ivy_LeafCreate ( Ivy_ObjFaninId1 ( pNode ) , nLatches ) ; if ( Next && Vec_IntFind ( vInside , Next ) == -1 ) { Vec_IntPush ( vFront , Next ) ; Vec_IntPush ( vInside , Next ) ; } assert ( Vec_IntSize ( vFront ) <= nSizeLimit ) ; return 1 ; }
Function
Synopsis    [Builds reconvergence-driven cut by changing one leaf at a time.]
Function Synopsis [ Builds reconvergence - driven cut by changing one leaf at a time . ]
// add random selection of the best fanin!!! // find the best fanin //printf( "Evaluating fanins of the cut:\n" ); //printf( "    Fanin %s has cost %d.\n", Ivy_ObjName(pNode), CostCur ); // can be if ( CostBest <= 1 ) //        return Ivy_NodeBuildCutLevelTwo_int( vInside, vFront, nFaninLimit ); //        return Ivy_NodeBuildCutLevelTwo_int( vInside, vFront, nFaninLimit ); // remove the node from the array //printf( "Removing fanin %s.\n", Ivy_ObjName(pNode) ); // get the node and its latches // add the left child to the fanins //printf( "Adding fanin %s.\n", Ivy_ObjName(pNext) ); // quit if this is the one fanin node // add the right child to the fanins //printf( "Adding fanin %s.\n", Ivy_ObjName(pNext) ); // keep doing this