ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
msatSolverSearch.c File Reference
#include "msatInt.h"
Include dependency graph for msatSolverSearch.c:

Go to the source code of this file.

Functions

int Msat_SolverAssume (Msat_Solver_t *p, Msat_Lit_t Lit)
 FUNCTION DEFINITIONS ///.
 
void Msat_SolverCancelUntil (Msat_Solver_t *p, int Level)
 
int Msat_SolverEnqueue (Msat_Solver_t *p, Msat_Lit_t Lit, Msat_Clause_t *pC)
 
Msat_Clause_tMsat_SolverPropagate (Msat_Solver_t *p)
 
int Msat_SolverSimplifyDB (Msat_Solver_t *p)
 
void Msat_SolverRemoveLearned (Msat_Solver_t *p)
 
void Msat_SolverRemoveMarked (Msat_Solver_t *p)
 
Msat_Type_t Msat_SolverSearch (Msat_Solver_t *p, int nConfLimit, int nLearnedLimit, int nBackTrackLimit, Msat_SearchParams_t *pPars)
 

Function Documentation

◆ Msat_SolverAssume()

int Msat_SolverAssume ( Msat_Solver_t * p,
Msat_Lit_t Lit )

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis [Makes the next assumption (Lit).]

Description [Returns FALSE if immediate conflict.]

SideEffects []

SeeAlso []

Definition at line 51 of file msatSolverSearch.c.

52{
53 assert( Msat_QueueReadSize(p->pQueue) == 0 );
54 if ( p->fVerbose )
55 printf(L_IND "assume(" L_LIT ")\n", L_ind, L_lit(Lit));
56 Msat_IntVecPush( p->vTrailLim, Msat_IntVecReadSize(p->vTrail) );
57// assert( Msat_IntVecReadSize(p->vTrailLim) <= Msat_IntVecReadSize(p->vTrail) + 1 );
58// assert( Msat_IntVecReadSize( p->vTrailLim ) < p->nVars );
59 return Msat_SolverEnqueue( p, Lit, NULL );
60}
Cube * p
Definition exorList.c:222
int Msat_QueueReadSize(Msat_Queue_t *p)
Definition msatQueue.c:91
int Msat_SolverEnqueue(Msat_Solver_t *p, Msat_Lit_t Lit, Msat_Clause_t *pC)
int Msat_IntVecReadSize(Msat_IntVec_t *p)
Definition msatVec.c:233
void Msat_IntVecPush(Msat_IntVec_t *p, int Entry)
Definition msatVec.c:351
#define L_ind
Definition satSolver.c:41
#define L_IND
Definition satSolver.c:40
#define L_lit(p)
Definition satSolver.c:43
#define L_LIT
Definition satSolver.c:42
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Msat_SolverCancelUntil()

void Msat_SolverCancelUntil ( Msat_Solver_t * p,
int Level )

Function*************************************************************

Synopsis [Reverts to the state at given level.]

Description []

SideEffects []

SeeAlso []

Definition at line 128 of file msatSolverSearch.c.

129{
130 while ( Msat_IntVecReadSize(p->vTrailLim) > Level )
131 Msat_SolverCancel(p);
132}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Msat_SolverEnqueue()

int Msat_SolverEnqueue ( Msat_Solver_t * p,
Msat_Lit_t Lit,
Msat_Clause_t * pC )

Function*************************************************************

Synopsis [Enqueues one variable assignment.]

Description [Puts a new fact on the propagation queue and immediately updates the variable value. Should a conflict arise, FALSE is returned. Otherwise returns TRUE.]

SideEffects []

SeeAlso []

Definition at line 173 of file msatSolverSearch.c.

