75 assert( nLutSize * nLutNum <= nFlops );
77 return Vec_IntStartNatural( nLutNum * nLutSize );
78 vFlops = Vec_IntAlloc( nLutNum * nLutSize );
79 pTemp =
strtok( pStr,
", " );
82 int iFlop = atoi(pTemp);
83 if ( iFlop >= nFlops )
85 printf(
"Flop index (%d) exceeds the number of flops (%d).\n", iFlop, nFlops );
88 Vec_IntPush( vFlops, iFlop );
89 pTemp =
strtok( NULL,
", " );
91 if ( Vec_IntSize(vFlops) != nLutNum * nLutSize )
93 printf(
"Gia_GenCollectFlopIndexes: Expecting %d flop indexes (instead of %d).\n", nLutNum * nLutSize, Vec_IntSize(vFlops) );
94 Vec_IntFree( vFlops );
97 nDups = Vec_IntCountDuplicates(vFlops);
100 printf(
"Gia_GenCollectFlopIndexes: There are %d duplicated flops in the list.\n", nDups );
101 Vec_IntFree( vFlops );
110 return Vec_IntEntry( vData, Shift );
117 Vec_Int_t * vLits = Vec_IntAlloc( nLutNum );
118 int i, k, iMux, iFlop, pCtrl[16];
120 assert( Vec_IntSize(vFlops) == nLutNum * nLutSize );
121 for ( i = 0; i < nLutNum; i++ )
123 for ( k = 0; k < nLutSize; k++ )
125 iFlop = Vec_IntEntry(vFlops, i * nLutSize + k);
126 assert( iFlop >= 0 && iFlop < Gia_ManRegNum(
p) );
128 pCtrl[k] = Gia_ManRi(
p, iFlop)->Value;
130 pCtrl[k] = Gia_ManRo(
p, iFlop)->Value;
133 Vec_IntPush( vLits, iMux );
141 int i, iMiter, iLut0, iLut1, nPars = nLutNum * (1 << nLutSize);
142 Vec_Int_t * vLits0, * vLits1, * vParLits;
145 vParLits = Vec_IntAlloc( nPars );
146 for ( i = 0; i < nPars; i++ )
147 Vec_IntPush( vParLits, i ? Abc_Var2Lit(i+1, 0) : 1 );
150 pNew->
pName = Abc_UtilStrsav(
p->pName );
151 pNew->
pSpec = Abc_UtilStrsav(
p->pSpec );
153 Gia_ManConst0(
p)->Value = 0;
154 for ( i = 0; i < nPars; i++ )
155 Gia_ManAppendCi( pNew );
157 pObj->
Value = Gia_ManAppendCi( pNew );
161 pObj->
Value = Gia_ObjFanin0Copy(pObj);
167 iLut0 = Vec_IntEntry(vLits0, 0);
168 iLut1 = Vec_IntEntry(vLits1, 0);
171 Gia_Obj_t * pObjPoLast = Gia_ManPo(
p, Gia_ManPoNum(
p)-1 );
172 int iOut = Abc_LitNotCond( Gia_ObjFanin0Copy(pObjPoLast), 0 );
177 iMiter =
Gia_ManHashAnd( pNew, Abc_LitNot(iMiter), Abc_Var2Lit(1, 0) );
178 Gia_ManAppendCo( pNew, iMiter );
180 Vec_IntFree( vLits0 );
181 Vec_IntFree( vLits1 );
182 Vec_IntFree( vFlops );
183 Vec_IntFree( vParLits );
205 return Vec_IntEntry( vData, Shift );
212 Vec_Int_t * vLits = Vec_IntAlloc( nLutNum );
215 assert( Vec_IntSize(vPLits) == nLutNum * (1 << nLutSize) );
216 assert( Vec_IntSize(vXLits) == nLutSize );
217 for ( i = 0; i < nLutNum; i++ )
220 Vec_IntPush( vLits, iMux );
227 Vec_Int_t * vPLits = Vec_IntAlloc( nLutNum * (1 << nLutSize) );
228 Vec_Int_t * vXLits = Vec_IntAlloc( nLutSize );
229 Vec_Int_t * vYLits = Vec_IntAlloc( nLutSize );
230 Vec_Int_t * vXYLits = Vec_IntAlloc( nLutSize );
232 Vec_Int_t * vXYRes2 = Vec_IntAlloc( 2 * nLutNum );
234 pNew->
pName = Abc_UtilStrsav(
"homoqbf" );
236 for ( i = 0; i < nLutNum * (1 << nLutSize); i++ )
237 Vec_IntPush( vPLits, Gia_ManAppendCi(pNew) );
238 for ( i = 0; i < nLutSize; i++ )
239 Vec_IntPush( vXLits, Gia_ManAppendCi(pNew) );
240 for ( i = 0; i < nLutSize; i++ )
241 Vec_IntPush( vYLits, Gia_ManAppendCi(pNew) );
242 for ( i = 0; i < nLutSize; i++ )
243 Vec_IntPush( vXYLits, Abc_LitNot(
Gia_ManHashAnd(pNew, Vec_IntEntry(vXLits, i), Vec_IntEntry(vYLits, i))) );
247 for ( i = 0; i < nLutNum; i++ )
249 Vec_IntPush( vXYRes2, Vec_IntEntry(vXYRes, i) );
250 Vec_IntPush( vXYRes2, Abc_LitNot(
Gia_ManHashAnd(pNew, Vec_IntEntry(vXRes, i), Vec_IntEntry(vYRes, i))) );
254 for ( i = 0; i < (1 << nLutSize); i++ )
256 Vec_Int_t * vCondA = Vec_IntAlloc( nLutNum );
257 Vec_Int_t * vCondB = Vec_IntAlloc( nLutNum );
258 for ( v = 0; v < nLutNum; v++ )
259 Vec_IntPush( vCondA, Vec_IntEntry(vPLits, v*(1 << nLutSize)+i) );
260 for ( k = i+1; k < (1 << nLutSize); k++ )
262 Vec_IntClear( vCondB );
263 for ( v = 0; v < nLutNum; v++ )
265 Vec_IntPush( vCondB, Vec_IntEntry(vCondA, v) );
266 Vec_IntPush( vCondB, Vec_IntEntry(vPLits, v*(1 << nLutSize)+k) );
271 Vec_IntFree( vCondA );
272 Vec_IntFree( vCondB );
274 Gia_ManAppendCo( pNew, Abc_LitNot(Res) );
276 Vec_IntFree( vPLits );
277 Vec_IntFree( vXLits );
278 Vec_IntFree( vYLits );
279 Vec_IntFree( vXYLits );
280 Vec_IntFree( vXRes );
281 Vec_IntFree( vYRes );
282 Vec_IntFree( vXYRes );
283 Vec_IntFree( vXYRes2 );
286 printf(
"Generated QBF miter with %d parameters, %d functional variables, and %d AIG nodes.\n",
287 nLutNum * (1 << nLutSize), 2*nLutSize, Gia_ManAndNum(pNew) );
293 for ( k = 0; k < nLutNum; k++ )
294 if ( Vec_IntEntry(vCode, k*(1 << nLutSize)+x) )
302 for ( k = 0; k < nLutNum; k++ )
303 if ( Vec_IntEntry(vCode, k*(1 << nLutSize)+x) )
304 Abc_InfoSetBit( (
unsigned *)pRes, k );
310 int i, n, nPairs = 16;
311 printf(
"%d-input %d-output code table:\n", nLutSize, nLutNum );
312 for ( i = 0; i < (1 << nLutSize); i++ )
319 printf(
"%5d ", (
int)CodeX[0] );
326 printf(
"Simulation of the encoding with %d random pairs:\n", nPairs );
327 for ( n = 0; n < nPairs; n++ )
329 unsigned MaskIn = Abc_InfoMask( nLutSize );
330 int NumX = 0, NumY = 0, NumXY,
nWords = Abc_Bit6WordNum(nLutNum);
331 word * CodeX, * CodeY, * CodeXY;
333 while ( NumX == NumY )
335 NumX = rand() % (1 << nLutSize);
336 NumY = rand() % (1 << nLutSize);
337 NumXY = MaskIn & ~(NumX & NumY);
342 Abc_TtAnd( CodeXCodeY, CodeX, CodeY,
nWords, 1 );
343 if ( nLutNum < 64*
nWords )
344 CodeXCodeY[
nWords-1] &= Abc_Tt6Mask(nLutNum % 64);
346 printf(
"%2d :", n );
347 printf(
" x =%3d ", NumX );
349 printf(
" y =%3d ", NumY );
351 printf(
" nand =%3d ", NumXY );
355 printf(
" c(x) = " );
357 printf(
" c(y) = " );
359 printf(
" c(nand) = " );
361 printf(
" nand(c(x),c(y)) = " );
365 printf(
"%s", Abc_TtEqual(CodeXCodeY, CodeXY,
nWords) ?
"yes" :
"no" );
376 int i, nLutSize = 1, nLutNum = 2;
377 Vec_Int_t * vCode = Vec_IntAlloc( (1 << nLutSize) * nLutNum );
379 for ( i = 0; i < (1 << nLutSize) * nLutNum; i++ )
380 Vec_IntPush( vCode, rand() & 1 );
382 Vec_IntFree( vCode );
401 int i, iLit, iParVarBeg, Iter;
402 int nSolutions = 0, RetValue = 0;
403 abctime clkStart = Abc_Clock();
406 iParVarBeg = pCnf->
nVars - Gia_ManPiNum(pGia);
409 vLits = Vec_IntAlloc( Gia_ManPiNum(pGia) );
410 for ( Iter = 1 ; ; Iter++ )
412 int status =
sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)nConfLimit, 0, 0, 0 );
413 if ( status ==
l_False ) { RetValue = 1;
break; }
414 if ( status ==
l_Undef ) { RetValue = 0;
break; }
417 Vec_IntClear( vLits );
418 for ( i = 0; i < Gia_ManPiNum(pGia); i++ )
419 Vec_IntPush( vLits, Abc_Var2Lit(iParVarBeg+i, sat_solver_var_value(pSat, iParVarBeg+i)) );
422 printf(
"%5d : ", Iter );
424 printf(
"%d", !Abc_LitIsCompl(iLit) );
428 if ( !
sat_solver_addclause( pSat, Vec_IntArray(vLits), Vec_IntArray(vLits) + Vec_IntSize(vLits) ) )
429 { RetValue = 1;
break; }
430 if ( nTimeOut && (Abc_Clock() - clkStart)/CLOCKS_PER_SEC >= nTimeOut ) { RetValue = 0;
break; }
433 Vec_IntFree( vLits );
434 if ( nTimeOut && (Abc_Clock() - clkStart)/CLOCKS_PER_SEC >= nTimeOut )
435 printf(
"Enumerated %d assignments when timeout (%d sec) was reached. ", nSolutions, nTimeOut );
436 else if ( nConfLimit && !RetValue )
437 printf(
"Enumerated %d assignments when conflict limit (%d) was reached. ", nSolutions, nConfLimit );
439 printf(
"Enumerated the complete set of %d assignments. ", nSolutions );
440 Abc_PrintTime( 1,
"Time", Abc_Clock() - clkStart );
460 Vec_Int_t * vVarMap, * vForAlls, * vExists;
465 vVarMap = Vec_IntStart( pCnf->
nVars );
468 Vec_IntWriteEntry( vVarMap, pCnf->
pVarNums[Gia_ManCiIdToId(pGia, i)], 1 );
470 vForAlls = Vec_IntAlloc( nPars );
471 vExists = Vec_IntAlloc( Gia_ManCiNum(pGia) - nPars );
474 Vec_IntPush( vForAlls, i );
476 Vec_IntPush( vExists, i );
481 Vec_IntFree( vForAlls );
482 Vec_IntFree( vExists );
483 Vec_IntFree( vVarMap );
484 printf(
"The 2QBF formula was written into file \"%s\".\n", pFileName );
491 Vec_Int_t * vVarMap, * vForAlls, * vExists1, * vExists2;
498 vVarMap = Vec_IntStart( pCnf->
nVars );
500 Vec_IntWriteEntry( vVarMap, pCnf->
pVarNums[Gia_ManCiIdToId(pGia, i)], i < nPars ? 1 : 2 );
502 vExists1 = Vec_IntAlloc( nPars );
503 vForAlls = Vec_IntAlloc( Gia_ManCiNum(pGia) - nPars );
504 vExists2 = Vec_IntAlloc( pCnf->
nVars - Gia_ManCiNum(pGia) );
507 Vec_IntPush( vExists1, i );
508 else if ( Entry == 2 )
509 Vec_IntPush( vForAlls, i );
511 Vec_IntPush( vExists2, i );
516 Vec_IntFree( vExists1 );
517 Vec_IntFree( vForAlls );
518 Vec_IntFree( vExists2 );
519 Vec_IntFree( vVarMap );
520 printf(
"The 2QBF formula was written into file \"%s\".\n", pFileName );
541 Gia_ObjFlipFaninC0( Gia_ManPo(pGia, 0) );
543 Gia_ObjFlipFaninC0( Gia_ManPo(pGia, 0) );
545 p->clkStart = Abc_Clock();
548 p->nVars = Gia_ManPiNum(pGia) - nPars;
549 p->fVerbose = fVerbose;
550 p->iParVarBeg = pCnf->
nVars - Gia_ManPiNum(pGia);
554 p->vValues = Vec_IntAlloc( Gia_ManPiNum(pGia) );
555 p->vParMap = Vec_IntStartFull( nPars );
556 p->vLits = Vec_IntAlloc( nPars );
567 Vec_IntFree(
p->vLits );
568 Vec_IntFree(
p->vValues );
569 Vec_IntFree(
p->vParMap );
591 pNew->
pName = Abc_UtilStrsav(
p->pName );
594 Gia_ManConst0(
p)->Value = 0;
596 pObj->
Value = Gia_ManAppendCi(pNew);
598 vCofs = Vec_IntAlloc( 2 * Gia_ManPoNum(
p) );
599 for ( c = 0; c < 2; c++ )
601 Gia_ManPi(
p, iVar)->Value = c;
605 Vec_IntPush( vCofs, Gia_ObjFanin0Copy(pObj) );
609 for ( i = 0; i < Gia_ManPoNum(
p); i++ )
610 Gia_ManAppendCo( pNew,
Gia_ManHashAnd(pNew, Vec_IntEntry(vCofs, i), Vec_IntEntry(vCofs, Gia_ManPoNum(
p)+i)) );
614 for ( i = 0; i < Gia_ManPoNum(
p); i++ )
615 Gia_ManAppendCo( pNew,
Gia_ManHashOr(pNew, Vec_IntEntry(vCofs, i), Vec_IntEntry(vCofs, Gia_ManPoNum(
p)+i)) );
620 Gia_ManAppendCo( pNew, c );
622 Vec_IntFree( vCofs );
631 for ( v = Gia_ManPiNum(
p) - 1; v >= nPars; v-- )
654 assert( Gia_ManPiNum(
p) == nPars + Vec_IntSize(vValues) );
656 pNew->
pName = Abc_UtilStrsav(
p->pName );
658 Gia_ManConst0(
p)->Value = 0;
662 pObj->
Value = Gia_ManAppendCi(pNew);
663 if ( Vec_IntEntry(vParMap, i) != -1 )
664 pObj->
Value = Vec_IntEntry(vParMap, i);
667 pObj->
Value = Vec_IntEntry(vValues, i - nPars);
671 pObj->
Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
674 assert( Gia_ManPiNum(pNew) == nPars );
701 for ( v = 0; v <
p->nLiterals; v++ )
703 var =
p->pClauses[0][v] / 2;
704 if (var < firstPiVar || var >= lastPiVar)
705 p->pClauses[0][v] += 2*nVarsPlus;
707 p->pClauses[0][v] -= 2*firstPiVar;
723 for ( i = 0; i < pCnf->
nClauses; i++ )
732 for ( i = 0; i < Gia_ManPiNum(
p->pGia); i++ )
733 if ( !sat_solver_add_buffer(
p->pSatSyn, i, iFirstVar+i, 0 ) )
740 int i, iFirstVar = pCnf->
nVars - Gia_ManPiNum(pCof);
743 for ( i = 0; i < pCnf->
nClauses; i++ )
767 Vec_IntClear( vValues );
768 for ( i = 0; i <
p->nPars; i++ )
773 printf(
"%5d : ", Iter );
774 assert( Vec_IntSize(vValues) ==
p->nVars );
775 Vec_IntPrintBinary( vValues ); printf(
" " );
779 Abc_PrintTime( 1,
"Time", Abc_Clock() -
p->clkStart );
795 int i, Entry, RetValue;
796 assert( Vec_IntSize(vValues) ==
p->nPars );
797 Vec_IntClear(
p->vLits );
799 Vec_IntPush(
p->vLits, Abc_Var2Lit(
p->iParVarBeg+i, !Entry) );
800 RetValue =
sat_solver_solve(
p->pSatVer, Vec_IntArray(
p->vLits), Vec_IntLimit(
p->vLits), 0, 0, 0, 0 );
803 Vec_IntClear( vValues );
804 for ( i = 0; i <
p->nVars; i++ )
805 Vec_IntPush( vValues, sat_solver_var_value(
p->pSatVer,
p->iParVarBeg+
p->nPars+i) );
807 return RetValue ==
l_True ? 1 : 0;
823 int i, status, Lits[2];
824 for ( i = 0; i < 4*11; i++ )
827 assert( Vec_IntEntry(
p->vParMap, i) == -1 );
828 Vec_IntWriteEntry(
p->vParMap, i, (i % 4) == 3 );
829 Lits[0] = Abc_Var2Lit( i, (i % 4) != 3 );
836 int i, status, Entry, Lits[2];
837 assert( Vec_IntSize(vValues) ==
p->nPars );
838 printf(
" Pattern " );
839 Vec_IntPrintBinary( vValues );
843 Lits[0] = Abc_Var2Lit( i, Entry );
845 printf(
" Var =%4d ", i );
849 Lits[0] = Abc_LitNot(Lits[0]);
855 Vec_IntPrintBinary(
p->vLits );
858 assert( Vec_IntSize(vValues) ==
p->nPars );
872int Gia_QbfSolve(
Gia_Man_t * pGia,
int nPars,
int nIterLimit,
int nConfLimit,
int nTimeOut,
int nEncVars,
int fGlucose,
int fVerbose )
876 int i, status, RetValue = 0;
880 printf(
"Solving QBF for \"%s\" with %d parameters, %d variables and %d AIG nodes.\n",
881 Gia_ManName(pGia),
p->nPars,
p->nVars, Gia_ManAndNum(pGia) );
882 assert( Gia_ManRegNum(pGia) == 0 );
883 Vec_IntFill(
p->vValues, nPars, 0 );
887 assert( Vec_IntSize(
p->vValues) ==
p->nVars );
891 if ( status == 0 ) { RetValue = 1;
break; }
897 status =
sat_solver_solve(
p->pSatSyn, NULL, NULL, (ABC_INT64_T)nConfLimit, 0, 0, 0 );
898 p->clkSat += Abc_Clock() - clk;
901 if ( status ==
l_False ) { RetValue = 1;
break; }
902 if ( status ==
l_Undef ) { RetValue = -1;
break; }
905 assert( Vec_IntSize(
p->vValues) ==
p->nPars );
909 if ( nIterLimit && i+1 == nIterLimit ) { RetValue = -1;
break; }
910 if ( nTimeOut && (Abc_Clock() -
p->clkStart)/CLOCKS_PER_SEC >= nTimeOut ) { RetValue = -1;
break; }
914 int nZeros = Vec_IntCountZero(
p->vValues );
915 printf(
"Parameters: " );
916 assert( Vec_IntSize(
p->vValues) == nPars );
917 Vec_IntPrintBinary(
p->vValues );
918 printf(
" Statistics: 0=%d 1=%d\n", nZeros, Vec_IntSize(
p->vValues) - nZeros );
921 int nBits = Vec_IntSize(
p->vValues)/(1 << nEncVars);
922 assert( Vec_IntSize(
p->vValues) == (1 << nEncVars) * nBits );
926 if ( RetValue == -1 && nTimeOut && (Abc_Clock() -
p->clkStart)/CLOCKS_PER_SEC >= nTimeOut )
927 printf(
"The problem timed out after %d sec. ", nTimeOut );
928 else if ( RetValue == -1 && nConfLimit )
929 printf(
"The problem aborted after %d conflicts. ", nConfLimit );
930 else if ( RetValue == -1 && nIterLimit )
931 printf(
"The problem aborted after %d iterations. ", nIterLimit );
932 else if ( RetValue == 1 )
933 printf(
"The problem is UNSAT after %d iterations. ", i );
935 printf(
"The problem is SAT after %d iterations. ", i );
939 Abc_PrintTime( 1,
"SAT ",
p->clkSat );
940 Abc_PrintTime( 1,
"Other", Abc_Clock() -
p->clkStart -
p->clkSat );
941 Abc_PrintTime( 1,
"TOTAL", Abc_Clock() -
p->clkStart );
944 Abc_PrintTime( 1,
"Time", Abc_Clock() -
p->clkStart );
962 Gia_Obj_t * pObj;
int i, nObjs = Gia_ManObjNum(
p);
967 Gia_ObjSetTravIdCurrent(
p, pObj);
969 if ( !Gia_ObjIsTravIdCurrent(
p, pObj) )
970 sat_solver_add_and( pSat, i, Gia_ObjFaninId0(pObj, i), Gia_ObjFaninId1(pObj, i), Gia_ObjFaninC0(pObj), Gia_ObjFaninC1(pObj), 0 );
972 sat_solver_add_and( pSat, nObjs+i, nObjs+Gia_ObjFaninId0(pObj, i), nObjs+Gia_ObjFaninId1(pObj, i), Gia_ObjFaninC0(pObj), Gia_ObjFaninC1(pObj), 0 );
974 if ( !Gia_ObjIsTravIdCurrent(
p, pObj) )
975 sat_solver_add_buffer( pSat, nObjs+Gia_ObjId(
p, pObj), Gia_ObjId(
p, pObj), 0 );
977 if ( Gia_ObjFaninId0p(
p, pObj) > 0 ) {
978 sat_solver_add_buffer( pSat, Gia_ObjId(
p, pObj), Gia_ObjFaninId0p(
p, pObj), Gia_ObjFaninC0(pObj) );
979 sat_solver_add_buffer( pSat, nObjs+Gia_ObjId(
p, pObj), nObjs+Gia_ObjFaninId0p(
p, pObj), Gia_ObjFaninC0(pObj) );
980 sat_solver_add_buffer( pSat, nObjs+Gia_ObjId(
p, pObj), Gia_ObjId(
p, pObj), 0 );
986 int nTimeOut = 600, nConfLimit = 1000000;
987 int i, iSatVar, Iter, Mask, nSolutions = 0, RetValue = 0;
988 abctime clkStart = Abc_Clock();
992 for ( Iter = 0; Iter < 1000000; Iter++ )
994 int status =
sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)nConfLimit, 0, 0, 0 );
995 if ( status ==
l_False ) { RetValue = 1;
break; }
996 if ( status ==
l_Undef ) { RetValue = 0;
break; }
1000 Vec_IntClear( vLits );
1002 Vec_IntPush( vLits, Abc_Var2Lit(iSatVar, sat_solver_var_value(pSat, iSatVar)) );
1003 if ( sat_solver_var_value(pSat, iSatVar) )
1004 Mask |= 1 << (Vec_IntSize(vInsOuts)-1-i);
1006 Vec_IntPush( vRes, Mask );
1009 printf(
"%5d : ", Iter );
1011 if ( i == nIns ) printf(
" " );
1012 printf(
"%d", (Mask >> (Vec_IntSize(vInsOuts)-1-i)) & 1 );
1017 if ( !
sat_solver_addclause( pSat, Vec_IntArray(vLits), Vec_IntArray(vLits) + Vec_IntSize(vLits) ) )
1018 { RetValue = 1;
break; }
1019 if ( nTimeOut && (Abc_Clock() - clkStart)/CLOCKS_PER_SEC >= nTimeOut ) { RetValue = 0;
break; }
1021 Vec_IntSort( vRes, 0 );
1022 Vec_IntFree( vLits );
1024 if ( RetValue == 0 )
1025 Vec_IntFreeP( &vRes );
1027 Abc_PrintTime( 1,
"Time", Abc_Clock() - clkStart );
1032 int i, k, Mask, nVars = nIns + nOuts;
1033 Abc_RData_t * p2, *
p = Abc_RDataStart( nIns, nOuts, Vec_IntSize(vRes) );
1035 for ( k = 0; k < nVars; k++ )
1036 if ( (Mask >> (nVars-1-k)) & 1 ) {
1038 Abc_RDataSetIn(
p, k, i );
1040 Abc_RDataSetOut(
p, 2*(k-nIns)+1, i );
1044 Abc_RDataSetOut(
p, 2*(k-nIns), i );
1047 Abc_WritePla(
p, pFileName, 0 );
1048 p2 = Abc_RData2Rel(
p );
1050 Abc_RDataStop( p2 );
1056 if ( vRes == NULL ) {
1057 printf(
"Enumerating solutions did not succeed.\n" );
1061 Vec_IntFree( vRes );
1080 for ( i = 0; i < nNodes; i++ )
1081 Gia_ObjSetTravIdCurrentId(
p, pNodes[i] );
1083 if ( Gia_ObjIsTravIdCurrentId(
p, i) )
1085 if ( Gia_ObjIsTravIdCurrentId(
p, Gia_ObjFaninId0(pObj, i)) || Gia_ObjIsTravIdCurrentId(
p, Gia_ObjFaninId1(pObj, i)) )
1086 Gia_ObjSetTravIdCurrentId(
p, i ), Vec_IntPush( vTfo, i );
1089 if ( Gia_ObjIsTravIdCurrentId(
p, Gia_ObjFaninId0p(
p, pObj)) )
1090 Vec_IntPush( vTfo, Gia_ObjId(
p, pObj) );
1099 if ( Gia_ObjIsCo(pObj) )
1100 Gia_ObjSetTravIdCurrentId(
p, Gia_ObjFaninId0p(
p, pObj) );
1102 if ( !Gia_ObjIsTravIdCurrentId(
p, i) )
1104 Gia_ObjSetTravIdCurrentId(
p, Gia_ObjFaninId0(pObj, i));
1105 Gia_ObjSetTravIdCurrentId(
p, Gia_ObjFaninId1(pObj, i));
1108 if ( Gia_ObjIsTravIdCurrentId(
p, Id) )
1109 Vec_IntPush( vTfi, Id );
1111 if ( Gia_ObjIsTravIdCurrentId(
p, i) )
1112 Vec_IntPush( vTfi, i );
1119 Vec_Int_t * vInLits = Vec_IntAlloc( nIns );
1120 Vec_Int_t * vOutLits = Vec_IntAlloc( Vec_IntSize(vInsOuts) - nIns );
1127 if ( Gia_ObjIsCi(pObj) )
1128 pObj->
Value = Gia_ManAppendCi(pNew);
1129 for ( i = 0; i < Vec_IntSize(vInsOuts)-nIns; i++ )
1130 Vec_IntPush( vInLits, Gia_ManAppendCi(pNew) );
1132 if ( Gia_ObjIsAnd(pObj) )
1135 if ( Gia_ObjIsCo(pObj) )
1136 pObj->
Value = Gia_ObjFanin0Copy(pObj);
1139 Vec_IntPush( vOutLits, pObj->
Value );
1141 pObj->
Value = Vec_IntEntry( vInLits, i-nIns );
1143 if ( Gia_ObjIsAnd(pObj) )
1146 if ( Gia_ObjIsCo(pObj) )
1148 Gia_ManAppendCo( pNew, iLit );
1150 Gia_ManAppendCo( pNew, iLit );
1151 Vec_IntFree( vTfo );
1152 Vec_IntFree( vTfi );
1153 Vec_IntFree( vInLits );
1154 Vec_IntFree( vOutLits );
1162 for (
int i = 0; i < nVars; i++ )
1163 printf(
"%s%d", i == nIns ?
" ":
"", (Mint >> (nVars-1-i)) & 1 );
1168 abctime clkStart = Abc_Clock();
1169 int nTimeOut = 600, nConfLimit = 1000000;
1170 int i, iNode, iSatVar, Iter, Mask, nSolutions = 0, RetValue = 0;
1174 int iLit = Abc_Var2Lit( 1, 0 );
1176 Vec_Int_t * vSatVars = Vec_IntAlloc( Vec_IntSize(vInsOuts) );
1178 Vec_IntPush( vSatVars, i < nIns ? 2+i : pCnf->nVars-Vec_IntSize(vInsOuts)+i );
1179 Vec_Int_t * vLits = Vec_IntAlloc( 100 );
1180 Vec_Int_t * vRes = Vec_IntAlloc( 1000 );
1181 for ( Iter = 0; Iter < 1000000; Iter++ )
1183 int status =
sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)nConfLimit, 0, 0, 0 );
1184 if ( status ==
l_False ) { RetValue = 1;
break; }
1185 if ( status ==
l_Undef ) { RetValue = 0;
break; }
1189 Vec_IntClear( vLits );
1191 Vec_IntPush( vLits, Abc_Var2Lit(iSatVar, sat_solver_var_value(pSat, iSatVar)) );
1192 if ( sat_solver_var_value(pSat, iSatVar) )
1193 Mask |= 1 << (Vec_IntSize(vInsOuts)-1-i);
1195 Vec_IntPush( vRes, Mask );
1197 printf(
"%5d : ", Iter );
1201 if ( !
sat_solver_addclause( pSat, Vec_IntArray(vLits), Vec_IntArray(vLits) + Vec_IntSize(vLits) ) )
1202 { RetValue = 1;
break; }
1203 if ( nTimeOut && (Abc_Clock() - clkStart)/CLOCKS_PER_SEC >= nTimeOut ) { RetValue = 0;
break; }
1206 Vec_Int_t * vBits = Vec_IntStart( 1 << Vec_IntSize(vInsOuts) );
1208 Vec_IntWriteEntry( vBits, Mask, 1 );
1209 Vec_IntClear( vRes );
1212 Vec_IntPush( vRes, i );
1213 Vec_IntFree( vBits );
1215 Vec_IntFree( vLits );
1219 if ( RetValue == 0 )
1220 Vec_IntFreeP( &vRes );
1225 abctime clkStart = Abc_Clock();
1227 if ( vRes == NULL ) {
1228 printf(
"Enumerating solutions did not succeed.\n" );
1233 printf(
"The resulting relation with %d input/output minterms is written into file \"%s\". ", Vec_IntSize(vRes), pFileName );
1234 Abc_PrintTime( 1,
"Time", Abc_Clock() - clkStart );
1241 Vec_IntFree( vRes );
int bmcg_sat_solver_conflictnum(bmcg_sat_solver *s)
int bmcg_sat_solver_varnum(bmcg_sat_solver *s)
bmcg_sat_solver * bmcg_sat_solver_start()
MACRO DEFINITIONS ///.
int bmcg_sat_solver_solve(bmcg_sat_solver *s, int *plits, int nlits)
int bmcg_sat_solver_addclause(bmcg_sat_solver *s, int *plits, int nlits)
int bmcg_sat_solver_read_cex_varvalue(bmcg_sat_solver *s, int ivar)
void bmcg_sat_solver_set_nvars(bmcg_sat_solver *s, int nvars)
int bmcg_sat_solver_clausenum(bmcg_sat_solver *s)
void bmcg_sat_solver_stop(bmcg_sat_solver *s)
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
#define sat_solver_addclause
#define sat_solver_add_and
void Cnf_DataWriteIntoFileInv(Cnf_Dat_t *p, char *pFileName, int fReadable, Vec_Int_t *vExists1, Vec_Int_t *vForAlls, Vec_Int_t *vExists2)
struct Cnf_Dat_t_ Cnf_Dat_t
void Cnf_DataFree(Cnf_Dat_t *p)
void Cnf_DataWriteIntoFile(Cnf_Dat_t *p, char *pFileName, int fReadable, Vec_Int_t *vForAlls, Vec_Int_t *vExists)
void Cnf_DataLift(Cnf_Dat_t *p, int nVarsPlus)
Gia_Man_t * Gia_QbfQuantifyAll(Gia_Man_t *p, int nPars, int fAndAll, int fOrAll)
Gia_Man_t * Gia_QbfQuantifyOne(Gia_Man_t *p, int iVar, int fAndAll, int fOrAll)
int Gia_QbfSolve(Gia_Man_t *pGia, int nPars, int nIterLimit, int nConfLimit, int nTimeOut, int nEncVars, int fGlucose, int fVerbose)
typedefABC_NAMESPACE_IMPL_START struct Qbf_Man_t_ Qbf_Man_t
DECLARATIONS ///.
void Gia_ManPrintRelMinterm(int Mint, int nIns, int nVars)
Vec_Int_t * Gia_GenCreateMuxes(Gia_Man_t *p, Gia_Man_t *pNew, Vec_Int_t *vFlops, int nLutNum, int nLutSize, Vec_Int_t *vParLits, int fUseRi)
void Gia_ManGenRel2(Gia_Man_t *pGia, Vec_Int_t *vInsOuts, int nIns, char *pFileName, int fVerbose)
word * Gia_Gen2CodeOneP(int nLutSize, int nLutNum, Vec_Int_t *vCode, int x)
int Gia_QbfAddCofactorG(Qbf_Man_t *p, Gia_Man_t *pCof)
int Gia_QbfAddCofactor(Qbf_Man_t *p, Gia_Man_t *pCof)
Vec_Int_t * Gia_ManCollectNodeTfos(Gia_Man_t *p, int *pNodes, int nNodes)
int Gia_Gen2CodeOne(int nLutSize, int nLutNum, Vec_Int_t *vCode, int x)
void Gia_ManGenRel(Gia_Man_t *pGia, Vec_Int_t *vInsOuts, int nIns, char *pFileName, int fVerbose)
Gia_Man_t * Gia_Gen2CreateMiter(int nLutSize, int nLutNum)
int Gia_Gen2CreateMux_rec(Gia_Man_t *pNew, int *pCtrl, int nCtrl, Vec_Int_t *vData, int Shift)
void Gia_QbfPrint(Qbf_Man_t *p, Vec_Int_t *vValues, int Iter)
int Gia_ManSatEnum(Gia_Man_t *pGia, int nConfLimit, int nTimeOut, int fVerbose)
int Gia_QbfVerify(Qbf_Man_t *p, Vec_Int_t *vValues)
void Gia_Gen2CodePrint(int nLutSize, int nLutNum, Vec_Int_t *vCode)
sat_solver * Gia_ManGenSolver(Gia_Man_t *p, Vec_Int_t *vInsOuts, int nIns)
void Gia_QbfLearnConstraint(Qbf_Man_t *p, Vec_Int_t *vValues)
Vec_Int_t * Gia_Gen2CreateMuxes(Gia_Man_t *pNew, int nLutSize, int nLutNum, Vec_Int_t *vPLits, Vec_Int_t *vXLits)
Gia_Man_t * Gia_GenQbfMiter(Gia_Man_t *p, int nFrames, int nLutNum, int nLutSize, char *pStr, int fUseOut, int fVerbose)
Vec_Int_t * Gia_ManGenIoCombs(Gia_Man_t *pGia, Vec_Int_t *vInsOuts, int nIns, int fVerbose)
void Gia_QbfOnePattern(Qbf_Man_t *p, Vec_Int_t *vValues)
void Gia_ManGenWriteRel(Vec_Int_t *vRes, int nIns, int nOuts, char *pFileName)
Gia_Man_t * Gia_ManGenRelMiter(Gia_Man_t *pGia, Vec_Int_t *vInsOuts, int nIns)
Vec_Int_t * Gia_GenCollectFlopIndexes(char *pStr, int nLutNum, int nLutSize, int nFlops)
FUNCTION DEFINITIONS ///.
void Gia_QbfAddSpecialConstr(Qbf_Man_t *p)
Vec_Int_t * Gia_ManCollectNodeTfis(Gia_Man_t *p, Vec_Int_t *vNodes)
Gia_Man_t * Gia_QbfCofactor(Gia_Man_t *p, int nPars, Vec_Int_t *vValues, Vec_Int_t *vParMap)
int Gia_GenCreateMux_rec(Gia_Man_t *pNew, int *pCtrl, int nCtrl, Vec_Int_t *vData, int Shift)
void Gia_QbfFree(Qbf_Man_t *p)
void Gia_QbfDumpFile(Gia_Man_t *pGia, int nPars)
void Cnf_SpecialDataLift(Cnf_Dat_t *p, int nVarsPlus, int firstPiVar, int lastPiVar)
void Gia_QbfDumpFileInv(Gia_Man_t *pGia, int nPars)
Vec_Int_t * Gia_ManGenCombs(Gia_Man_t *p, Vec_Int_t *vInsOuts, int nIns, int fVerbose)
Qbf_Man_t * Gia_QbfAlloc(Gia_Man_t *pGia, int nPars, int fGlucose, int fVerbose)
void Gia_ManStop(Gia_Man_t *p)
Gia_Man_t * Gia_ManDup(Gia_Man_t *p)
#define Gia_ManForEachPo(p, pObj, i)
#define Gia_ManForEachAnd(p, pObj, i)
#define Gia_ManForEachAndReverse(p, pObj, i)
int Gia_ManHashDualMiter(Gia_Man_t *p, Vec_Int_t *vOuts)
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
void Gia_ManHashAlloc(Gia_Man_t *p)
#define Gia_ManForEachPi(p, pObj, i)
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
#define Gia_ManForEachObjVecStart(vVec, p, pObj, i, Start)
int Gia_ManHashOr(Gia_Man_t *p, int iLit0, int iLit1)
struct Gia_Obj_t_ Gia_Obj_t
int Gia_ManHashXor(Gia_Man_t *p, int iLit0, int iLit1)
void Gia_ManFillValue(Gia_Man_t *p)
struct Gia_Man_t_ Gia_Man_t
#define Gia_ManForEachObjVec(vVec, p, pObj, i)
int Gia_ManHashMux(Gia_Man_t *p, int iCtrl, int iData1, int iData0)
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
void Gia_ManIncrementTravId(Gia_Man_t *p)
#define Gia_ManForEachCo(p, pObj, i)
#define Gia_ManForEachCi(p, pObj, i)
void Gia_ManHashStop(Gia_Man_t *p)
void * Mf_ManGenerateCnf(Gia_Man_t *pGia, int nLutSize, int fCnfObjIds, int fAddOrCla, int fMapping, int fVerbose)
#define Gia_ManForEachCiId(p, Id, i)
void Extra_PrintBinary(FILE *pFile, unsigned Sign[], int nBits)
typedefABC_NAMESPACE_HEADER_START struct Abc_RData_t_ Abc_RData_t
INCLUDES ///.
unsigned __int64 word
DECLARATIONS ///.
void * Cnf_DataWriteIntoSolver(Cnf_Dat_t *p, int nFrames, int fInit)
sat_solver * sat_solver_new(void)
int sat_solver_nconflicts(sat_solver *s)
int sat_solver_nclauses(sat_solver *s)
void sat_solver_setnvars(sat_solver *s, int n)
int sat_solver_nvars(sat_solver *s)
void sat_solver_delete(sat_solver *s)
bmcg_sat_solver * pSatSynG
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.