abc/src/base/abci/abcPrint.c
/**Function*************************************************************

  Synopsis    [If the network is best, saves it in "best.blif" and returns 1.]

  Description [If the networks are incomparable, saves the new network, 
  returns its parameters in the internal parameter structure, and returns 1.
  If the new network is not a logic network, quits without saving and returns 0.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Function
Synopsis    [If the network is best, saves it in "best.blif" and returns 1.]

Description [If the networks are incomparable, saves the new network,
returns its parameters in the internal parameter structure, and returns 1.
If the new network is not a logic network, quits without saving and returns 0.]




Function Synopsis [ If the network is best saves it in " best . blif " and returns 1 . ] Description [ If the networks are incomparable saves the new network returns its parameters in the internal parameter structure and returns 1 . If the new network is not a logic network quits without saving and returns 0 . ]
int Abc_NtkCompareAndSaveBest( Abc_Ntk_t * pNtk )
{
    extern void Io_Write( Abc_Ntk_t * pNtk, char * pFileName, Io_FileType_t FileType );
    static struct ParStruct {
        char * pName;  
        int    Depth;  
        int    Flops;  
        int    Nodes;  
        int    Edges;  
        int    nPis;   
        int    nPos;   
    } ParsNew, ParsBest = { 0 };
    char * pFileNameOut;
    if ( pNtk == NULL )
    {
        ABC_FREE( ParsBest.pName );
        return 0;
    }
    if ( !Abc_NtkIsLogic(pNtk) )
        return 0;
    ParsNew.Depth = Abc_NtkLevel( pNtk );
    ParsNew.Flops = Abc_NtkLatchNum( pNtk );
    ParsNew.Nodes = Abc_NtkNodeNum( pNtk );
    ParsNew.Edges = Abc_NtkGetTotalFanins( pNtk );
    ParsNew.nPis  = Abc_NtkPiNum( pNtk );
    ParsNew.nPos  = Abc_NtkPoNum( pNtk );
    if (  ParsBest.pName == NULL ||
          strcmp(ParsBest.pName, pNtk->pName) ||
          ParsBest.Depth >  ParsNew.Depth ||
         (ParsBest.Depth == ParsNew.Depth && ParsBest.Flops >  ParsNew.Flops) ||
         (ParsBest.Depth == ParsNew.Depth && ParsBest.Flops == ParsNew.Flops && ParsBest.Edges >  ParsNew.Edges) )
    {
        ABC_FREE( ParsBest.pName );
        ParsBest.pName = Extra_UtilStrsav( pNtk->pName );
        ParsBest.Depth = ParsNew.Depth;
        ParsBest.Flops = ParsNew.Flops;
        ParsBest.Nodes = ParsNew.Nodes;
        ParsBest.Edges = ParsNew.Edges;
        ParsBest.nPis  = ParsNew.nPis;
        ParsBest.nPos  = ParsNew.nPos;
        if ( strcmp(pNtk->pSpec + strlen(pNtk->pSpec) - strlen("_best.blif"), "_best.blif") )
            pFileNameOut = Extra_FileNameGenericAppend( pNtk->pSpec, "_best.blif" );
        else
            pFileNameOut = pNtk->pSpec;
        Io_Write( pNtk, pFileNameOut, IO_FILE_BLIF );
        return 1;
    }
    return 0;
}
int Abc_NtkCompareAndSaveBest ( Abc_Ntk_t * pNtk ) { extern void Io_Write ( Abc_Ntk_t * pNtk , char * pFileName , Io_FileType_t FileType ) ; static struct ParStruct { char * pName ; int Depth ; int Flops ; int Nodes ; int Edges ; int nPis ; int nPos ; } ParsNew , ParsBest = { 0 } ; char * pFileNameOut ; if ( pNtk == NULL ) { ABC_FREE ( ParsBest . pName ) ; return 0 ; } if ( ! Abc_NtkIsLogic ( pNtk ) ) return 0 ; ParsNew . Depth = Abc_NtkLevel ( pNtk ) ; ParsNew . Flops = Abc_NtkLatchNum ( pNtk ) ; ParsNew . Nodes = Abc_NtkNodeNum ( pNtk ) ; ParsNew . Edges = Abc_NtkGetTotalFanins ( pNtk ) ; ParsNew . nPis = Abc_NtkPiNum ( pNtk ) ; ParsNew . nPos = Abc_NtkPoNum ( pNtk ) ; if ( ParsBest . pName == NULL || strcmp ( ParsBest . pName , pNtk -> pName ) || ParsBest . Depth > ParsNew . Depth || ( ParsBest . Depth == ParsNew . Depth && ParsBest . Flops > ParsNew . Flops ) || ( ParsBest . Depth == ParsNew . Depth && ParsBest . Flops == ParsNew . Flops && ParsBest . Edges > ParsNew . Edges ) ) { ABC_FREE ( ParsBest . pName ) ; ParsBest . pName = Extra_UtilStrsav ( pNtk -> pName ) ; ParsBest . Depth = ParsNew . Depth ; ParsBest . Flops = ParsNew . Flops ; ParsBest . Nodes = ParsNew . Nodes ; ParsBest . Edges = ParsNew . Edges ; ParsBest . nPis = ParsNew . nPis ; ParsBest . nPos = ParsNew . nPos ; if ( strcmp ( pNtk -> pSpec + strlen ( pNtk -> pSpec ) - strlen ( " " ) , " " ) ) pFileNameOut = Extra_FileNameGenericAppend ( pNtk -> pSpec , " " ) ; else pFileNameOut = pNtk -> pSpec ; Io_Write ( pNtk , pFileNameOut , IO_FILE_BLIF ) ; return 1 ; } return 0 ; }
Function
Synopsis    [If the network is best, saves it in "best.blif" and returns 1.]
Function Synopsis [ If the network is best saves it in " best . blif " and returns 1 . ]
// name of the best saved network // depth of the best saved network // flops in the best saved network  // nodes in the best saved network // edges in the best saved network // the number of primary inputs // the number of primary outputs // free storage for the name // quit if not a logic network // get the parameters // reset the parameters if the network has the same name // writ the network