174{
176
177 // skip literals that are not in the current cone
178 if ( !Msat_IntVecReadEntry( p->vVarsUsed, Var ) )
179 return 1;
180
181// assert( Msat_QueueReadSize(p->pQueue) == Msat_IntVecReadSize(p->vTrail) );
182 // if the literal is assigned
183 // return 1 if the assignment is consistent
184 // return 0 if the assignment is inconsistent (conflict)
185 if ( p->pAssigns[Var] != MSAT_VAR_UNASSIGNED )
186 return p->pAssigns[Var] == Lit;
187 // new fact - store it
188 if ( p->fVerbose )
189 {
190// printf(L_IND"bind("L_LIT")\n", L_ind, L_lit(Lit));
191 printf(L_IND "bind(" L_LIT ") ", L_ind, L_lit(Lit));
193 }
194 p->pAssigns[Var] = Lit;
195 p->pLevel[Var] = Msat_IntVecReadSize(p->vTrailLim);
196// p->pReasons[Var] = p->pLevel[Var]? pC: NULL;
197 p->pReasons[Var] = pC;
198 Msat_IntVecPush( p->vTrail, Lit );
199 Msat_QueueInsert( p->pQueue, Lit );
200
201 Msat_OrderVarAssigned( p->pOrder, Var );
202 return 1;
203}
int Var
Definition exorList.c:228
void Msat_ClausePrintSymbols(Msat_Clause_t *pC)
Definition msatClause.c:515
#define MSAT_VAR_UNASSIGNED
Definition msatInt.h:68
void Msat_QueueInsert(Msat_Queue_t *p, int Lit)
Definition msatQueue.c:107
void Msat_OrderVarAssigned(Msat_Order_t *p, int Var)
Definition msatOrderH.c:220
int Msat_Var_t
Definition msatInt.h:66
#define MSAT_LIT2VAR(l)
Definition msat.h:59
int Msat_IntVecReadEntry(Msat_IntVec_t *p, int i)
Definition msatVec.c:249
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Msat_SolverPropagate()

Msat_Clause_t * Msat_SolverPropagate ( Msat_Solver_t * p)

Function*************************************************************

Synopsis [Propagates the assignments in the queue.]

Description [Propagates all enqueued facts. If a conflict arises, the conflicting clause is returned, otherwise NULL.]

SideEffects [The propagation queue is empty, even if there was a conflict.]

SeeAlso []

Definition at line 217 of file msatSolverSearch.c.

218{
219 Msat_ClauseVec_t ** pvWatched = p->pvWatched;
220 Msat_Clause_t ** pClauses;
221 Msat_Clause_t * pConflict;
222 Msat_Lit_t Lit, Lit_out;
223 int i, j, nClauses;
224
225 // propagate all the literals in the queue
226 while ( (Lit = Msat_QueueExtract( p->pQueue )) >= 0 )
227 {
228 p->Stats.nPropagations++;
229 // get the clauses watched by this literal
230 nClauses = Msat_ClauseVecReadSize( pvWatched[Lit] );
231 pClauses = Msat_ClauseVecReadArray( pvWatched[Lit] );
232 // go through the watched clauses and decide what to do with them
233 for ( i = j = 0; i < nClauses; i++ )
234 {
235 p->Stats.nInspects++;
236 // clear the returned literal
237 Lit_out = -1;
238 // propagate the clause
239 if ( !Msat_ClausePropagate( pClauses[i], Lit, p->pAssigns, &Lit_out ) )
240 { // the clause is unit
241 // "Lit_out" contains the new assignment to be enqueued
242 if ( Msat_SolverEnqueue( p, Lit_out, pClauses[i] ) )
243 { // consistent assignment
244 // no changes to the implication queue; the watch is the same too
245 pClauses[j++] = pClauses[i];
246 continue;
247 }
248 // remember the reason of conflict (will be returned)
249 pConflict = pClauses[i];
250 // leave the remaning clauses in the same watched list
251 for ( ; i < nClauses; i++ )
252 pClauses[j++] = pClauses[i];
253 Msat_ClauseVecShrink( pvWatched[Lit], j );
254 // clear the propagation queue
255 Msat_QueueClear( p->pQueue );
256 return pConflict;
257 }
258 // the clause is not unit
259 // in this case "Lit_out" contains the new watch if it has changed
260 if ( Lit_out >= 0 )
261 Msat_ClauseVecPush( pvWatched[Lit_out], pClauses[i] );
262 else // the watch did not change
263 pClauses[j++] = pClauses[i];
264 }
265 Msat_ClauseVecShrink( pvWatched[Lit], j );
266 }
267 return NULL;
268}
int Msat_ClauseVecReadSize(Msat_ClauseVec_t *p)
Msat_Clause_t ** Msat_ClauseVecReadArray(Msat_ClauseVec_t *p)
void Msat_ClauseVecPush(Msat_ClauseVec_t *p, Msat_Clause_t *Entry)
void Msat_ClauseVecShrink(Msat_ClauseVec_t *p, int nSizeNew)
int Msat_ClausePropagate(Msat_Clause_t *pC, Msat_Lit_t Lit, int *pAssigns, Msat_Lit_t *pLit_out)
Definition msatClause.c:335
void Msat_QueueClear(Msat_Queue_t *p)
Definition msatQueue.c:149
typedefABC_NAMESPACE_HEADER_START struct Msat_Clause_t_ Msat_Clause_t
INCLUDES ///.
Definition msatInt.h:57
int Msat_QueueExtract(Msat_Queue_t *p)
Definition msatQueue.c:131
int Msat_Lit_t
Definition msatInt.h:65
struct Msat_ClauseVec_t_ Msat_ClauseVec_t
Definition msat.h:46
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Msat_SolverRemoveLearned()

