00001
00021 #include "abc.h"
00022
00023
00024
00025
00026
00027
00028
00029
00030
00034
00035 static void Abc_NtkModelToVector( Abc_Ntk_t * pNtk, Vec_Int_t * vPiValues );
00036 static void Abc_NtkVectorClearPars( Vec_Int_t * vPiValues, int nPars );
00037 static void Abc_NtkVectorClearVars( Abc_Ntk_t * pNtk, Vec_Int_t * vPiValues, int nPars );
00038 static void Abc_NtkVectorPrintPars( Vec_Int_t * vPiValues, int nPars );
00039 static void Abc_NtkVectorPrintVars( Abc_Ntk_t * pNtk, Vec_Int_t * vPiValues, int nPars );
00040
00044
00058 void Abc_NtkQbf( Abc_Ntk_t * pNtk, int nPars, int fVerbose )
00059 {
00060 Abc_Ntk_t * pNtkVer, * pNtkSyn, * pNtkSyn2, * pNtkTemp;
00061 Vec_Int_t * vPiValues;
00062 int clkTotal = clock(), clkS, clkV;
00063 int nIters, nIterMax = 500, nInputs, RetValue, fFound = 0;
00064
00065 assert( Abc_NtkIsStrash(pNtk) );
00066 assert( Abc_NtkIsComb(pNtk) );
00067 assert( Abc_NtkPoNum(pNtk) == 1 );
00068 assert( nPars > 0 && nPars < Abc_NtkPiNum(pNtk) );
00069 assert( Abc_NtkPiNum(pNtk)-nPars < 32 );
00070 nInputs = Abc_NtkPiNum(pNtk) - nPars;
00071
00072
00073 vPiValues = Vec_IntStart( Abc_NtkPiNum(pNtk) );
00074 Abc_NtkVectorClearPars( vPiValues, nPars );
00075 pNtkSyn = Abc_NtkMiterCofactor( pNtk, vPiValues );
00076 if ( fVerbose )
00077 {
00078 printf( "Iter %2d : ", 0 );
00079 printf( "AIG = %6d ", Abc_NtkNodeNum(pNtkSyn) );
00080 Abc_NtkVectorPrintVars( pNtk, vPiValues, nPars );
00081 printf( "\n" );
00082 }
00083
00084
00085 for ( nIters = 0; nIters < nIterMax; nIters++ )
00086 {
00087
00088 clkS = clock();
00089 RetValue = Abc_NtkMiterSat( pNtkSyn, 0, 0, 0, NULL, NULL );
00090 clkS = clock() - clkS;
00091 if ( RetValue == 0 )
00092 Abc_NtkModelToVector( pNtkSyn, vPiValues );
00093 if ( RetValue == 1 )
00094 {
00095 break;
00096 }
00097 if ( RetValue == -1 )
00098 {
00099 printf( "Synthesis timed out.\n" );
00100 break;
00101 }
00102
00103
00104
00105 Abc_NtkVectorClearVars( pNtk, vPiValues, nPars );
00106 pNtkVer = Abc_NtkMiterCofactor( pNtk, vPiValues );
00107
00108 Abc_ObjXorFaninC( Abc_NtkPo(pNtkVer,0), 0 );
00109
00110
00111 clkV = clock();
00112 RetValue = Abc_NtkMiterSat( pNtkVer, 0, 0, 0, NULL, NULL );
00113 clkV = clock() - clkV;
00114 if ( RetValue == 0 )
00115 Abc_NtkModelToVector( pNtkVer, vPiValues );
00116 Abc_NtkDelete( pNtkVer );
00117 if ( RetValue == 1 )
00118 {
00119 fFound = 1;
00120 break;
00121 }
00122 if ( RetValue == -1 )
00123 {
00124 printf( "Verification timed out.\n" );
00125 break;
00126 }
00127
00128
00129
00130 Abc_NtkVectorClearPars( vPiValues, nPars );
00131 pNtkSyn2 = Abc_NtkMiterCofactor( pNtk, vPiValues );
00132
00133 pNtkSyn = Abc_NtkMiterAnd( pNtkTemp = pNtkSyn, pNtkSyn2, 0, 0 );
00134 Abc_NtkDelete( pNtkSyn2 );
00135 Abc_NtkDelete( pNtkTemp );
00136
00137 if ( fVerbose )
00138 {
00139 printf( "Iter %2d : ", nIters+1 );
00140 printf( "AIG = %6d ", Abc_NtkNodeNum(pNtkSyn) );
00141 Abc_NtkVectorPrintVars( pNtk, vPiValues, nPars );
00142 printf( " " );
00143
00144 PRT( "Ver", clkV );
00145 }
00146 }
00147 Abc_NtkDelete( pNtkSyn );
00148
00149 if ( fFound )
00150 {
00151 printf( "Parameters: " );
00152 Abc_NtkVectorPrintPars( vPiValues, nPars );
00153 printf( "\n" );
00154 printf( "Solved after %d interations. ", nIters );
00155 }
00156 else if ( nIters == nIterMax )
00157 printf( "Unsolved after %d interations. ", nIters );
00158 else
00159 printf( "Implementation does not exist. " );
00160 PRT( "Total runtime", clock() - clkTotal );
00161 Vec_IntFree( vPiValues );
00162 }
00163
00164
00176 void Abc_NtkModelToVector( Abc_Ntk_t * pNtk, Vec_Int_t * vPiValues )
00177 {
00178 int * pModel, i;
00179 pModel = pNtk->pModel;
00180 for ( i = 0; i < Abc_NtkPiNum(pNtk); i++ )
00181 Vec_IntWriteEntry( vPiValues, i, pModel[i] );
00182 }
00183
00195 void Abc_NtkVectorClearPars( Vec_Int_t * vPiValues, int nPars )
00196 {
00197 int i;
00198 for ( i = 0; i < nPars; i++ )
00199 Vec_IntWriteEntry( vPiValues, i, -1 );
00200 }
00201
00213 void Abc_NtkVectorClearVars( Abc_Ntk_t * pNtk, Vec_Int_t * vPiValues, int nPars )
00214 {
00215 int i;
00216 for ( i = nPars; i < Abc_NtkPiNum(pNtk); i++ )
00217 Vec_IntWriteEntry( vPiValues, i, -1 );
00218 }
00219
00231 void Abc_NtkVectorPrintPars( Vec_Int_t * vPiValues, int nPars )
00232 {
00233 int i;
00234 for ( i = 0; i < nPars; i++ )
00235 printf( "%d", Vec_IntEntry(vPiValues,i) );
00236 }
00237
00249 void Abc_NtkVectorPrintVars( Abc_Ntk_t * pNtk, Vec_Int_t * vPiValues, int nPars )
00250 {
00251 int i;
00252 for ( i = nPars; i < Abc_NtkPiNum(pNtk); i++ )
00253 printf( "%d", Vec_IntEntry(vPiValues,i) );
00254 }
00255
00259
00260