58int Abc_NtkMiterSat(
Abc_Ntk_t * pNtk, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit,
int fVerbose, ABC_INT64_T * pNumConfs, ABC_INT64_T * pNumInspects )
70 assert( Abc_NtkLatchNum(pNtk) == 0 );
103 status =
sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)nConfLimit, (ABC_INT64_T)nInsLimit, (ABC_INT64_T)0, (ABC_INT64_T)0 );
109 else if ( status ==
l_True )
130 Vec_IntFree( vCiIds );
163 int * pResult = NULL;
194 vCiIds = Vec_IntAlloc( Abc_NtkCiNum(pNtk) );
196 Vec_IntPush( vCiIds, (
int)(ABC_PTRINT_T)pObj->
pCopy );
217 Vec_IntPush( vVars, toLitCond( (
int)(ABC_PTRINT_T)Abc_ObjRegular(pNode)->pCopy, Abc_ObjIsComplement(pNode) ) );
240 Vec_IntPush( vVars, toLitCond( (
int)(ABC_PTRINT_T)Abc_ObjRegular(pNode)->pCopy, Abc_ObjIsComplement(pNode) ) );
261 assert( !Abc_ObjIsComplement( pNode ) );
262 assert( Abc_ObjIsNode( pNode ) );
265 Var = (int)(ABC_PTRINT_T)pNode->
pCopy;
269 for ( i = 0; i < vSuper->nSize; i++ )
273 fComp1 = Abc_ObjIsComplement((
Abc_Obj_t *)vSuper->pArray[i]);
275 Var1 = (int)(ABC_PTRINT_T)Abc_ObjRegular((
Abc_Obj_t *)vSuper->pArray[i])->pCopy;
285 Vec_IntPush( vVars, toLitCond(
Var1, fComp1) );
286 Vec_IntPush( vVars, toLitCond(
Var, 1 ) );
294 for ( i = 0; i < vSuper->nSize; i++ )
298 fComp1 = Abc_ObjIsComplement((
Abc_Obj_t *)vSuper->pArray[i]);
300 Var1 = (int)(ABC_PTRINT_T)Abc_ObjRegular((
Abc_Obj_t *)vSuper->pArray[i])->pCopy;
303 Vec_IntPush( vVars, toLitCond(
Var1, !fComp1) );
305 Vec_IntPush( vVars, toLitCond(
Var, 0) );
322 int VarF, VarI, VarT, VarE, fCompT, fCompE;
325 assert( !Abc_ObjIsComplement( pNode ) );
328 VarF = (int)(ABC_PTRINT_T)pNode->
pCopy;
329 VarI = (int)(ABC_PTRINT_T)pNodeC->
pCopy;
330 VarT = (int)(ABC_PTRINT_T)Abc_ObjRegular(pNodeT)->
pCopy;
331 VarE = (int)(ABC_PTRINT_T)Abc_ObjRegular(pNodeE)->
pCopy;
338 fCompT = Abc_ObjIsComplement(pNodeT);
339 fCompE = Abc_ObjIsComplement(pNodeE);
348 Vec_IntPush( vVars, toLitCond(VarI, 1) );
349 Vec_IntPush( vVars, toLitCond(VarT, 1^fCompT) );
350 Vec_IntPush( vVars, toLitCond(VarF, 0) );
354 Vec_IntPush( vVars, toLitCond(VarI, 1) );
355 Vec_IntPush( vVars, toLitCond(VarT, 0^fCompT) );
356 Vec_IntPush( vVars, toLitCond(VarF, 1) );
360 Vec_IntPush( vVars, toLitCond(VarI, 0) );
361 Vec_IntPush( vVars, toLitCond(VarE, 1^fCompE) );
362 Vec_IntPush( vVars, toLitCond(VarF, 0) );
366 Vec_IntPush( vVars, toLitCond(VarI, 0) );
367 Vec_IntPush( vVars, toLitCond(VarE, 0^fCompE) );
368 Vec_IntPush( vVars, toLitCond(VarF, 1) );
382 Vec_IntPush( vVars, toLitCond(VarT, 0^fCompT) );
383 Vec_IntPush( vVars, toLitCond(VarE, 0^fCompE) );
384 Vec_IntPush( vVars, toLitCond(VarF, 1) );
388 Vec_IntPush( vVars, toLitCond(VarT, 1^fCompT) );
389 Vec_IntPush( vVars, toLitCond(VarE, 1^fCompE) );
390 Vec_IntPush( vVars, toLitCond(VarF, 0) );
407 int RetValue1, RetValue2, i;
409 if ( Abc_ObjRegular(pNode)->fMarkB )
412 for ( i = 0; i < vSuper->nSize; i++ )
413 if ( vSuper->pArray[i] == pNode )
416 for ( i = 0; i < vSuper->nSize; i++ )
417 if ( vSuper->pArray[i] == Abc_ObjNot(pNode) )
424 if ( Abc_ObjIsComplement(pNode) || !Abc_ObjIsNode(pNode) || Abc_ObjFanoutNum(pNode) > 1 || (fStopAtMux &&
Abc_NodeIsMuxType(pNode)) )
426 Vec_PtrPush( vSuper, pNode );
427 Abc_ObjRegular(pNode)->fMarkB = 1;
430 assert( !Abc_ObjIsComplement(pNode) );
431 assert( Abc_ObjIsNode(pNode) );
435 if ( RetValue1 == -1 || RetValue2 == -1 )
438 return RetValue1 || RetValue2;
455 assert( !Abc_ObjIsComplement(pNode) );
457 Vec_PtrClear( vNodes );
459 assert( vNodes->nSize > 1 );
461 for ( i = 0; i < vNodes->nSize; i++ )
462 Abc_ObjRegular((
Abc_Obj_t *)vNodes->pArray[i])->fMarkB = 0;
465 if ( RetValue == -1 )
486 return (
int)(100000000.0 * (1 + 0.01 * pObj->
Level));
503 Abc_Obj_t * pNode, * pFanin, * pNodeC, * pNodeT, * pNodeE;
506 int i, k, fUseMuxes = 1;
510 assert( Abc_NtkIsStrash(pNtk) );
517 vNodes = Vec_PtrAlloc( 1000 );
518 vSuper = Vec_PtrAlloc( 100 );
519 vVars = Vec_IntAlloc( 100 );
525 Vec_PtrPush( vNodes, pNode );
537 Vec_PtrClear( vSuper );
541 pFanin = Abc_ObjFanin0(pNode);
543 if ( pFanin->
fMarkA == 0 )
547 Vec_PtrPush( vNodes, pFanin );
550 Vec_PtrPush( vSuper, Abc_ObjChild0(pNode) );
559 assert( !Abc_ObjIsComplement(pNode) );
560 if ( !Abc_AigNodeIsAnd(pNode) )
570 Vec_PtrClear( vSuper );
571 Vec_PtrPush( vSuper, pNodeC );
572 Vec_PtrPush( vSuper, pNodeT );
573 Vec_PtrPush( vSuper, pNodeE );
577 pFanin = Abc_ObjRegular(pFanin);
578 if ( pFanin->
fMarkA == 0 )
582 Vec_PtrPush( vNodes, pFanin );
596 pFanin = Abc_ObjRegular(pFanin);
597 if ( pFanin->
fMarkA == 0 )
601 Vec_PtrPush( vNodes, pFanin );
605 if ( vSuper->nSize == 0 )
647 Vec_IntFree( vVars );
648 Vec_PtrFree( vNodes );
649 Vec_PtrFree( vSuper );
670 assert( Abc_NtkIsStrash(pNtk) || Abc_NtkIsBddLogic(pNtk) );
671 if ( Abc_NtkIsBddLogic(pNtk) )
672 return Abc_NtkMiterSatCreateLogic(pNtk, fAllPrimes);
715 nFanins = Abc_ObjFaninNum( pNode );
723 if ( !Cudd_IsComplement(pNode->
pData) )
724 Vec_IntPush( vVars, toLit(pNode->
Id) );
726 Vec_IntPush( vVars, lit_neg(toLit(pNode->
Id)) );
730 printf(
"The CNF is trivially UNSAT.\n" );
740 pCube = pSop0 + c * (nFanins + 3);
747 if ( pCube[i] ==
'0' )
748 Vec_IntPush( vVars, toLit(pFanin->
Id) );
749 else if ( pCube[i] ==
'1' )
750 Vec_IntPush( vVars, lit_neg(toLit(pFanin->
Id)) );
752 Vec_IntPush( vVars, lit_neg(toLit(pNode->
Id)) );
756 printf(
"The CNF is trivially UNSAT.\n" );
765 pCube = pSop1 + c * (nFanins + 3);
772 if ( pCube[i] ==
'0' )
773 Vec_IntPush( vVars, toLit(pFanin->
Id) );
774 else if ( pCube[i] ==
'1' )
775 Vec_IntPush( vVars, lit_neg(toLit(pFanin->
Id)) );
777 Vec_IntPush( vVars, toLit(pNode->
Id) );
781 printf(
"The CNF is trivially UNSAT.\n" );
804 pFanin = Abc_ObjFanin0(pNode);
805 if ( Abc_ObjFaninC0(pNode) )
808 Vec_IntPush( vVars, toLit(pFanin->
Id) );
809 Vec_IntPush( vVars, toLit(pNode->
Id) );
813 printf(
"The CNF is trivially UNSAT.\n" );
818 Vec_IntPush( vVars, lit_neg(toLit(pFanin->
Id)) );
819 Vec_IntPush( vVars, lit_neg(toLit(pNode->
Id)) );
823 printf(
"The CNF is trivially UNSAT.\n" );
830 Vec_IntPush( vVars, lit_neg(toLit(pFanin->
Id)) );
831 Vec_IntPush( vVars, toLit(pNode->
Id) );
835 printf(
"The CNF is trivially UNSAT.\n" );
840 Vec_IntPush( vVars, toLit(pFanin->
Id) );
841 Vec_IntPush( vVars, lit_neg(toLit(pNode->
Id)) );
845 printf(
"The CNF is trivially UNSAT.\n" );
851 Vec_IntPush( vVars, toLit(pNode->
Id) );
855 printf(
"The CNF is trivially UNSAT.\n" );
879 char * pSop0, * pSop1;
882 assert( Abc_NtkIsBddLogic(pNtk) );
892 vCube = Vec_StrAlloc( 100 );
893 vVars = Vec_IntAlloc( 100 );
901 if ( !Abc_NodeAddClauses( pSat, pSop0, pSop1, pNode, vVars ) )
911 if ( !Abc_NodeAddClausesTop( pSat, pNode, vVars ) )
922 Vec_StrFree( vCube );
923 Vec_IntFree( vVars );
930sat_solver * Abc_NtkMiterSatCreateLogic(
Abc_Ntk_t * pNtk,
int fAllPrimes ) {
return NULL; }
950 Abc_Obj_t * pObj, * ppNodes[2], * ppRoots[2];
955 if ( nQueens <= 0 && nQueens >= nVars )
957 printf(
"The number of queens (Q = %d) should belong to the interval: 0 < Q < %d.\n", nQueens, nQueens);
960 assert( nQueens > 0 && nQueens < nVars );
963 sprintf( Command,
"gen -s -N %d sorter%d.blif", nVars, nVars );
966 fprintf( stdout,
"Cannot execute command \"%s\".\n", Command );
970 sprintf( Command,
"read sorter%d.blif; strash", nVars );
973 fprintf( stdout,
"Cannot execute command \"%s\".\n", Command );
980 ppNodes[0] = Abc_NtkPo( pNtk, nVars - nQueens - 1 );
981 ppNodes[1] = Abc_NtkPo( pNtk, nVars - nQueens );
982 ppRoots[0] = Abc_ObjFanin0( ppNodes[0] );
983 ppRoots[1] = Abc_ObjFanin0( ppNodes[1] );
1015 pFile = fopen( pFileName,
"w" );
1016 fprintf( pFile,
"c CNF for %d-bit sorter with %d bits set to 1 generated by ABC.\n", nVars, nQueens );
1017 fprintf( pFile,
"p cnf %d %d\n", Counter, 3 * Vec_PtrSize(vNodes) + 2 );
1021 fprintf( pFile,
"%d %s%d %s%d 0\n", 1+(
int)(ABC_PTRINT_T)pObj->
pCopy,
1022 Abc_ObjFaninC0(pObj)?
"" :
"-", 1+(
int)(ABC_PTRINT_T)Abc_ObjFanin0(pObj)->pCopy,
1023 Abc_ObjFaninC1(pObj)?
"" :
"-", 1+(
int)(ABC_PTRINT_T)Abc_ObjFanin1(pObj)->pCopy );
1025 fprintf( pFile,
"-%d %s%d 0\n", 1+(
int)(ABC_PTRINT_T)pObj->
pCopy,
1026 Abc_ObjFaninC0(pObj)?
"-" :
"", 1+(
int)(ABC_PTRINT_T)Abc_ObjFanin0(pObj)->pCopy );
1027 fprintf( pFile,
"-%d %s%d 0\n", 1+(
int)(ABC_PTRINT_T)pObj->
pCopy,
1028 Abc_ObjFaninC1(pObj)?
"-" :
"", 1+(
int)(ABC_PTRINT_T)Abc_ObjFanin1(pObj)->pCopy );
1030 Vec_PtrFree( vNodes );
1037 fprintf( pFile,
"%s%d 0\n",
1038 Abc_ObjFaninC0(ppNodes[0])?
"" :
"-", 1+(
int)(ABC_PTRINT_T)Abc_ObjFanin0(ppNodes[0])->pCopy );
1040 fprintf( pFile,
"%s%d 0\n",
1041 Abc_ObjFaninC0(ppNodes[1])?
"-" :
"", 1+(
int)(ABC_PTRINT_T)Abc_ObjFanin0(ppNodes[1])->pCopy );
void * Abc_NtkMiterSatCreate(Abc_Ntk_t *pNtk, int fAllPrimes)
int Abc_NtkClauseTop(sat_solver *pSat, Vec_Ptr_t *vNodes, Vec_Int_t *vVars)
void Abc_NtkWriteSorterCnf(char *pFileName, int nVars, int nQueens)
int Abc_NtkCollectSupergate_rec(Abc_Obj_t *pNode, Vec_Ptr_t *vSuper, int fFirst, int fStopAtMux)
int Abc_NtkClauseAnd(sat_solver *pSat, Abc_Obj_t *pNode, Vec_Ptr_t *vSuper, Vec_Int_t *vVars)
int Abc_NtkNodeFactor(Abc_Obj_t *pObj, int nLevelMax)
int Abc_NtkMiterSatCreateInt(sat_solver *pSat, Abc_Ntk_t *pNtk)
Vec_Int_t * Abc_NtkGetCiSatVarNums(Abc_Ntk_t *pNtk)
void Abc_NtkCollectSupergate(Abc_Obj_t *pNode, int fStopAtMux, Vec_Ptr_t *vNodes)
int Abc_NtkMiterSat(Abc_Ntk_t *pNtk, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, int fVerbose, ABC_INT64_T *pNumConfs, ABC_INT64_T *pNumInspects)
FUNCTION DEFINITIONS ///.
int Abc_NtkClauseMux(sat_solver *pSat, Abc_Obj_t *pNode, Abc_Obj_t *pNodeC, Abc_Obj_t *pNodeT, Abc_Obj_t *pNodeE, Vec_Int_t *vVars)
int * Abc_NtkSolveGiaMiter(Gia_Man_t *p)
int Abc_NtkClauseTriv(sat_solver *pSat, Abc_Obj_t *pNode, Vec_Int_t *vVars)
struct Abc_Obj_t_ Abc_Obj_t
#define Abc_NtkForEachCo(pNtk, pCo, i)
#define Abc_NtkForEachPo(pNtk, pPo, i)
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
#define Abc_ObjForEachFanin(pObj, pFanin, i)
struct Abc_Ntk_t_ Abc_Ntk_t
ABC_DLL void Abc_NodeBddToCnf(Abc_Obj_t *pNode, Mem_Flex_t *pMmMan, Vec_Str_t *vCube, int fAllPrimes, char **ppSop0, char **ppSop1)
#define Abc_NtkForEachPi(pNtk, pPi, i)
ABC_DLL int Abc_SopGetVarNum(char *pSop)
#define Abc_NtkForEachCi(pNtk, pCi, i)
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
ABC_DLL Vec_Ptr_t * Abc_NtkDfsNodes(Abc_Ntk_t *pNtk, Abc_Obj_t **ppNodes, int nNodes)
ABC_DLL int Abc_NodeIsMuxType(Abc_Obj_t *pNode)
ABC_DLL Abc_Obj_t * Abc_NodeRecognizeMux(Abc_Obj_t *pNode, Abc_Obj_t **ppNodeT, Abc_Obj_t **ppNodeE)
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
#define Abc_NtkForEachNode(pNtk, pNode, i)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
ABC_DLL Abc_Frame_t * Abc_FrameGetGlobalFrame()
void Aig_ManStop(Aig_Man_t *p)
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
ABC_DLL Abc_Ntk_t * Abc_FrameReadNtk(Abc_Frame_t *p)
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
struct Vec_Str_t_ Vec_Str_t
#define sat_solver_addclause
ABC_DLL int Cmd_CommandExecute(Abc_Frame_t *pAbc, const char *sCommand)
Aig_Man_t * Gia_ManToAig(Gia_Man_t *p, int fChoices)
ABC_NAMESPACE_IMPL_START Abc_Ntk_t * Abc_NtkFromAigPhase(Aig_Man_t *pMan)
DECLARATIONS ///.
struct Gia_Man_t_ Gia_Man_t
Mem_Flex_t * Mem_FlexStart()
void Mem_FlexStop(Mem_Flex_t *p, int fVerbose)
struct Mem_Flex_t_ Mem_Flex_t
sat_solver * sat_solver_new(void)
int sat_solver_simplify(sat_solver *s)
void sat_solver_store_free(sat_solver *s)
void sat_solver_store_write(sat_solver *s, char *pFileName)
void sat_solver_store_alloc(sat_solver *s)
void sat_solver_store_mark_roots(sat_solver *s)
void sat_solver_delete(sat_solver *s)
int * Sat_SolverGetModel(sat_solver *p, int *pVars, int nVars)
void Sat_SolverPrintStats(FILE *pFile, sat_solver *p)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.