void Msat_SolverRemoveLearned ( Msat_Solver_t * p)

Function*************************************************************

Synopsis [Removes the learned clauses.]

Description []

SideEffects []

SeeAlso []

Definition at line 371 of file msatSolverSearch.c.

372{
373 Msat_Clause_t ** pLearned;
374 int nLearned, i;
375
376 // discard the learned clauses
377 nLearned = Msat_ClauseVecReadSize( p->vLearned );
378 pLearned = Msat_ClauseVecReadArray( p->vLearned );
379 for ( i = 0; i < nLearned; i++ )
380 {
381 assert( !Msat_ClauseIsLocked( p, pLearned[i]) );
382
383 Msat_ClauseFree( p, pLearned[i], 1 );
384 }
385 Msat_ClauseVecShrink( p->vLearned, 0 );
386 p->nClauses = Msat_ClauseVecReadSize(p->vClauses);
387
388 for ( i = 0; i < p->nVarsAlloc; i++ )
389 p->pReasons[i] = NULL;
390}
int Msat_ClauseIsLocked(Msat_Solver_t *p, Msat_Clause_t *pC)
Definition msatClause.c:278
void Msat_ClauseFree(Msat_Solver_t *p, Msat_Clause_t *pC, int fRemoveWatched)
Definition msatClause.c:223
Here is the call graph for this function:

◆ Msat_SolverRemoveMarked()

void Msat_SolverRemoveMarked ( Msat_Solver_t * p)

Function*************************************************************

Synopsis [Removes the recently added clauses.]

Description []

SideEffects []

SeeAlso []

Definition at line 403 of file msatSolverSearch.c.

404{
405 Msat_Clause_t ** pLearned, ** pClauses;
406 int nLearned, nClauses, i;
407
408 // discard the learned clauses
409 nClauses = Msat_ClauseVecReadSize( p->vClauses );
410 pClauses = Msat_ClauseVecReadArray( p->vClauses );
411 for ( i = p->nClausesStart; i < nClauses; i++ )
412 {
413// assert( !Msat_ClauseIsLocked( p, pClauses[i]) );
414 Msat_ClauseFree( p, pClauses[i], 1 );
415 }
416 Msat_ClauseVecShrink( p->vClauses, p->nClausesStart );
417
418 // discard the learned clauses
419 nLearned = Msat_ClauseVecReadSize( p->vLearned );
420 pLearned = Msat_ClauseVecReadArray( p->vLearned );
421 for ( i = 0; i < nLearned; i++ )
422 {
423// assert( !Msat_ClauseIsLocked( p, pLearned[i]) );
424 Msat_ClauseFree( p, pLearned[i], 1 );
425 }
426 Msat_ClauseVecShrink( p->vLearned, 0 );
427 p->nClauses = Msat_ClauseVecReadSize(p->vClauses);
428/*
429 // undo the previous data
430 for ( i = 0; i < p->nVarsAlloc; i++ )
431 {
432 p->pAssigns[i] = MSAT_VAR_UNASSIGNED;
433 p->pReasons[i] = NULL;
434 p->pLevel[i] = -1;
435 p->pdActivity[i] = 0.0;
436 }
437 Msat_OrderClean( p->pOrder, p->nVars, NULL );
438 Msat_QueueClear( p->pQueue );
439*/
440}
Here is the call graph for this function:

