51 int i, Id;
word Sim, Sim0, Sim1;
54 Sim = Vec_IntEntry(vPat, i) ? ~(
word)0 : 0;
55 Sim ^= (
word)1 << (i + 1);
56 Vec_WrdWriteEntry(
p->vSims, Id, Sim );
60 Sim0 = Vec_WrdEntry(
p->vSims, Gia_ObjFaninId0(pObj, i) );
61 Sim1 = Vec_WrdEntry(
p->vSims, Gia_ObjFaninId1(pObj, i) );
62 Sim0 = Gia_ObjFaninC0(pObj) ? ~Sim0 : Sim0;
63 Sim1 = Gia_ObjFaninC1(pObj) ? ~Sim1 : Sim1;
64 Vec_WrdWriteEntry(
p->vSims, i, Sim0 & Sim1 );
68 Id = Gia_ObjId(
p, pObj );
69 Sim0 = Vec_WrdEntry(
p->vSims, Gia_ObjFaninId0(pObj, Id) );
70 Sim0 = Gia_ObjFaninC0(pObj) ? ~Sim0 : Sim0;
71 Vec_WrdWriteEntry(
p->vSims, Id, Sim0 );
73 pObj = Gia_ManCo(
p, 0 );
74 Sim = Vec_WrdEntry(
p->vSims, Gia_ObjId(
p, pObj) );
75 Vec_IntClear( vPat2 );
76 for ( i = 1; i <= Gia_ManCiNum(
p); i++ )
77 Vec_IntPush( vPat2, (
int)((Sim & 1) ^ ((Sim >> i) & 1)) );
78 return (
int)(Sim & 1);
82 int i, v, w, Res, Bit, Bit2, nPats = 256;
83 int Count[2][64][64] = {{{0}}};
84 int PatCount[64][2][2] = {{{0}}};
85 int DiffCount[64] = {0};
86 Vec_Int_t * vPat = Vec_IntAlloc( Gia_ManCiNum(
p) );
87 Vec_Int_t * vPat2 = Vec_IntAlloc( Gia_ManCiNum(
p) );
88 Vec_WrdFreeP( &
p->vSims );
89 p->vSims = Vec_WrdStart( Gia_ManObjNum(
p) );
90 printf(
"Number of patterns = %d.\n", nPats );
91 for ( i = 0; i < nPats; i++ )
94 for ( v = 0; v < Gia_ManCiNum(
p); v++ )
95 Vec_IntPush( vPat, rand() & 1 );
109 PatCount[v][Res][Bit]++;
121 Vec_IntFree( vPat2 );
122 Vec_WrdFreeP( &
p->vSims );
127 for ( v = 0; v < Gia_ManCiNum(
p); v++ )
128 printf(
"%3c ",
'a'+v );
132 for ( v = 0; v < Gia_ManCiNum(
p); v++ )
133 printf(
"%3d ", PatCount[v][0][0] );
137 for ( v = 0; v < Gia_ManCiNum(
p); v++ )
138 printf(
"%3d ", PatCount[v][0][1] );
142 for ( v = 0; v < Gia_ManCiNum(
p); v++ )
143 printf(
"%3d ", PatCount[v][1][0] );
147 for ( v = 0; v < Gia_ManCiNum(
p); v++ )
148 printf(
"%3d ", PatCount[v][1][1] );
153 for ( v = 0; v < Gia_ManCiNum(
p); v++ )
154 printf(
"%3d ", DiffCount[v] );
158 for ( i = 0; i < 2; i++ )
161 for ( v = 0; v < Gia_ManCiNum(
p); v++ )
162 printf(
"%3c ",
'a'+v );
165 for ( v = 0; v < Gia_ManCiNum(
p); v++ )
167 printf(
" %c ",
'a'+v );
168 for ( w = 0; w < Gia_ManCiNum(
p); w++ )
170 if ( Count[i][v][w] )
171 printf(
"%3d ", Count[i][v][w] );
188#define Bmc_SopForEachCube( pSop, nVars, pCube ) for ( pCube = (pSop); *pCube; pCube += (nVars) + 3 )
206 int i, k, status, iLit, nRemoved = 0;
209 char * pCube, * pSop = Vec_StrArray(vSop);
210 Vec_Ptr_t * vCubes = Vec_PtrAlloc(nCubes);
211 assert( Vec_StrSize(vSop) == nCubes * (nVars + 3) + 1 );
213 Vec_PtrPush( vCubes, pCube );
221 Vec_IntClear( vLits );
222 for ( k = 0; k < nVars; k++ )
223 if ( pCube[k] !=
'-' )
224 Vec_IntPush( vLits, Abc_Var2Lit(k, pCube[k] ==
'1') );
228 status =
sat_solver_solve( pSat, Vec_IntArray(vLits), Vec_IntLimit(vLits), nBTLimit, 0, 0, 0 );
233 Vec_PtrWriteEntry( vCubes, i, NULL );
240 Vec_IntWriteEntry( vLits, k, Abc_LitNot(iLit) );
247 if ( i == -1 && nRemoved > 0 )
252 for ( k = 0; k < nVars + 3; k++ )
253 Vec_StrWriteEntry( vSop, j++, pCube[k] );
254 Vec_StrWriteEntry( vSop, j++,
'\0' );
255 Vec_StrShrink( vSop, j );
258 Vec_PtrFree( vCubes );
259 Vec_IntFree( vLits );
260 return i == -1 ? 1 : 0;
279 int i, k, status, nRemoved = 0;
280 Vec_Int_t * vLits = Vec_IntAlloc(nVars+nCubes);
282 char * pCube, * pSop = Vec_StrArray(vSop);
283 Vec_Ptr_t * vCubes = Vec_PtrAlloc(nCubes);
284 assert( Vec_StrSize(vSop) == nCubes * (nVars + 3) + 1 );
286 Vec_PtrPush( vCubes, pCube );
294 Vec_IntFill( vLits, 1, Abc_Var2Lit(nVars + i, 1) );
295 for ( k = 0; k < nVars; k++ )
296 if ( pCube[k] !=
'-' )
297 Vec_IntPush( vLits, Abc_Var2Lit(k, pCube[k] ==
'0') );
306 Vec_IntClear( vLits );
307 for ( k = 0; k < nCubes; k++ )
308 if ( k != i && Vec_PtrEntry(vCubes, k) )
309 Vec_IntPush( vLits, Abc_Var2Lit(nVars + k, 0) );
311 for ( k = 0; k < nVars; k++ )
312 if ( pCube[k] !=
'-' )
313 Vec_IntPush( vLits, Abc_Var2Lit(k, pCube[k] ==
'1') );
316 status =
sat_solver_solve( pSat, Vec_IntArray(vLits), Vec_IntLimit(vLits), nBTLimit, 0, 0, 0 );
321 Vec_PtrWriteEntry( vCubes, i, NULL );
329 if ( i == Vec_PtrSize(vCubes) && nRemoved > 0 )
334 for ( k = 0; k < nVars + 3; k++ )
335 Vec_StrWriteEntry( vSop, j++, pCube[k] );
336 Vec_StrWriteEntry( vSop, j++,
'\0' );
337 Vec_StrShrink( vSop, j );
340 Vec_PtrFree( vCubes );
341 Vec_IntFree( vLits );
342 return i == -1 ? 1 : 0;
360 Vec_IntClear( vTemp );
363 Vec_IntPush( vTemp, iLit );
364 assert( Vec_IntSize(vTemp) > 0 );
366 if ( fOnOffSetLit >= 0 )
370 Vec_IntShrink( vTemp, nLits );
372 if ( fOnOffSetLit >= 0 )
376 if ( iLit != -1 && Vec_IntFind(vTemp, iLit) == -1 )
377 Vec_IntWriteEntry( vLits, i, -1 );
384 int k, n, iLit, status;
388 for ( k = Vec_IntSize(vLits) - 1; k >= 0; k-- )
390 int Save = Vec_IntEntry( vLits, k );
396 assert( fOnOffSetLit == -1 );
398 if ( fCanon && !Abc_LitIsCompl(Save) )
401 Vec_IntClear( vTemp );
404 Vec_IntPush( vTemp, Abc_LitNotCond(iLit, k==n) );
406 if ( fProfile ) clk = Abc_Clock();
407 status =
sat_solver_solve( pSatOn, Vec_IntArray(vTemp), Vec_IntLimit(vTemp), nBTLimit, 0, 0, 0 );
408 if ( fProfile ) clkCheck1 += Abc_Clock() - clk;
414 if ( fProfile ) clkCheckU += Abc_Clock() - clk;
417 if ( fProfile ) clkCheckS += Abc_Clock() - clk;
420 Vec_IntWriteEntry( vLits, k, -1 );
422 Vec_IntClear( vTemp );
423 if ( fOnOffSetLit >= 0 )
424 Vec_IntPush( vTemp, fOnOffSetLit );
427 Vec_IntPush( vTemp, iLit );
429 if ( fProfile ) clk = Abc_Clock();
430 status =
sat_solver_solve( pSat, Vec_IntArray(vTemp), Vec_IntLimit(vTemp), nBTLimit, 0, 0, 0 );
431 if ( fProfile ) clkCheck2 += Abc_Clock() - clk;
438 Vec_IntWriteEntry( vLits, k, Save );
439 if ( fProfile ) clkCheckS += Abc_Clock() - clk;
442 if ( fProfile ) clkCheckU += Abc_Clock() - clk;
465 int i, k, iLit, status, nFinal, * pFinal;
467 if ( fOnOffSetLit >= 0 )
468 Vec_IntPush( vLits, fOnOffSetLit );
469 status =
sat_solver_solve( pSat, Vec_IntArray(vLits), Vec_IntLimit(vLits), nBTLimit, 0, 0, 0 );
470 if ( fOnOffSetLit >= 0 )
476 nFinal = sat_solver_final( pSat, &pFinal );
480 for ( k = 0; k < nFinal; k++ )
481 if ( iLit == Abc_LitNot(pFinal[k]) )
484 Vec_IntWriteEntry( vLits, i, -1 );
499 Vec_IntClear( vNums );
502 Vec_IntPush( vNums, i );
512 int i, k, iLit, j, iNum, status, nFinal, * pFinal;
515 if ( fOnOffSetLit >= 0 )
516 Vec_IntPush( vLits, fOnOffSetLit );
517 status =
sat_solver_solve( pSat, Vec_IntArray(vLits), Vec_IntLimit(vLits), nBTLimit, 0, 0, 0 );
518 if ( fOnOffSetLit >= 0 )
525 nFinal = sat_solver_final( pSat, &pFinal );
526 Vec_IntClear( vNums );
527 Vec_IntClear( vTemp );
528 if ( fOnOffSetLit >= 0 )
531 Vec_IntPush( vTemp, fOnOffSetLit );
535 for ( k = 0; k < nFinal; k++ )
536 if ( iLit == Abc_LitNot(pFinal[k]) )
540 Vec_IntPush( vNums, i );
541 Vec_IntPush( vTemp, iLit );
545 status =
sat_solver_solve( pSat, Vec_IntArray(vTemp), Vec_IntLimit(vTemp), nBTLimit, 0, 0, 0 );
551 nFinal = sat_solver_final( pSat, &pFinal );
555 if ( iLit == fOnOffSetLit )
557 for ( k = 0; k < nFinal; k++ )
558 if ( iLit == Abc_LitNot(pFinal[k]) )
562 Vec_IntWriteEntry( vNums, j++, Vec_IntEntry(vNums, i) );
564 Vec_IntShrink( vNums, j );
568 for ( i = 0; i < Vec_IntSize(vNums); i++ )
570 Vec_IntClear( vTemp );
571 if ( fOnOffSetLit >= 0 )
572 Vec_IntPush( vTemp, fOnOffSetLit );
575 Vec_IntPush( vTemp, Vec_IntEntry(vLits, iNum) );
577 status =
sat_solver_solve( pSat, Vec_IntArray(vTemp), Vec_IntLimit(vTemp), nBTLimit, 0, 0, 0 );
583 Vec_IntDrop( vNums, i );
621 int i, k, iLit, status =
l_Undef;
622 for ( i = 0; i < Vec_IntSize(vLits); i++ )
625 Vec_IntClear( vTemp );
627 Vec_IntPush( vTemp, iLit );
629 status =
sat_solver_solve( pSat, Vec_IntArray(vTemp), Vec_IntLimit(vTemp), nBTLimit, 0, 0, 0 );
635 iLit = Vec_IntEntry( vLits, i );
637 if ( !Abc_LitIsCompl(iLit) )
639 Vec_IntWriteEntry( vLits, i, Abc_LitNot(iLit) );
641 Vec_IntWriteEntry( vLits, k, Abc_LitNot(Abc_LitRegular(iLit)) );
667 int fPrintMinterm = 0;
668 int nVars = Gia_ManCiNum(
p);
669 Vec_Int_t * vVars = Vec_IntAlloc( nVars );
670 Vec_Int_t * vLits = Vec_IntAlloc( nVars );
671 Vec_Int_t * vLitsC= Vec_IntAlloc( nVars );
672 Vec_Int_t * vNums = Vec_IntAlloc( nVars );
673 Vec_Int_t * vCube = Vec_IntAlloc( nVars );
675 int iOut = 0, iLit, iVar, status, n, Count, Start;
686 int iCiVarBeg = pCnf->
nVars - nVars;
688 for ( n = nVars - 1; n >= 0; n-- )
689 Vec_IntPush( vVars, iCiVarBeg + n );
691 for ( n = 0; n < nVars; n++ )
692 Vec_IntPush( vVars, iCiVarBeg + n );
696 Vec_IntPush( vLitsC, Abc_Var2Lit(iVar, 1) );
699 for ( n = 0; n < 2 + fCanon; n++ )
701 iLit = Abc_Var2Lit( iOut + 1, n&1 );
705 Vec_StrPrintStr( vSop, ((n&1) ^ fCompl) ?
" 1\n" :
" 0\n" );
706 Vec_StrPush( vSop,
'\0' );
712 Vec_StrFreeP( &vSop );
717 Vec_StrPrintStr( vSop, ((n&1) ^ fCompl) ?
" 1\n" :
" 0\n" );
718 Vec_StrPush( vSop,
'\0' );
722 Vec_StrPush( vSop,
'\0' );
735 sat_solver_clean_polarity( pSat[0], Vec_IntArray(vVars), Vec_IntSize(vVars) );
740 Vec_StrFreeP( &vSop );
746 if ( nCubeLim > 0 && Count == nCubeLim )
749 Vec_StrFreeP( &vSop );
753 Vec_IntClear( vLits );
754 Vec_IntClear( vLitsC );
757 iLit = Abc_Var2Lit(iVar, !sat_solver_var_value(pSat[0], iVar));
758 Vec_IntPush( vLits, iLit );
759 Vec_IntPush( vLitsC, iLit );
766 printf(
"%d", !Abc_LitIsCompl(iLit) );
770 status =
Bmc_CollapseExpand( pSat[1], fCanon ? pSat[2] : pSat[0], vLits, vNums, vCube, nBTLimit, fCanon, -1 );
773 Vec_StrFreeP( &vSop );
778 Start = Vec_StrSize( vSop );
779 Vec_StrFillExtra( vSop, Start + nVars + 4,
'-' );
780 Vec_StrWriteEntry( vSop, Start + nVars + 0,
' ' );
781 Vec_StrWriteEntry( vSop, Start + nVars + 1, (
char)(fCompl ?
'0' :
'1') );
782 Vec_StrWriteEntry( vSop, Start + nVars + 2,
'\n' );
783 Vec_StrWriteEntry( vSop, Start + nVars + 3,
'\0' );
784 Vec_IntClear( vCube );
787 iLit = Vec_IntEntry( vLits, iVar );
788 Vec_IntPush( vCube, Abc_LitNot(iLit) );
790 Vec_StrWriteEntry( vSop, Start + nVars - iVar - 1, (
char)(
'0' + !Abc_LitIsCompl(iLit)) );
792 Vec_StrWriteEntry( vSop, Start + iVar, (
char)(
'0' + !Abc_LitIsCompl(iLit)) );
808 Vec_IntFree( vVars );
809 Vec_IntFree( vLits );
810 Vec_IntFree( vLitsC );
811 Vec_IntFree( vNums );
812 Vec_IntFree( vCube );
830 nCubesOn = Vec_StrCountEntry(vSopOn,
'\n');
831 Gia_ObjFlipFaninC0( Gia_ManPo(
p, 0) );
832 vSopOff =
Bmc_CollapseOneInt2(
p, Abc_MinInt(nCubeLim, nCubesOn), nBTLimit, fCanon, fReverse, fVerbose, 1 );
833 Gia_ObjFlipFaninC0( Gia_ManPo(
p, 0) );
835 nCubesOff = Vec_StrCountEntry(vSopOff,
'\n');
836 if ( vSopOn == NULL )
838 if ( vSopOff == NULL )
840 if ( nCubesOn <= nCubesOff )
842 Vec_StrFree( vSopOff );
847 Vec_StrFree( vSopOn );
866 int fVeryVerbose = fVerbose;
867 int nVars = Gia_ManCiNum(
p);
871 Vec_Str_t * vSop[2] = { Vec_StrAlloc(1000), Vec_StrAlloc(1000) }, * vRes = NULL;
872 Vec_Int_t * vLitsC[2] = { Vec_IntAlloc(nVars), Vec_IntAlloc(nVars) };
873 Vec_Int_t * vVars = Vec_IntAlloc( nVars );
874 Vec_Int_t * vLits = Vec_IntAlloc( nVars );
875 Vec_Int_t * vNums = Vec_IntAlloc( nVars );
876 Vec_Int_t * vCube = Vec_IntAlloc( nVars );
877 int n, v, iVar, iLit, iCiVarBeg, iCube = 0, Start, status;
878 abctime clk = 0, Time[2][2] = {{0}};
879 int fComplete[2] = {0};
882 iCiVarBeg = pCnf->
nVars - nVars;
884 for ( v = nVars - 1; v >= 0; v-- )
885 Vec_IntPush( vVars, iCiVarBeg + v );
887 for ( v = 0; v < nVars; v++ )
888 Vec_IntPush( vVars, iCiVarBeg + v );
891 for ( n = 0; n < 2; n++ )
893 iLit = Abc_Var2Lit( 1, n );
899 Vec_StrClear( vSop[0] );
900 Vec_StrPrintStr( vSop[0], n ?
" 1\n" :
" 0\n" );
901 Vec_StrPush( vSop[0],
'\0' );
907 Vec_IntPush( vLitsC[n], Abc_Var2Lit(iVar, 1) );
914 Vec_StrPush( vSop[n],
'\0' );
918 for ( iCube = 0; nCubeLim == 0 || iCube < nCubeLim; iCube++ )
920 for ( n = 0; n < 2; n++ )
922 if ( fVeryVerbose ) clk = Abc_Clock();
928 sat_solver_clean_polarity( pSat[n], Vec_IntArray(vVars), Vec_IntSize(vVars) );
931 if ( fVeryVerbose ) Time[n][0] += Abc_Clock() - clk;
940 Vec_IntClear( vLits );
941 Vec_IntClear( vLitsC[n] );
944 iLit = Abc_Var2Lit(iVar, !sat_solver_var_value(pSat[n], iVar));
945 Vec_IntPush( vLits, iLit );
946 Vec_IntPush( vLitsC[n], iLit );
949 if ( fVeryVerbose ) clk = Abc_Clock();
950 status =
Bmc_CollapseExpand( pSatClean[!n], pSat[n], vLits, vNums, vCube, nBTLimit, fCanon, -1 );
951 if ( fVeryVerbose ) Time[n][1] += Abc_Clock() - clk;
955 Vec_StrPop( vSop[n] );
956 Start = Vec_StrSize( vSop[n] );
957 Vec_StrFillExtra( vSop[n], Start + nVars + 4,
'-' );
958 Vec_StrWriteEntry( vSop[n], Start + nVars + 0,
' ' );
959 Vec_StrWriteEntry( vSop[n], Start + nVars + 1, (
char)(n ?
'0' :
'1') );
960 Vec_StrWriteEntry( vSop[n], Start + nVars + 2,
'\n' );
961 Vec_StrWriteEntry( vSop[n], Start + nVars + 3,
'\0' );
962 Vec_IntClear( vCube );
965 iLit = Vec_IntEntry( vLits, iVar );
966 Vec_IntPush( vCube, Abc_LitNot(iLit) );
968 Vec_StrWriteEntry( vSop[n], Start + nVars - iVar - 1, (
char)(
'0' + !Abc_LitIsCompl(iLit)) );
970 Vec_StrWriteEntry( vSop[n], Start + iVar, (
char)(
'0' + !Abc_LitIsCompl(iLit)) );
981 if ( fComplete[0] || fComplete[1] )
985 Vec_IntFree( vVars );
986 Vec_IntFree( vLits );
987 Vec_IntFree( vLitsC[0] );
988 Vec_IntFree( vLitsC[1] );
989 Vec_IntFree( vNums );
990 Vec_IntFree( vCube );
996 assert( !fComplete[0] || !fComplete[1] );
997 if ( fComplete[0] || fComplete[1] )
999 vRes = vSop[fComplete[1]]; vSop[fComplete[1]] = NULL;
1007 printf(
"Processed output with %d supp vars. ", nVars );
1009 printf(
"The resulting SOP exceeded %d cubes.\n", nCubeLim );
1011 printf(
"The best cover contains %d cubes.\n", Vec_StrSize(vRes)/(nVars +3) );
1012 Abc_PrintTime( 1,
"Onset minterm", Time[0][0] );
1013 Abc_PrintTime( 1,
"Onset expand ", Time[0][1] );
1014 Abc_PrintTime( 1,
"Offset minterm", Time[1][0] );
1015 Abc_PrintTime( 1,
"Offset expand ", Time[1][1] );
1018 Abc_PrintTime( 1,
"Expand check1 ", clkCheck1 ); clkCheck1 = 0;
1019 Abc_PrintTime( 1,
"Expand check2 ", clkCheck2 ); clkCheck2 = 0;
1020 Abc_PrintTime( 1,
"Expand sat ", clkCheckS ); clkCheckS = 0;
1021 Abc_PrintTime( 1,
"Expand unsat ", clkCheckU ); clkCheckU = 0;
1024 Vec_StrFreeP( &vSop[0] );
1025 Vec_StrFreeP( &vSop[1] );
1042 int fVeryVerbose = fVerbose;
1044 sat_solver * pSatClean[2] = { pSat2, pSat3 };
1045 Vec_Str_t * vSop[2] = { Vec_StrAlloc(1000), Vec_StrAlloc(1000) }, * vRes = NULL;
1046 Vec_Int_t * vLitsC[2] = { Vec_IntAlloc(nVars), Vec_IntAlloc(nVars) };
1047 Vec_Int_t * vVars = Vec_IntAlloc( nVars );
1048 Vec_Int_t * vLits = Vec_IntAlloc( nVars );
1049 Vec_Int_t * vNums = Vec_IntAlloc( nVars );
1050 Vec_Int_t * vCube = Vec_IntAlloc( nVars );
1051 int n, v, iVar, iLit, iCiVarBeg, iCube = 0, Start, status;
1052 abctime clk = 0, Time[2][2] = {{0}};
1053 int fComplete[2] = {0};
1059 for ( v = nVars - 1; v >= 0; v-- )
1060 Vec_IntPush( vVars, iCiVarBeg + v );
1062 for ( v = 0; v < nVars; v++ )
1063 Vec_IntPush( vVars, iCiVarBeg + v );
1066 for ( n = 0; n < 2; n++ )
1068 iLit = Abc_Var2Lit( 1, n );
1074 Vec_StrClear( vSop[0] );
1075 Vec_StrPrintStr( vSop[0], n ?
" 1\n" :
" 0\n" );
1076 Vec_StrPush( vSop[0],
'\0' );
1082 Vec_IntPush( vLitsC[n], Abc_Var2Lit(iVar, 1) );
1089 Vec_StrPush( vSop[n],
'\0' );
1093 for ( iCube = 0; nCubeLim == 0 || iCube < nCubeLim; iCube++ )
1095 for ( n = 0; n < 2; n++ )
1097 if ( fVeryVerbose ) clk = Abc_Clock();
1103 sat_solver_clean_polarity( pSat[n], Vec_IntArray(vVars), Vec_IntSize(vVars) );
1106 if ( fVeryVerbose ) Time[n][0] += Abc_Clock() - clk;
1115 Vec_IntClear( vLits );
1116 Vec_IntClear( vLitsC[n] );
1119 iLit = Abc_Var2Lit(iVar, !sat_solver_var_value(pSat[n], iVar));
1120 Vec_IntPush( vLits, iLit );
1121 Vec_IntPush( vLitsC[n], iLit );
1124 if ( fVeryVerbose ) clk = Abc_Clock();
1125 status =
Bmc_CollapseExpand( pSatClean[!n], pSat[n], vLits, vNums, vCube, nBTLimit, fCanon, -1 );
1126 if ( fVeryVerbose ) Time[n][1] += Abc_Clock() - clk;
1130 Vec_StrPop( vSop[n] );
1131 Start = Vec_StrSize( vSop[n] );
1132 Vec_StrFillExtra( vSop[n], Start + nVars + 4,
'-' );
1133 Vec_StrWriteEntry( vSop[n], Start + nVars + 0,
' ' );
1134 Vec_StrWriteEntry( vSop[n], Start + nVars + 1, (
char)(n ?
'0' :
'1') );
1135 Vec_StrWriteEntry( vSop[n], Start + nVars + 2,
'\n' );
1136 Vec_StrWriteEntry( vSop[n], Start + nVars + 3,
'\0' );
1137 Vec_IntClear( vCube );
1140 iLit = Vec_IntEntry( vLits, iVar );
1141 Vec_IntPush( vCube, Abc_LitNot(iLit) );
1143 Vec_StrWriteEntry( vSop[n], Start + nVars - iVar - 1, (
char)(
'0' + !Abc_LitIsCompl(iLit)) );
1145 Vec_StrWriteEntry( vSop[n], Start + iVar, (
char)(
'0' + !Abc_LitIsCompl(iLit)) );
1156 if ( fComplete[0] || fComplete[1] )
1160 Vec_IntFree( vVars );
1161 Vec_IntFree( vLits );
1162 Vec_IntFree( vLitsC[0] );
1163 Vec_IntFree( vLitsC[1] );
1164 Vec_IntFree( vNums );
1165 Vec_IntFree( vCube );
1166 assert( !fComplete[0] || !fComplete[1] );
1167 if ( fComplete[0] || fComplete[1] )
1169 vRes = vSop[fComplete[1]]; vSop[fComplete[1]] = NULL;
1177 printf(
"Processed output with %d supp vars. ", nVars );
1179 printf(
"The resulting SOP exceeded %d cubes.\n", nCubeLim );
1181 printf(
"The best cover contains %d cubes.\n", Vec_StrSize(vRes)/(nVars +3) );
1182 Abc_PrintTime( 1,
"Onset minterm", Time[0][0] );
1183 Abc_PrintTime( 1,
"Onset expand ", Time[0][1] );
1184 Abc_PrintTime( 1,
"Offset minterm", Time[1][0] );
1185 Abc_PrintTime( 1,
"Offset expand ", Time[1][1] );
1188 Abc_PrintTime( 1,
"Expand check1 ", clkCheck1 ); clkCheck1 = 0;
1189 Abc_PrintTime( 1,
"Expand check2 ", clkCheck2 ); clkCheck2 = 0;
1190 Abc_PrintTime( 1,
"Expand sat ", clkCheckS ); clkCheckS = 0;
1191 Abc_PrintTime( 1,
"Expand unsat ", clkCheckU ); clkCheckU = 0;
1194 Vec_StrFreeP( &vSop[0] );
1195 Vec_StrFreeP( &vSop[1] );
1228 int fVeryVerbose = fVerbose;
1230 Vec_Str_t * vSop[2] = { Vec_StrAlloc(1000), Vec_StrAlloc(1000) }, * vRes = NULL;
1231 Vec_Int_t * vVars = Vec_IntAlloc( nVars+1 );
1232 Vec_Int_t * vLits = Vec_IntAlloc( nVars+1 );
1233 Vec_Int_t * vNums = Vec_IntAlloc( nVars+1 );
1234 Vec_Int_t * vCube = Vec_IntAlloc( nVars+1 );
1235 int n, v, iVar, pLits[2], iCube = 0, Start, status;
1236 abctime clk = 0, Time[2][2] = {{0}};
1237 int fComplete[2] = {0};
1240 int iOOVars[2] = {0, 1};
1248 for ( v = nVars - 1; v >= 0; v-- )
1249 Vec_IntPush( vVars, iCiVarBeg + v );
1251 for ( v = 0; v < nVars; v++ )
1252 Vec_IntPush( vVars, iCiVarBeg + v );
1255 for ( n = 0; n < 2; n++ )
1257 pLits[0] = Abc_Var2Lit( iOutVar, n );
1263 Vec_StrClear( vSop[0] );
1264 Vec_StrPrintStr( vSop[0], n ?
" 1\n" :
" 0\n" );
1265 Vec_StrPush( vSop[0],
'\0' );
1273 Vec_StrPush( vSop[n],
'\0' );
1277 for ( iCube = 0; nCubeLim == 0 || iCube < nCubeLim; iCube++ )
1279 for ( n = 0; n < 2; n++ )
1281 if ( fVeryVerbose ) clk = Abc_Clock();
1283 sat_solver_clean_polarity( pSat[n], Vec_IntArray(vVars), Vec_IntSize(vVars) );
1284 pLits[0] = Abc_Var2Lit( iOOVars[n], 1 );
1288 if ( fVeryVerbose ) Time[n][0] += Abc_Clock() - clk;
1297 Vec_IntClear( vLits );
1299 Vec_IntPush( vLits, Abc_Var2Lit(iVar, !sat_solver_var_value(pSat[n], iVar)) );
1301 if ( fVeryVerbose ) clk = Abc_Clock();
1303 status =
Bmc_CollapseExpand( pSat[!n], NULL, vLits, vNums, vCube, nBTLimit, fCanon, -1 );
1304 if ( fVeryVerbose ) Time[n][1] += Abc_Clock() - clk;
1308 Vec_StrPop( vSop[n] );
1309 Start = Vec_StrSize( vSop[n] );
1310 Vec_StrFillExtra( vSop[n], Start + nVars + 4,
'-' );
1311 Vec_StrWriteEntry( vSop[n], Start + nVars + 0,
' ' );
1312 Vec_StrWriteEntry( vSop[n], Start + nVars + 1, (
char)(n ?
'0' :
'1') );
1313 Vec_StrWriteEntry( vSop[n], Start + nVars + 2,
'\n' );
1314 Vec_StrWriteEntry( vSop[n], Start + nVars + 3,
'\0' );
1315 Vec_IntClear( vCube );
1316 Vec_IntPush( vCube, Abc_Var2Lit( iOOVars[n], 0 ) );
1319 int iLit = Vec_IntEntry( vLits, iVar );
1320 Vec_IntPush( vCube, Abc_LitNot(iLit) );
1322 Vec_StrWriteEntry( vSop[n], Start + nVars - iVar - 1, (
char)(
'0' + !Abc_LitIsCompl(iLit)) );
1324 Vec_StrWriteEntry( vSop[n], Start + iVar, (
char)(
'0' + !Abc_LitIsCompl(iLit)) );
1336 if ( fComplete[0] || fComplete[1] )
1340 Vec_IntFree( vVars );
1341 Vec_IntFree( vLits );
1342 Vec_IntFree( vNums );
1343 Vec_IntFree( vCube );
1344 assert( !fComplete[0] || !fComplete[1] );
1345 if ( fComplete[0] || fComplete[1] )
1347 vRes = vSop[fComplete[1]]; vSop[fComplete[1]] = NULL;
1355 printf(
"Processed output with %d supp vars. ", nVars );
1357 printf(
"The resulting SOP exceeded %d cubes.\n", nCubeLim );
1359 printf(
"The best cover contains %d cubes.\n", Vec_StrSize(vRes)/(nVars +3) );
1360 Abc_PrintTime( 1,
"Onset minterm", Time[0][0] );
1361 Abc_PrintTime( 1,
"Onset expand ", Time[0][1] );
1362 Abc_PrintTime( 1,
"Offset minterm", Time[1][0] );
1363 Abc_PrintTime( 1,
"Offset expand ", Time[1][1] );
1366 Abc_PrintTime( 1,
"Expand check1 ", clkCheck1 ); clkCheck1 = 0;
1367 Abc_PrintTime( 1,
"Expand check2 ", clkCheck2 ); clkCheck2 = 0;
1368 Abc_PrintTime( 1,
"Expand sat ", clkCheckS ); clkCheckS = 0;
1369 Abc_PrintTime( 1,
"Expand unsat ", clkCheckU ); clkCheckU = 0;
1372 Vec_StrFreeP( &vSop[0] );
1373 Vec_StrFreeP( &vSop[1] );
1391 int fVeryVerbose = fVerbose;
1392 Vec_Str_t * vSop[2] = { Vec_StrAlloc(1000), Vec_StrAlloc(1000) }, * vRes = NULL;
1393 Vec_Int_t * vVars = Vec_IntAlloc( nVars+1 );
1394 Vec_Int_t * vLits = Vec_IntAlloc( nVars+1 );
1395 Vec_Int_t * vNums = Vec_IntAlloc( nVars+1 );
1396 Vec_Int_t * vCube = Vec_IntAlloc( nVars+1 );
1397 int n, v, iVar, pLits[2], iCube = 0, Start, status;
1398 abctime clk = 0, Time[2][2] = {{0}};
1399 int fComplete[2] = {0};
1402 int iOOVars[2] = {0, 1};
1410 for ( v = nVars - 1; v >= 0; v-- )
1411 Vec_IntPush( vVars, iCiVarBeg + v );
1413 for ( v = 0; v < nVars; v++ )
1414 Vec_IntPush( vVars, iCiVarBeg + v );
1417 for ( n = 0; n < 2; n++ )
1419 pLits[0] = Abc_Var2Lit( iOutVar, n );
1425 Vec_StrClear( vSop[0] );
1426 Vec_StrPrintStr( vSop[0], n ?
" 1\n" :
" 0\n" );
1427 Vec_StrPush( vSop[0],
'\0' );
1432 Vec_StrPush( vSop[n],
'\0' );
1436 for ( iCube = 0; nCubeLim == 0 || iCube < nCubeLim; iCube++ )
1438 for ( n = 0; n < 2; n++ )
1440 if ( fVeryVerbose ) clk = Abc_Clock();
1442 sat_solver_clean_polarity( pSat, Vec_IntArray(vVars), Vec_IntSize(vVars) );
1443 pLits[0] = Abc_Var2Lit( iOutVar, n );
1444 pLits[1] = Abc_Var2Lit( iOOVars[n], 1 );
1446 if ( fVeryVerbose ) Time[n][0] += Abc_Clock() - clk;
1455 Vec_IntClear( vLits );
1457 Vec_IntPush( vLits, Abc_Var2Lit(iVar, !sat_solver_var_value(pSat, iVar)) );
1459 if ( fVeryVerbose ) clk = Abc_Clock();
1460 status =
Bmc_CollapseExpand( pSat, NULL, vLits, vNums, vCube, nBTLimit, fCanon, Abc_Var2Lit(iOutVar, !n) );
1461 if ( fVeryVerbose ) Time[n][1] += Abc_Clock() - clk;
1465 Vec_StrPop( vSop[n] );
1466 Start = Vec_StrSize( vSop[n] );
1467 Vec_StrFillExtra( vSop[n], Start + nVars + 4,
'-' );
1468 Vec_StrWriteEntry( vSop[n], Start + nVars + 0,
' ' );
1469 Vec_StrWriteEntry( vSop[n], Start + nVars + 1, (
char)(n ?
'0' :
'1') );
1470 Vec_StrWriteEntry( vSop[n], Start + nVars + 2,
'\n' );
1471 Vec_StrWriteEntry( vSop[n], Start + nVars + 3,
'\0' );
1472 Vec_IntClear( vCube );
1473 Vec_IntPush( vCube, Abc_Var2Lit( iOOVars[n], 0 ) );
1476 int iLit = Vec_IntEntry( vLits, iVar );
1477 Vec_IntPush( vCube, Abc_LitNot(iLit) );
1479 Vec_StrWriteEntry( vSop[n], Start + nVars - iVar - 1, (
char)(
'0' + !Abc_LitIsCompl(iLit)) );
1481 Vec_StrWriteEntry( vSop[n], Start + iVar, (
char)(
'0' + !Abc_LitIsCompl(iLit)) );
1492 if ( fComplete[0] || fComplete[1] )
1496 Vec_IntFree( vVars );
1497 Vec_IntFree( vLits );
1498 Vec_IntFree( vNums );
1499 Vec_IntFree( vCube );
1500 assert( !fComplete[0] || !fComplete[1] );
1501 if ( fComplete[0] || fComplete[1] )
1503 vRes = vSop[fComplete[1]]; vSop[fComplete[1]] = NULL;
1511 printf(
"Processed output with %d supp vars. ", nVars );
1513 printf(
"The resulting SOP exceeded %d cubes.\n", nCubeLim );
1515 printf(
"The best cover contains %d cubes.\n", Vec_StrSize(vRes)/(nVars +3) );
1516 Abc_PrintTime( 1,
"Onset minterm", Time[0][0] );
1517 Abc_PrintTime( 1,
"Onset expand ", Time[0][1] );
1518 Abc_PrintTime( 1,
"Offset minterm", Time[1][0] );
1519 Abc_PrintTime( 1,
"Offset expand ", Time[1][1] );
1522 Abc_PrintTime( 1,
"Expand check1 ", clkCheck1 ); clkCheck1 = 0;
1523 Abc_PrintTime( 1,
"Expand check2 ", clkCheck2 ); clkCheck2 = 0;
1524 Abc_PrintTime( 1,
"Expand sat ", clkCheckS ); clkCheckS = 0;
1525 Abc_PrintTime( 1,
"Expand unsat ", clkCheckU ); clkCheckU = 0;
1528 Vec_StrFreeP( &vSop[0] );
1529 Vec_StrFreeP( &vSop[1] );
#define ABC_INFINITY
MACRO DEFINITIONS ///.
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
struct Vec_Str_t_ Vec_Str_t
int Bmc_CollapseExpand(sat_solver *pSat, sat_solver *pSatOn, Vec_Int_t *vLits, Vec_Int_t *vNums, Vec_Int_t *vTemp, int nBTLimit, int fCanon, int fOnOffSetLit)
int Bmc_CollapseExpandRound2(sat_solver *pSat, Vec_Int_t *vLits, Vec_Int_t *vTemp, int nBTLimit, int fOnOffSetLit)
Vec_Str_t * Bmc_CollapseOne3(Gia_Man_t *p, int nCubeLim, int nBTLimit, int fCanon, int fReverse, int fVerbose)
Vec_Str_t * Bmc_CollapseOneOld(Gia_Man_t *p, int nCubeLim, int nBTLimit, int fCanon, int fReverse, int fVerbose)
#define Bmc_SopForEachCube(pSop, nVars, pCube)
int Bmc_CollapseIrredundant(Vec_Str_t *vSop, int nCubes, int nVars)
Vec_Str_t * Bmc_CollapseOneOld2(Gia_Man_t *p, int nCubeLim, int nBTLimit, int fCanon, int fReverse, int fVerbose)
Vec_Str_t * Bmc_CollapseOne_int(sat_solver *pSat, int nVars, int nCubeLim, int nBTLimit, int fCanon, int fReverse, int fVerbose)
int Bmc_CollapseExpandRound(sat_solver *pSat, sat_solver *pSatOn, Vec_Int_t *vLits, Vec_Int_t *vNums, Vec_Int_t *vTemp, int nBTLimit, int fCanon, int fOnOffSetLit)
ABC_NAMESPACE_IMPL_START int Bmc_ComputeSimDiff(Gia_Man_t *p, Vec_Int_t *vPat, Vec_Int_t *vPat2)
DECLARATIONS ///.
int Bmc_ComputeCanonical(sat_solver *pSat, Vec_Int_t *vLits, Vec_Int_t *vTemp, int nBTLimit)
int Bmc_ComputeCanonical2(sat_solver *pSat, Vec_Int_t *vLits, Vec_Int_t *vTemp, int nBTLimit)
Vec_Str_t * Bmc_CollapseOne_int2(sat_solver *pSat1, sat_solver *pSat2, int nVars, int nCubeLim, int nBTLimit, int fCanon, int fReverse, int fVerbose)
int Bmc_CollapseExpand2(sat_solver *pSat, sat_solver *pSatOn, Vec_Int_t *vLits, Vec_Int_t *vNums, Vec_Int_t *vTemp, int nBTLimit, int fCanon, int fOnOffSetLit)
Vec_Str_t * Bmc_CollapseOne(Gia_Man_t *p, int nCubeLim, int nBTLimit, int fCanon, int fReverse, int fVerbose)
Vec_Str_t * Bmc_CollapseOneInt2(Gia_Man_t *p, int nCubeLim, int nBTLimit, int fCanon, int fReverse, int fVerbose, int fCompl)
int Bmc_CollapseIrredundantFull(Vec_Str_t *vSop, int nCubes, int nVars)
Vec_Str_t * Bmc_CollapseOne_int3(sat_solver *pSat0, sat_solver *pSat1, sat_solver *pSat2, sat_solver *pSat3, int nVars, int nCubeLim, int nBTLimit, int fCanon, int fReverse, int fVerbose)
void Bmc_ComputeSimTest(Gia_Man_t *p)
#define sat_solver_addclause
struct Cnf_Dat_t_ Cnf_Dat_t
void Cnf_DataFree(Cnf_Dat_t *p)
#define Gia_ManForEachAnd(p, pObj, i)
struct Gia_Obj_t_ Gia_Obj_t
struct Gia_Man_t_ Gia_Man_t
#define Gia_ManForEachCo(p, pObj, i)
void * Mf_ManGenerateCnf(Gia_Man_t *pGia, int nLutSize, int fCnfObjIds, int fAddOrCla, int fMapping, int fVerbose)
#define Gia_ManForEachCiId(p, Id, i)
unsigned __int64 word
DECLARATIONS ///.
void * Cnf_DataWriteIntoSolver(Cnf_Dat_t *p, int nFrames, int fInit)
sat_solver * sat_solver_new(void)
void sat_solver_setnvars(sat_solver *s, int n)
int sat_solver_nvars(sat_solver *s)
int sat_solver_push(sat_solver *s, int p)
void sat_solver_pop(sat_solver *s)
void sat_solver_set_resource_limits(sat_solver *s, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, ABC_INT64_T nConfLimitGlobal, ABC_INT64_T nInsLimitGlobal)
void sat_solver_delete(sat_solver *s)
int sat_solver_solve_lexsat(sat_solver *s, int *pLits, int nLits)
int sat_solver_minimize_assumptions(sat_solver *s, int *pLits, int nLits, int nConfLimit)
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
#define Vec_IntForEachEntryStop(vVec, Entry, i, Stop)
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
#define Vec_PtrForEachEntryReverse(Type, vVec, pEntry, i)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.