00001
00021 #include "msatInt.h"
00022
00026
00027 static char * Msat_TimeStamp();
00028
00032
00044 void Msat_SolverPrintAssignment( Msat_Solver_t * p )
00045 {
00046 int i;
00047 printf( "Current assignments are: \n" );
00048 for ( i = 0; i < p->nVars; i++ )
00049 printf( "%d", i % 10 );
00050 printf( "\n" );
00051 for ( i = 0; i < p->nVars; i++ )
00052 if ( p->pAssigns[i] == MSAT_VAR_UNASSIGNED )
00053 printf( "." );
00054 else
00055 {
00056 assert( i == MSAT_LIT2VAR(p->pAssigns[i]) );
00057 if ( MSAT_LITSIGN(p->pAssigns[i]) )
00058 printf( "0" );
00059 else
00060 printf( "1" );
00061 }
00062 printf( "\n" );
00063 }
00064
00076 void Msat_SolverPrintClauses( Msat_Solver_t * p )
00077 {
00078 Msat_Clause_t ** pClauses;
00079 int nClauses, i;
00080
00081 printf( "Original clauses: \n" );
00082 nClauses = Msat_ClauseVecReadSize( p->vClauses );
00083 pClauses = Msat_ClauseVecReadArray( p->vClauses );
00084 for ( i = 0; i < nClauses; i++ )
00085 {
00086 printf( "%3d: ", i );
00087 Msat_ClausePrint( pClauses[i] );
00088 }
00089
00090 printf( "Learned clauses: \n" );
00091 nClauses = Msat_ClauseVecReadSize( p->vLearned );
00092 pClauses = Msat_ClauseVecReadArray( p->vLearned );
00093 for ( i = 0; i < nClauses; i++ )
00094 {
00095 printf( "%3d: ", i );
00096 Msat_ClausePrint( pClauses[i] );
00097 }
00098
00099 printf( "Variable activity: \n" );
00100 for ( i = 0; i < p->nVars; i++ )
00101 printf( "%3d : %.4f\n", i, p->pdActivity[i] );
00102 }
00103
00115 void Msat_SolverWriteDimacs( Msat_Solver_t * p, char * pFileName )
00116 {
00117 FILE * pFile;
00118 Msat_Clause_t ** pClauses;
00119 int nClauses, i;
00120
00121 nClauses = Msat_ClauseVecReadSize(p->vClauses) + Msat_ClauseVecReadSize(p->vLearned);
00122 for ( i = 0; i < p->nVars; i++ )
00123 nClauses += ( p->pLevel[i] == 0 );
00124
00125 pFile = fopen( pFileName, "wb" );
00126 fprintf( pFile, "c Produced by Msat_SolverWriteDimacs() on %s\n", Msat_TimeStamp() );
00127 fprintf( pFile, "p cnf %d %d\n", p->nVars, nClauses );
00128
00129 nClauses = Msat_ClauseVecReadSize( p->vClauses );
00130 pClauses = Msat_ClauseVecReadArray( p->vClauses );
00131 for ( i = 0; i < nClauses; i++ )
00132 Msat_ClauseWriteDimacs( pFile, pClauses[i], 1 );
00133
00134 nClauses = Msat_ClauseVecReadSize( p->vLearned );
00135 pClauses = Msat_ClauseVecReadArray( p->vLearned );
00136 for ( i = 0; i < nClauses; i++ )
00137 Msat_ClauseWriteDimacs( pFile, pClauses[i], 1 );
00138
00139
00140 for ( i = 0; i < p->nVars; i++ )
00141 if ( p->pLevel[i] == 0 )
00142 fprintf( pFile, "%s%d 0\n", ((p->pAssigns[i]&1)? "-": ""), i + 1 );
00143
00144 fprintf( pFile, "\n" );
00145 fclose( pFile );
00146 }
00147
00148
00160 char * Msat_TimeStamp()
00161 {
00162 static char Buffer[100];
00163 time_t ltime;
00164 char * TimeStamp;
00165
00166 time( <ime );
00167 TimeStamp = asctime( localtime( <ime ) );
00168 TimeStamp[ strlen(TimeStamp) - 1 ] = 0;
00169 strcpy( Buffer, TimeStamp );
00170 return Buffer;
00171 }
00172
00176
00177