◆ Msat_SolverSearch()

Msat_Type_t Msat_SolverSearch ( Msat_Solver_t * p,
int nConfLimit,
int nLearnedLimit,
int nBackTrackLimit,
Msat_SearchParams_t * pPars )

Function*************************************************************

Synopsis [The search procedure called between the restarts.]

Description [Search for a satisfying solution as long as the number of conflicts does not exceed the limit (nConfLimit) while keeping the number of learnt clauses below the provided limit (nLearnedLimit). NOTE! Use negative value for nConfLimit or nLearnedLimit to indicate infinity.]

SideEffects []

SeeAlso []

Definition at line 535 of file msatSolverSearch.c.

536{
537 Msat_Clause_t * pConf;
539 int nLevelBack, nConfs, nAssigns, Value;
540 int i;
541
542 assert( Msat_SolverReadDecisionLevel(p) == p->nLevelRoot );
543 p->Stats.nStarts++;
544 p->dVarDecay = 1 / pPars->dVarDecay;
545 p->dClaDecay = 1 / pPars->dClaDecay;
546
547 // reset the activities
548 for ( i = 0; i < p->nVars; i++ )
549 p->pdActivity[i] = (double)p->pFactors[i];
550// p->pdActivity[i] = 0.0;
551
552 nConfs = 0;
553 while ( 1 )
554 {
555 pConf = Msat_SolverPropagate( p );
556 if ( pConf != NULL ){
557 // CONFLICT
558 if ( p->fVerbose )
559 {
560// printf(L_IND"**CONFLICT**\n", L_ind);
561 printf(L_IND"**CONFLICT** ", L_ind);
563 }
564 // count conflicts
565 p->Stats.nConflicts++;
566 nConfs++;
567
568 // if top level, return UNSAT
569 if ( Msat_SolverReadDecisionLevel(p) == p->nLevelRoot )
570 return MSAT_FALSE;
571
572 // perform conflict analysis
573 Msat_SolverAnalyze( p, pConf, p->vTemp, &nLevelBack );
574 Msat_SolverCancelUntil( p, (p->nLevelRoot > nLevelBack)? p->nLevelRoot : nLevelBack );
575 Msat_SolverRecord( p, p->vTemp );
576
577 // it is important that recording is done after cancelling
578 // because canceling cleans the queue while recording adds to it
581
582 }
583 else{
584 // NO CONFLICT
585 if ( Msat_IntVecReadSize(p->vTrailLim) == 0 ) {
586 // Simplify the set of problem clauses:
587// Value = Msat_SolverSimplifyDB(p);
588// assert( Value );
589 }
590 nAssigns = Msat_IntVecReadSize( p->vTrail );
591 if ( nLearnedLimit >= 0 && Msat_ClauseVecReadSize(p->vLearned) >= nLearnedLimit + nAssigns ) {
592 // Reduce the set of learnt clauses:
593 Msat_SolverReduceDB(p);
594 }
595
596 Var = Msat_OrderVarSelect( p->pOrder );
597 if ( Var == MSAT_ORDER_UNKNOWN ) {
598 // Model found and stored in p->pAssigns
599 memcpy( p->pModel, p->pAssigns, sizeof(int) * p->nVars );
600 Msat_QueueClear( p->pQueue );
601 Msat_SolverCancelUntil( p, p->nLevelRoot );
602 return MSAT_TRUE;
603 }
604 if ( nConfLimit > 0 && nConfs > nConfLimit ) {
605 // Reached bound on number of conflicts:
606 p->dProgress = Msat_SolverProgressEstimate( p );
607 Msat_QueueClear( p->pQueue );
608 Msat_SolverCancelUntil( p, p->nLevelRoot );
609 return MSAT_UNKNOWN;
610 }
611 else if ( nBackTrackLimit > 0 && (int)p->Stats.nConflicts - p->nBackTracks > nBackTrackLimit ) {
612 // Reached bound on number of conflicts:
613 Msat_QueueClear( p->pQueue );
614 Msat_SolverCancelUntil( p, p->nLevelRoot );
615 return MSAT_UNKNOWN;
616 }
617 else{
618 // New variable decision:
619 p->Stats.nDecisions++;
620 assert( Var != MSAT_ORDER_UNKNOWN && Var >= 0 && Var < p->nVars );
621 Value = Msat_SolverAssume(p, MSAT_VAR2LIT(Var,0) );
622 assert( Value );
623 }
624 }
625 }
626}
void Msat_SolverVarDecayActivity(Msat_Solver_t *p)
GLOBAL VARIABLES ///.
void Msat_SolverClaDecayActivity(Msat_Solver_t *p)
int Msat_SolverReadDecisionLevel(Msat_Solver_t *p)
int Msat_OrderVarSelect(Msat_Order_t *p)
Definition msatOrderH.c:183
double Msat_SolverProgressEstimate(Msat_Solver_t *p)
#define MSAT_ORDER_UNKNOWN
Definition msatInt.h:70
int Msat_SolverAssume(Msat_Solver_t *p, Msat_Lit_t Lit)
FUNCTION DEFINITIONS ///.
void Msat_SolverCancelUntil(Msat_Solver_t *p, int Level)
Msat_Clause_t * Msat_SolverPropagate(Msat_Solver_t *p)
#define MSAT_VAR2LIT(v, s)
Definition msat.h:56
@ MSAT_TRUE
Definition msat.h:50
@ MSAT_FALSE
Definition msat.h:50
@ MSAT_UNKNOWN
Definition msat.h:50
char * memcpy()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Msat_SolverSimplifyDB()

