Commit 1b185838 by Alan Mishchenko

Fixed the problem with 'write_cnf' after recent changes to the SAT solver.

parent 1e159a82
...@@ -38,6 +38,27 @@ static void Sat_SolverClauseWriteDimacs( FILE * pFile, clause * pC, int fIncreme ...@@ -38,6 +38,27 @@ static void Sat_SolverClauseWriteDimacs( FILE * pFile, clause * pC, int fIncreme
/**Function************************************************************* /**Function*************************************************************
Synopsis [Writes the given clause in a file in DIMACS format.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Sat_SolverClauseWriteDimacs( FILE * pFile, clause * pC, int fIncrement )
{
int i;
for ( i = 0; i < (int)pC->size; i++ )
fprintf( pFile, "%s%d ", (lit_sign(pC->lits[i])? "-": ""), lit_var(pC->lits[i]) + (fIncrement>0) );
if ( fIncrement )
fprintf( pFile, "0" );
fprintf( pFile, "\n" );
}
/**Function*************************************************************
Synopsis [Write the clauses in the solver into a file in DIMACS format.] Synopsis [Write the clauses in the solver into a file in DIMACS format.]
Description [] Description []
...@@ -47,12 +68,18 @@ static void Sat_SolverClauseWriteDimacs( FILE * pFile, clause * pC, int fIncreme ...@@ -47,12 +68,18 @@ static void Sat_SolverClauseWriteDimacs( FILE * pFile, clause * pC, int fIncreme
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
void Sat_SolverWriteDimacs( sat_solver * p, char * pFileName, lit* assumptionsBegin, lit* assumptionsEnd, int incrementVars ) void Sat_SolverWriteDimacs( sat_solver * p, char * pFileName, lit* assumpBegin, lit* assumpEnd, int incrementVars )
{ {
Sat_Mem_t * pMem = &p->Mem; Sat_Mem_t * pMem = &p->Mem;
FILE * pFile; FILE * pFile;
clause * c; clause * c;
int i, k; int i, k, nUnits;
// count the number of unit clauses
nUnits = 0;
for ( i = 0; i < p->size; i++ )
if ( p->levels[i] == 0 && p->assigns[i] != l_Undef )
nUnits++;
// start the file // start the file
pFile = fopen( pFileName, "wb" ); pFile = fopen( pFileName, "wb" );
...@@ -62,7 +89,7 @@ void Sat_SolverWriteDimacs( sat_solver * p, char * pFileName, lit* assumptionsBe ...@@ -62,7 +89,7 @@ void Sat_SolverWriteDimacs( sat_solver * p, char * pFileName, lit* assumptionsBe
return; return;
} }
// fprintf( pFile, "c CNF generated by ABC on %s\n", Extra_TimeStamp() ); // fprintf( pFile, "c CNF generated by ABC on %s\n", Extra_TimeStamp() );
fprintf( pFile, "p cnf %d %d\n", p->size, Sat_MemEntryNum(&p->Mem, 0) ); fprintf( pFile, "p cnf %d %d\n", p->size, Sat_MemEntryNum(&p->Mem, 0)+Sat_MemEntryNum(&p->Mem, 1)+nUnits+(assumpEnd-assumpBegin) );
// write the original clauses // write the original clauses
Sat_MemForEachClause( pMem, c, i, k ) Sat_MemForEachClause( pMem, c, i, k )
...@@ -80,12 +107,12 @@ void Sat_SolverWriteDimacs( sat_solver * p, char * pFileName, lit* assumptionsBe ...@@ -80,12 +107,12 @@ void Sat_SolverWriteDimacs( sat_solver * p, char * pFileName, lit* assumptionsBe
i + (int)(incrementVars>0), i + (int)(incrementVars>0),
(incrementVars) ? " 0" : ""); (incrementVars) ? " 0" : "");
// write the assumptions // write the assump
if (assumptionsBegin) { if (assumpBegin) {
for (; assumptionsBegin != assumptionsEnd; assumptionsBegin++) { for (; assumpBegin != assumpEnd; assumpBegin++) {
fprintf( pFile, "%s%d%s\n", fprintf( pFile, "%s%d%s\n",
lit_sign(*assumptionsBegin)? "-": "", lit_sign(*assumpBegin)? "-": "",
lit_var(*assumptionsBegin) + (int)(incrementVars>0), lit_var(*assumpBegin) + (int)(incrementVars>0),
(incrementVars) ? " 0" : ""); (incrementVars) ? " 0" : "");
} }
} }
...@@ -93,12 +120,18 @@ void Sat_SolverWriteDimacs( sat_solver * p, char * pFileName, lit* assumptionsBe ...@@ -93,12 +120,18 @@ void Sat_SolverWriteDimacs( sat_solver * p, char * pFileName, lit* assumptionsBe
fprintf( pFile, "\n" ); fprintf( pFile, "\n" );
fclose( pFile ); fclose( pFile );
} }
void Sat_Solver2WriteDimacs( sat_solver2 * p, char * pFileName, lit* assumptionsBegin, lit* assumptionsEnd, int incrementVars ) void Sat_Solver2WriteDimacs( sat_solver2 * p, char * pFileName, lit* assumpBegin, lit* assumpEnd, int incrementVars )
{ {
Sat_Mem_t * pMem = &p->Mem; Sat_Mem_t * pMem = &p->Mem;
FILE * pFile; FILE * pFile;
clause * c; clause * c;
int i, k; int i, k, nUnits;
// count the number of unit clauses
nUnits = 0;
for ( i = 0; i < p->size; i++ )
if ( p->levels[i] == 0 && p->assigns[i] != l_Undef )
nUnits++;
// start the file // start the file
pFile = fopen( pFileName, "wb" ); pFile = fopen( pFileName, "wb" );
...@@ -108,7 +141,7 @@ void Sat_Solver2WriteDimacs( sat_solver2 * p, char * pFileName, lit* assumptions ...@@ -108,7 +141,7 @@ void Sat_Solver2WriteDimacs( sat_solver2 * p, char * pFileName, lit* assumptions
return; return;
} }
// fprintf( pFile, "c CNF generated by ABC on %s\n", Extra_TimeStamp() ); // fprintf( pFile, "c CNF generated by ABC on %s\n", Extra_TimeStamp() );
fprintf( pFile, "p cnf %d %d\n", p->size, Sat_MemEntryNum(&p->Mem, 0) ); fprintf( pFile, "p cnf %d %d\n", p->size, Sat_MemEntryNum(&p->Mem, 0)+Sat_MemEntryNum(&p->Mem, 1)+nUnits+(assumpEnd-assumpBegin) );
// write the original clauses // write the original clauses
Sat_MemForEachClause2( pMem, c, i, k ) Sat_MemForEachClause2( pMem, c, i, k )
...@@ -126,12 +159,12 @@ void Sat_Solver2WriteDimacs( sat_solver2 * p, char * pFileName, lit* assumptions ...@@ -126,12 +159,12 @@ void Sat_Solver2WriteDimacs( sat_solver2 * p, char * pFileName, lit* assumptions
i + (int)(incrementVars>0), i + (int)(incrementVars>0),
(incrementVars) ? " 0" : ""); (incrementVars) ? " 0" : "");
// write the assumptions // write the assump
if (assumptionsBegin) { if (assumpBegin) {
for (; assumptionsBegin != assumptionsEnd; assumptionsBegin++) { for (; assumpBegin != assumpEnd; assumpBegin++) {
fprintf( pFile, "%s%d%s\n", fprintf( pFile, "%s%d%s\n",
lit_sign(*assumptionsBegin)? "-": "", lit_sign(*assumpBegin)? "-": "",
lit_var(*assumptionsBegin) + (int)(incrementVars>0), lit_var(*assumpBegin) + (int)(incrementVars>0),
(incrementVars) ? " 0" : ""); (incrementVars) ? " 0" : "");
} }
} }
...@@ -152,27 +185,6 @@ void Sat_Solver2WriteDimacs( sat_solver2 * p, char * pFileName, lit* assumptions ...@@ -152,27 +185,6 @@ void Sat_Solver2WriteDimacs( sat_solver2 * p, char * pFileName, lit* assumptions
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
void Sat_SolverClauseWriteDimacs( FILE * pFile, clause * pC, int fIncrement )
{
int i;
for ( i = 0; i < (int)pC->size; i++ )
fprintf( pFile, "%s%d ", (lit_sign(pC->lits[i])? "-": ""), lit_var(pC->lits[i]) + (fIncrement>0) );
if ( fIncrement )
fprintf( pFile, "0" );
fprintf( pFile, "\n" );
}
/**Function*************************************************************
Synopsis [Writes the given clause in a file in DIMACS format.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Sat_SolverPrintStats( FILE * pFile, sat_solver * p ) void Sat_SolverPrintStats( FILE * pFile, sat_solver * p )
{ {
// printf( "calls : %10d (%d)\n", (int)p->nCalls, (int)p->nCalls2 ); // printf( "calls : %10d (%d)\n", (int)p->nCalls, (int)p->nCalls2 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment