33static inline int Cnf_Lit2Var(
int Lit ) {
return (Lit & 1)? -(Lit >> 1)-1 : (Lit >> 1)+1; }
34static inline int Cnf_Lit2Var2(
int Lit ) {
return (Lit & 1)? -(Lit >> 1) : (Lit >> 1); }
64 p->pTruths[0] =
ABC_ALLOC(
unsigned, 4 * Abc_TruthWordNum(
p->nMergeLimit) );
65 for ( i = 1; i < 4; i++ )
66 p->pTruths[i] =
p->pTruths[i-1] + Abc_TruthWordNum(
p->nMergeLimit);
67 p->vMemory = Vec_IntAlloc( 1 << 18 );
84 Vec_IntFree(
p->vMemory );
107 Vec_Int_t * vCiIds = Vec_IntAlloc( Aig_ManCiNum(
p) );
109 Vec_IntPush( vCiIds, pCnf->
pVarNums[pObj->
Id] );
158 memcpy( pCnf->
pVarNums,
p->pVarNums,
sizeof(
int) * Aig_ManObjNumMax(
p->pMan) );
159 for ( i = 1; i <
p->nClauses; i++ )
170 memcpy( pCnf->
pVarNums,
p->pVarNums,
sizeof(
int) * Aig_ManObjNumMax(
p->pMan) );
171 for ( i = 1; i <
p->nClauses; i++ )
182 pCnf =
Cnf_DataAlloc(
p->pMan,
p->nVars,
p->nClauses+Vec_IntSize(vLits),
p->nLiterals+Vec_IntSize(vLits) );
185 memcpy( pCnf->
pVarNums,
p->pVarNums,
sizeof(
int) * Aig_ManObjNumMax(
p->pMan) );
186 for ( i = 1; i <
p->nClauses; i++ )
211 Vec_IntFreeP( &
p->vMapping );
239 if (
p->pVarNums[pObj->
Id] >= 0 )
240 p->pVarNums[pObj->
Id] += nVarsPlus;
242 for ( v = 0; v <
p->nLiterals; v++ )
243 p->pClauses[0][v] += 2*nVarsPlus;
249 Vec_IntClear( vFlips );
250 for ( v = 0; v <
p->nLiterals; v++ )
251 if ( Abc_Lit2Var(
p->pClauses[0][v]) == iFlipVar )
252 Vec_IntPush( vFlips, v );
259 p->pClauses[0][iLit] = Abc_LitNot(
p->pClauses[0][iLit]) + 2*nVarsPlus;
275 FILE * pFile = stdout;
276 int * pLit, * pStop, i;
277 fprintf( pFile,
"p cnf %d %d\n",
p->nVars,
p->nClauses );
278 for ( i = 0; i <
p->nClauses; i++ )
280 for ( pLit =
p->pClauses[i], pStop =
p->pClauses[i+1]; pLit < pStop; pLit++ )
281 fprintf( pFile,
"%s%d ", Abc_LitIsCompl(*pLit) ?
"-":
"", fReadable? Abc_Lit2Var(*pLit) : Abc_Lit2Var(*pLit)+1 );
282 fprintf( pFile,
"\n" );
284 fprintf( pFile,
"\n" );
301 int * pLit, * pStop, i, VarId;
302 pFile =
gzopen( pFileName,
"wb" );
305 printf(
"Cnf_WriteIntoFile(): Output file cannot be opened.\n" );
308 gzprintf( pFile,
"c Result of efficient AIG-to-CNF conversion using package CNF\n" );
309 gzprintf( pFile,
"p cnf %d %d\n",
p->nVars,
p->nClauses );
314 gzprintf( pFile,
"%d ", fReadable? VarId : VarId+1 );
321 gzprintf( pFile,
"%d ", fReadable? VarId : VarId+1 );
324 for ( i = 0; i <
p->nClauses; i++ )
326 for ( pLit =
p->pClauses[i], pStop =
p->pClauses[i+1]; pLit < pStop; pLit++ )
327 gzprintf( pFile,
"%d ", fReadable? Cnf_Lit2Var2(*pLit) : Cnf_Lit2Var(*pLit) );
336 int * pLit, * pStop, i, VarId;
337 pFile =
gzopen( pFileName,
"wb" );
340 printf(
"Cnf_WriteIntoFile(): Output file cannot be opened.\n" );
343 gzprintf( pFile,
"c Result of efficient AIG-to-CNF conversion using package CNF\n" );
344 gzprintf( pFile,
"p cnf %d %d\n",
p->nVars,
p->nClauses );
349 gzprintf( pFile,
"%d ", fReadable? VarId : VarId+1 );
356 gzprintf( pFile,
"%d ", fReadable? VarId : VarId+1 );
363 gzprintf( pFile,
"%d ", fReadable? VarId : VarId+1 );
366 for ( i = 0; i <
p->nClauses; i++ )
368 for ( pLit =
p->pClauses[i], pStop =
p->pClauses[i+1]; pLit < pStop; pLit++ )
369 gzprintf( pFile,
"%d ", fReadable? Cnf_Lit2Var2(*pLit) : Cnf_Lit2Var(*pLit) );
390 int * pLit, * pStop, i, VarId;
396 pFile = fopen( pFileName,
"w" );
399 printf(
"Cnf_WriteIntoFile(): Output file cannot be opened.\n" );
402 fprintf( pFile,
"c Result of efficient AIG-to-CNF conversion using package CNF\n" );
403 fprintf( pFile,
"p cnf %d %d\n",
p->nVars,
p->nClauses );
406 fprintf( pFile,
"a " );
408 fprintf( pFile,
"%d ", fReadable? VarId : VarId+1 );
409 fprintf( pFile,
"0\n" );
413 fprintf( pFile,
"e " );
415 fprintf( pFile,
"%d ", fReadable? VarId : VarId+1 );
416 fprintf( pFile,
"0\n" );
418 for ( i = 0; i <
p->nClauses; i++ )
420 for ( pLit =
p->pClauses[i], pStop =
p->pClauses[i+1]; pLit < pStop; pLit++ )
421 fprintf( pFile,
"%d ", fReadable? Cnf_Lit2Var2(*pLit) : Cnf_Lit2Var(*pLit) );
422 fprintf( pFile,
"0\n" );
424 fprintf( pFile,
"\n" );
430 int * pLit, * pStop, i, VarId;
436 pFile = fopen( pFileName,
"w" );
439 printf(
"Cnf_WriteIntoFile(): Output file cannot be opened.\n" );
442 fprintf( pFile,
"c Result of efficient AIG-to-CNF conversion using package CNF\n" );
443 fprintf( pFile,
"p cnf %d %d\n",
p->nVars,
p->nClauses );
446 fprintf( pFile,
"e " );
448 fprintf( pFile,
"%d ", fReadable? VarId : VarId+1 );
449 fprintf( pFile,
"0\n" );
453 fprintf( pFile,
"a " );
455 fprintf( pFile,
"%d ", fReadable? VarId : VarId+1 );
456 fprintf( pFile,
"0\n" );
460 fprintf( pFile,
"e " );
462 fprintf( pFile,
"%d ", fReadable? VarId : VarId+1 );
463 fprintf( pFile,
"0\n" );
465 for ( i = 0; i <
p->nClauses; i++ )
467 for ( pLit =
p->pClauses[i], pStop =
p->pClauses[i+1]; pLit < pStop; pLit++ )
468 fprintf( pFile,
"%d ", fReadable? Cnf_Lit2Var2(*pLit) : Cnf_Lit2Var(*pLit) );
469 fprintf( pFile,
"0\n" );
471 fprintf( pFile,
"\n" );
494 for ( i = 0; i <
p->nClauses; i++ )
505 int nLitsAll, * pLits, Lits[2];
506 nLitsAll = 2 *
p->nVars;
507 pLits =
p->pClauses[0];
508 for ( f = 1; f < nFrames; f++ )
513 Lits[0] = (f-1)*nLitsAll + toLitCond(
p->pVarNums[pObjLi->
Id], 0 );
514 Lits[1] = f *nLitsAll + toLitCond(
p->pVarNums[pObjLo->
Id], 1 );
529 for ( i = 0; i <
p->nLiterals; i++ )
530 pLits[i] += nLitsAll;
531 for ( i = 0; i <
p->nClauses; i++ )
541 nLitsAll = (f-1) * nLitsAll;
542 for ( i = 0; i <
p->nLiterals; i++ )
543 pLits[i] -= nLitsAll;
551 Lits[0] = toLitCond(
p->pVarNums[pObjLo->
Id], 1 );
602 for ( i = 0; i <
p->nClauses; i++ )
613 int nLitsAll, * pLits, Lits[2];
614 nLitsAll = 2 *
p->nVars;
615 pLits =
p->pClauses[0];
616 for ( f = 1; f < nFrames; f++ )
621 Lits[0] = (f-1)*nLitsAll + toLitCond(
p->pVarNums[pObjLi->
Id], 0 );
622 Lits[1] = f *nLitsAll + toLitCond(
p->pVarNums[pObjLo->
Id], 1 );
637 for ( i = 0; i <
p->nLiterals; i++ )
638 pLits[i] += nLitsAll;
639 for ( i = 0; i <
p->nClauses; i++ )
649 nLitsAll = (f-1) * nLitsAll;
650 for ( i = 0; i <
p->nLiterals; i++ )
651 pLits[i] -= nLitsAll;
659 Lits[0] = toLitCond(
p->pVarNums[pObjLo->
Id], 1 );
694 pLits[i] = toLitCond( pCnf->
pVarNums[pObj->
Id], 0 );
722 pLits[i] = toLitCond( pCnf->
pVarNums[pObj->
Id], 0 );
750 Lit = toLitCond( pCnf->
pVarNums[pObj->
Id], 0 );
777 if ( !fTransformPos && Aig_ObjIsCo(pObj) )
785 iVar = lit_var(pCnf->
pClauses[0][i]);
786 assert( iVar < pCnf->nVars );
787 if ( pVarToPol[iVar] )
807 assert( iVarA > 0 && iVarB > 0 && iVarC > 0 );
809 Lits[0] = toLitCond( iVarA, 1 );
810 Lits[1] = toLitCond( iVarB, 1 );
811 Lits[2] = toLitCond( iVarC, 1 );
815 Lits[0] = toLitCond( iVarA, 1 );
816 Lits[1] = toLitCond( iVarB, 0 );
817 Lits[2] = toLitCond( iVarC, 0 );
821 Lits[0] = toLitCond( iVarA, 0 );
822 Lits[1] = toLitCond( iVarB, 1 );
823 Lits[2] = toLitCond( iVarC, 0 );
827 Lits[0] = toLitCond( iVarA, 0 );
828 Lits[1] = toLitCond( iVarB, 0 );
829 Lits[2] = toLitCond( iVarC, 1 );
#define ABC_FALLOC(type, num)
#define ABC_ALLOC(type, num)
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void Aig_MmFlexStop(Aig_MmFlex_t *p, int fVerbose)
#define Aig_ManForEachObj(p, pObj, i)
#define Aig_ManForEachCi(p, pObj, i)
ITERATORS ///.
struct Aig_Obj_t_ Aig_Obj_t
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
#define Aig_ManForEachCo(p, pObj, i)
Aig_MmFlex_t * Aig_MmFlexStart()
#define Aig_ManForEachLoSeq(p, pObj, i)
#define Aig_ManForEachLiLoSeq(p, pObjLi, pObjLo, k)
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
#define sat_solver_addclause
int Cnf_DataAddXorClause(void *pSat, int iVarA, int iVarB, int iVarC)
void * Cnf_DataWriteIntoSolver(Cnf_Dat_t *p, int nFrames, int fInit)
void Cnf_DataPrint(Cnf_Dat_t *p, int fReadable)
Cnf_Dat_t * Cnf_DataDup(Cnf_Dat_t *p)
Vec_Int_t * Cnf_DataCollectPiSatNums(Cnf_Dat_t *pCnf, Aig_Man_t *p)
void Cnf_DataWriteIntoFileInv(Cnf_Dat_t *p, char *pFileName, int fReadable, Vec_Int_t *vExists1, Vec_Int_t *vForAlls, Vec_Int_t *vExists2)
Cnf_Dat_t * Cnf_DataDupCofArray(Cnf_Dat_t *p, Vec_Int_t *vLits)
void * Cnf_DataWriteIntoSolver2(Cnf_Dat_t *p, int nFrames, int fInit)
int Cnf_DataWriteOrClause(void *p, Cnf_Dat_t *pCnf)
void Cnf_DataTranformPolarity(Cnf_Dat_t *pCnf, int fTransformPos)
Cnf_Dat_t * Cnf_DataAlloc(Aig_Man_t *pAig, int nVars, int nClauses, int nLiterals)
int Cnf_DataWriteAndClauses(void *p, Cnf_Dat_t *pCnf)
void Cnf_DataWriteIntoFileGz(Cnf_Dat_t *p, char *pFileName, int fReadable, Vec_Int_t *vForAlls, Vec_Int_t *vExists)
Cnf_Man_t * Cnf_ManStart()
FUNCTION DEFINITIONS ///.
void Cnf_DataCollectFlipLits(Cnf_Dat_t *p, int iFlipVar, Vec_Int_t *vFlips)
void * Cnf_DataWriteIntoSolverInt(void *pSolver, Cnf_Dat_t *p, int nFrames, int fInit)
Cnf_Dat_t * Cnf_DataDupCof(Cnf_Dat_t *p, int Lit)
int Cnf_DataWriteOrClause2(void *p, Cnf_Dat_t *pCnf)
void Cnf_DataLiftAndFlipLits(Cnf_Dat_t *p, int nVarsPlus, Vec_Int_t *vLits)
void Cnf_DataFree(Cnf_Dat_t *p)
void Cnf_ManStop(Cnf_Man_t *p)
void Cnf_DataWriteIntoFile(Cnf_Dat_t *p, char *pFileName, int fReadable, Vec_Int_t *vForAlls, Vec_Int_t *vExists)
void Cnf_DataWriteIntoFileInvGz(Cnf_Dat_t *p, char *pFileName, int fReadable, Vec_Int_t *vExists1, Vec_Int_t *vForAlls, Vec_Int_t *vExists2)
void Cnf_DataLift(Cnf_Dat_t *p, int nVarsPlus)
void Cnf_ReadMsops(char **ppSopSizes, char ***ppSops)
FUNCTION DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Cnf_Man_t_ Cnf_Man_t
INCLUDES ///.
struct Cnf_Dat_t_ Cnf_Dat_t
ABC_NAMESPACE_IMPL_START int ZEXPORT gzclose(gzFile file)
gzFile ZEXPORT gzopen(const char *path, const char *mode)
int ZEXPORTVA gzprintf(gzFile file, const char *format, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, int a16, int a17, int a18, int a19, int a20)
void sat_solver2_delete(sat_solver2 *s)
int sat_solver2_simplify(sat_solver2 *s)
sat_solver2 * sat_solver2_new(void)
void sat_solver2_setnvars(sat_solver2 *s, int n)
int sat_solver2_addclause(sat_solver2 *s, lit *begin, lit *end, int Id)
struct sat_solver2_t sat_solver2
sat_solver * sat_solver_new(void)
int sat_solver_simplify(sat_solver *s)
void sat_solver_setnvars(sat_solver *s, int n)
void sat_solver_delete(sat_solver *s)
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.