int Msat_SolverSimplifyDB ( Msat_Solver_t * p)

Function*************************************************************

Synopsis [Simplifies the data base.]

Description [Simplify all constraints according to the current top-level assigment (redundant constraints may be removed altogether).]

SideEffects []

SeeAlso []

Definition at line 282 of file msatSolverSearch.c.

283{
284 Msat_ClauseVec_t * vClauses;
285 Msat_Clause_t ** pClauses;
286 int nClauses, Type, i, j;
287 int * pAssigns;
288 int Counter;
289
291 if ( Msat_SolverPropagate(p) != NULL )
292 return 0;
293//Msat_SolverPrintClauses( p );
294//Msat_SolverPrintAssignment( p );
295//printf( "Simplification\n" );
296
297 // simplify and reassign clause numbers
298 Counter = 0;
299 pAssigns = Msat_SolverReadAssignsArray( p );
300 for ( Type = 0; Type < 2; Type++ )
301 {
302 vClauses = Type? p->vLearned : p->vClauses;
303 nClauses = Msat_ClauseVecReadSize( vClauses );
304 pClauses = Msat_ClauseVecReadArray( vClauses );
305 for ( i = j = 0; i < nClauses; i++ )
306 if ( Msat_ClauseSimplify( pClauses[i], pAssigns ) )
307 Msat_ClauseFree( p, pClauses[i], 1 );
308 else
309 {
310 pClauses[j++] = pClauses[i];
311 Msat_ClauseSetNum( pClauses[i], Counter++ );
312 }
313 Msat_ClauseVecShrink( vClauses, j );
314 }
315 p->nClauses = Counter;
316 return 1;
317}
int Msat_ClauseSimplify(Msat_Clause_t *pC, int *pAssigns)
Definition msatClause.c:374
void Msat_ClauseSetNum(Msat_Clause_t *pC, int Num)
Definition msatClause.c:263
int * Msat_SolverReadAssignsArray(Msat_Solver_t *p)
Here is the call graph for this function: