00001
00021 #include "abc.h"
00022 #include "sim.h"
00023 #include "fraig.h"
00024
00028
00029 static int Sim_SymmsSatProveOne( Sym_Man_t * p, int Out, int Var1, int Var2, unsigned * pPattern );
00030
00034
00048 int Sim_SymmsGetPatternUsingSat( Sym_Man_t * p, unsigned * pPattern )
00049 {
00050 Vec_Int_t * vSupport;
00051 Extra_BitMat_t * pMatSym, * pMatNonSym;
00052 int Index1, Index2, Index3, IndexU, IndexV;
00053 int v, u, i, k, b, out;
00054
00055
00056 for ( out = p->iOutput; out < p->nOutputs; out++ )
00057 {
00058 pMatSym = Vec_PtrEntry( p->vMatrSymms, out );
00059 pMatNonSym = Vec_PtrEntry( p->vMatrNonSymms, out );
00060
00061
00062 vSupport = Vec_VecEntry( p->vSupports, out );
00063 Vec_IntForEachEntry( vSupport, v, Index1 )
00064 Vec_IntForEachEntryStart( vSupport, u, Index2, Index1+1 )
00065 {
00066 if ( Extra_BitMatrixLookup1( pMatSym, v, u ) || Extra_BitMatrixLookup1( pMatNonSym, v, u ) )
00067 continue;
00068 p->nSatRuns++;
00069
00070
00071 Vec_IntClear( p->vVarsU );
00072 Vec_IntClear( p->vVarsV );
00073 Vec_IntForEachEntry( vSupport, b, Index3 )
00074 {
00075 if ( Extra_BitMatrixLookup1( pMatSym, u, b ) )
00076 Vec_IntPush( p->vVarsU, b );
00077 if ( Extra_BitMatrixLookup1( pMatSym, v, b ) )
00078 Vec_IntPush( p->vVarsV, b );
00079 }
00080
00081 if ( Sim_SymmsSatProveOne( p, out, v, u, pPattern ) )
00082 {
00083 p->nSatRunsUnsat++;
00084 Vec_IntForEachEntry( p->vVarsU, i, IndexU )
00085 Vec_IntForEachEntry( p->vVarsV, k, IndexV )
00086 {
00087 Extra_BitMatrixInsert1( pMatSym, i, k );
00088 Extra_BitMatrixInsert2( pMatSym, i, k );
00089 Extra_BitMatrixOrTwo( pMatNonSym, i, k );
00090 }
00091 }
00092 else
00093 {
00094 p->nSatRunsSat++;
00095 Vec_IntForEachEntry( p->vVarsU, i, IndexU )
00096 Vec_IntForEachEntry( p->vVarsV, k, IndexV )
00097 {
00098 Extra_BitMatrixInsert1( pMatNonSym, i, k );
00099 Extra_BitMatrixInsert2( pMatNonSym, i, k );
00100 }
00101
00102
00103 p->iOutput = out;
00104 p->iVar1Old = p->iVar1;
00105 p->iVar2Old = p->iVar2;
00106 p->iVar1 = v;
00107 p->iVar2 = u;
00108 return 1;
00109
00110 }
00111 }
00112
00113 assert( Extra_BitMatrixIsClique( pMatSym ) );
00114 }
00115
00116
00117 p->iOutput = p->nOutputs;
00118 return 0;
00119 }
00120
00132 int Sim_SymmsSatProveOne( Sym_Man_t * p, int Out, int Var1, int Var2, unsigned * pPattern )
00133 {
00134 Fraig_Params_t Params;
00135 Fraig_Man_t * pMan;
00136 Abc_Ntk_t * pMiter;
00137 int RetValue, i, clk;
00138 int * pModel;
00139
00140
00141 pMiter = Abc_NtkMiterForCofactors( p->pNtk, Out, Var1, Var2 );
00142
00143 Fraig_ParamsSetDefault( &Params );
00144 Params.fInternal = 1;
00145 Params.nPatsRand = 512;
00146 Params.nPatsDyna = 512;
00147 Params.nSeconds = ABC_INFINITY;
00148
00149 clk = clock();
00150 pMan = Abc_NtkToFraig( pMiter, &Params, 0, 0 );
00151 p->timeFraig += clock() - clk;
00152 clk = clock();
00153 Fraig_ManProveMiter( pMan );
00154 p->timeSat += clock() - clk;
00155
00156
00157 RetValue = Fraig_ManCheckMiter( pMan );
00158
00159
00160 if ( RetValue == 0 )
00161 {
00162
00163 pModel = Fraig_ManReadModel( pMan );
00164 assert( pModel != NULL );
00165
00166
00167 for ( i = 0; i < p->nSimWords; i++ )
00168 pPattern[i] = 0;
00169 for ( i = 0; i < p->nInputs; i++ )
00170 if ( pModel[i] )
00171 Sim_SetBit( pPattern, i );
00172
00173 Sim_SetBit( pPattern, Var1 );
00174 Sim_SetBit( pPattern, Var2 );
00175 }
00176 else if ( RetValue == -1 )
00177 {
00178
00179
00180
00181
00182
00183
00184 memset( pPattern, 0, sizeof(unsigned) * p->nSimWords );
00185 RetValue = 0;
00186 }
00187
00188 Fraig_ManFree( pMan );
00189
00190 Abc_NtkDelete( pMiter );
00191 return RetValue;
00192 }
00193
00194
00198
00199