00001
00021 #include "msatInt.h"
00022
00026
00030
00042 bool Msat_SolverAddVar( Msat_Solver_t * p, int Level )
00043 {
00044 if ( p->nVars == p->nVarsAlloc )
00045 Msat_SolverResize( p, 2 * p->nVarsAlloc );
00046 p->pLevel[p->nVars] = Level;
00047 p->nVars++;
00048 return 1;
00049 }
00050
00062 bool Msat_SolverAddClause( Msat_Solver_t * p, Msat_IntVec_t * vLits )
00063 {
00064 Msat_Clause_t * pC;
00065 bool Value;
00066 Value = Msat_ClauseCreate( p, vLits, 0, &pC );
00067 if ( pC != NULL )
00068 Msat_ClauseVecPush( p->vClauses, pC );
00069
00070
00071 return Value;
00072 }
00073
00085 double Msat_SolverProgressEstimate( Msat_Solver_t * p )
00086 {
00087 double dProgress = 0.0;
00088 double dF = 1.0 / p->nVars;
00089 int i;
00090 for ( i = 0; i < p->nVars; i++ )
00091 if ( p->pAssigns[i] != MSAT_VAR_UNASSIGNED )
00092 dProgress += pow( dF, p->pLevel[i] );
00093 return dProgress / p->nVars;
00094 }
00095
00107 void Msat_SolverPrintStats( Msat_Solver_t * p )
00108 {
00109 printf("C solver (%d vars; %d clauses; %d learned):\n",
00110 p->nVars, Msat_ClauseVecReadSize(p->vClauses), Msat_ClauseVecReadSize(p->vLearned) );
00111 printf("starts : %lld\n", p->Stats.nStarts);
00112 printf("conflicts : %lld\n", p->Stats.nConflicts);
00113 printf("decisions : %lld\n", p->Stats.nDecisions);
00114 printf("propagations : %lld\n", p->Stats.nPropagations);
00115 printf("inspects : %lld\n", p->Stats.nInspects);
00116 }
00117
00135 bool Msat_SolverSolve( Msat_Solver_t * p, Msat_IntVec_t * vAssumps, int nBackTrackLimit, int nTimeLimit )
00136 {
00137 Msat_SearchParams_t Params = { 0.95, 0.999 };
00138 double nConflictsLimit, nLearnedLimit;
00139 Msat_Type_t Status;
00140 int timeStart = clock();
00141 int64 nConflictsOld = p->Stats.nConflicts;
00142 int64 nDecisionsOld = p->Stats.nDecisions;
00143
00144
00145
00146
00147 if ( vAssumps )
00148 {
00149 int * pAssumps, nAssumps, i;
00150
00151 assert( Msat_IntVecReadSize(p->vTrailLim) == 0 );
00152
00153 nAssumps = Msat_IntVecReadSize( vAssumps );
00154 pAssumps = Msat_IntVecReadArray( vAssumps );
00155 for ( i = 0; i < nAssumps; i++ )
00156 {
00157 if ( !Msat_SolverAssume(p, pAssumps[i]) || Msat_SolverPropagate(p) )
00158 {
00159 Msat_QueueClear( p->pQueue );
00160 Msat_SolverCancelUntil( p, 0 );
00161 return MSAT_FALSE;
00162 }
00163 }
00164 }
00165 p->nLevelRoot = Msat_SolverReadDecisionLevel(p);
00166 p->nClausesInit = Msat_ClauseVecReadSize( p->vClauses );
00167 nConflictsLimit = 100;
00168 nLearnedLimit = Msat_ClauseVecReadSize(p->vClauses) / 3;
00169 Status = MSAT_UNKNOWN;
00170 p->nBackTracks = (int)p->Stats.nConflicts;
00171 while ( Status == MSAT_UNKNOWN )
00172 {
00173 if ( p->fVerbose )
00174 printf("Solving -- conflicts=%d learnts=%d progress=%.4f %%\n",
00175 (int)nConflictsLimit, (int)nLearnedLimit, p->dProgress*100);
00176 Status = Msat_SolverSearch( p, (int)nConflictsLimit, (int)nLearnedLimit, nBackTrackLimit, &Params );
00177 nConflictsLimit *= 1.5;
00178 nLearnedLimit *= 1.1;
00179
00180 if ( nBackTrackLimit > 0 && (int)p->Stats.nConflicts - p->nBackTracks > nBackTrackLimit )
00181 break;
00182
00183 if ( nTimeLimit > 0 && clock() - timeStart >= nTimeLimit * CLOCKS_PER_SEC )
00184 break;
00185 }
00186 Msat_SolverCancelUntil( p, 0 );
00187 p->nBackTracks = (int)p->Stats.nConflicts - p->nBackTracks;
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 return Status;
00206 }
00207
00211
00212