ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
xsatSolver.c
Go to the documentation of this file.
1
24#include <stdio.h>
25#include <assert.h>
26#include <string.h>
27#include <math.h>
28
29#include "xsatHeap.h"
30#include "xsatSolver.h"
31#include "xsatUtils.h"
32
34
38
49static inline int xSAT_SolverDecide( xSAT_Solver_t * s )
50{
51 int NextVar = VarUndef;
52
53 while ( NextVar == VarUndef || Vec_StrEntry( s->vAssigns, NextVar ) != VarX )
54 {
55 if ( xSAT_HeapSize( s->hOrder ) == 0 )
56 {
57 NextVar = VarUndef;
58 break;
59 }
60 else
61 NextVar = xSAT_HeapRemoveMin( s->hOrder );
62 }
63 return NextVar;
64}
65
78{
79 Vec_Int_t * vTemp = Vec_IntAlloc( Vec_StrSize( s->vAssigns ) );
80 int Var;
81
82 for ( Var = 0; Var < Vec_StrSize( s->vAssigns ); Var++ )
83 if ( Vec_StrEntry( s->vAssigns, Var ) == VarX )
84 Vec_IntPush( vTemp, Var );
85
86 xSAT_HeapBuild( s->hOrder, vTemp );
87 Vec_IntFree( vTemp );
88}
89
101static inline void xSAT_SolverVarActRescale( xSAT_Solver_t * s )
102{
103 int i;
104 unsigned * pActivity = ( unsigned * ) Vec_IntArray( s->vActivity );
105
106 for ( i = 0; i < Vec_IntSize( s->vActivity ); i++ )
107 pActivity[i] >>= 19;
108
109 s->nVarActInc >>= 19;
110 s->nVarActInc = Abc_MaxInt( s->nVarActInc, ( 1 << 5 ) );
111}
112
124static inline void xSAT_SolverVarActBump( xSAT_Solver_t * s, int Var )
125{
126 unsigned * pActivity = ( unsigned * ) Vec_IntArray( s->vActivity );
127
128 pActivity[Var] += s->nVarActInc;
129 if ( pActivity[Var] & 0x80000000 )
130 xSAT_SolverVarActRescale( s );
131
132 if ( xSAT_HeapInHeap( s->hOrder, Var ) )
133 xSAT_HeapDecrease( s->hOrder, Var );
134}
135
147static inline void xSAT_SolverVarActDecay( xSAT_Solver_t * s )
148{
149 s->nVarActInc += ( s->nVarActInc >> 4 );
150}
151
163static inline void xSAT_SolverClaActRescale( xSAT_Solver_t * s )
164{
165 xSAT_Clause_t * pC;
166 int i, CRef;
167
168 Vec_IntForEachEntry( s->vLearnts, CRef, i )
169 {
170 pC = xSAT_SolverReadClause( s, ( unsigned ) CRef );
171 pC->pData[pC->nSize].Act >>= 14;
172 }
173 s->nClaActInc >>= 14;
174 s->nClaActInc = Abc_MaxInt( s->nClaActInc, ( 1 << 10 ) );
175}
176
188static inline void xSAT_SolverClaActBump( xSAT_Solver_t* s, xSAT_Clause_t * pCla )
189{
190 pCla->pData[pCla->nSize].Act += s->nClaActInc;
191 if ( pCla->pData[pCla->nSize].Act & 0x80000000 )
192 xSAT_SolverClaActRescale( s );
193}
194
206static inline void xSAT_SolverClaActDecay( xSAT_Solver_t * s )
207{
208 s->nClaActInc += ( s->nClaActInc >> 10 );
209}
210
222static inline int xSAT_SolverClaCalcLBD( xSAT_Solver_t * s, xSAT_Clause_t * pCla )
223{
224 int i;
225 int nLBD = 0;
226
227 s->nStamp++;
228 for ( i = 0; i < pCla->nSize; i++ )
229 {
230 int Level = Vec_IntEntry( s->vLevels, xSAT_Lit2Var( pCla->pData[i].Lit ) );
231 if ( ( unsigned ) Vec_IntEntry( s->vStamp, Level ) != s->nStamp )
232 {
233 Vec_IntWriteEntry( s->vStamp, Level, ( int ) s->nStamp );
234 nLBD++;
235 }
236 }
237 return nLBD;
238}
239
240static inline int xSAT_SolverClaCalcLBD2( xSAT_Solver_t * s, Vec_Int_t * vLits )
241{
242 int i;
243 int nLBD = 0;
244
245 s->nStamp++;
246 for ( i = 0; i < Vec_IntSize( vLits ); i++ )
247 {
248 int Level = Vec_IntEntry( s->vLevels, xSAT_Lit2Var( Vec_IntEntry( vLits, i ) ) );
249 if ( ( unsigned ) Vec_IntEntry( s->vStamp, Level ) != s->nStamp )
250 {
251 Vec_IntWriteEntry( s->vStamp, Level, ( int ) s->nStamp );
252 nLBD++;
253 }
254 }
255 return nLBD;
256}
257
269unsigned xSAT_SolverClaNew( xSAT_Solver_t * s, Vec_Int_t * vLits , int fLearnt )
270{
271 unsigned CRef;
272 xSAT_Clause_t * pCla;
275 unsigned nWords;
276
277 assert( Vec_IntSize( vLits ) > 1);
278 assert( fLearnt == 0 || fLearnt == 1 );
279
280 nWords = 3 + fLearnt + Vec_IntSize( vLits );
281 CRef = xSAT_MemAppend( s->pMemory, nWords );
282 pCla = xSAT_SolverReadClause( s, CRef );
283 pCla->fLearnt = fLearnt;
284 pCla->fMark = 0;
285 pCla->fReallocd = 0;
286 pCla->fCanBeDel = fLearnt;
287 pCla->nSize = Vec_IntSize( vLits );
288 memcpy( &( pCla->pData[0].Lit ), Vec_IntArray( vLits ), sizeof( int ) * Vec_IntSize( vLits ) );
289
290 if ( fLearnt )
291 {
292 Vec_IntPush( s->vLearnts, CRef );
293 pCla->nLBD = xSAT_SolverClaCalcLBD2( s, vLits );
294 pCla->pData[pCla->nSize].Act = 0;
295 s->Stats.nLearntLits += Vec_IntSize( vLits );
296 xSAT_SolverClaActBump(s, pCla);
297 }
298 else
299 {
300 Vec_IntPush( s->vClauses, CRef );
301 s->Stats.nClauseLits += Vec_IntSize( vLits );
302 }
303
304 w1.CRef = CRef;
305 w2.CRef = CRef;
306 w1.Blocker = pCla->pData[1].Lit;
307 w2.Blocker = pCla->pData[0].Lit;
308
309 if ( Vec_IntSize( vLits ) == 2 )
310 {
311 xSAT_WatchListPush( xSAT_VecWatchListEntry( s->vBinWatches, xSAT_NegLit( pCla->pData[0].Lit ) ), w1 );
312 xSAT_WatchListPush( xSAT_VecWatchListEntry( s->vBinWatches, xSAT_NegLit( pCla->pData[1].Lit ) ), w2 );
313 }
314 else
315 {
316 xSAT_WatchListPush( xSAT_VecWatchListEntry( s->vWatches, xSAT_NegLit( pCla->pData[0].Lit ) ), w1 );
317 xSAT_WatchListPush( xSAT_VecWatchListEntry( s->vWatches, xSAT_NegLit( pCla->pData[1].Lit ) ), w2 );
318 }
319 return CRef;
320}
321
333int xSAT_SolverEnqueue( xSAT_Solver_t * s, int Lit, unsigned Reason )
334{
335 int Var = xSAT_Lit2Var( Lit );
336
337 Vec_StrWriteEntry( s->vAssigns, Var, (char)xSAT_LitSign( Lit ) );
338 Vec_IntWriteEntry( s->vLevels, Var, xSAT_SolverDecisionLevel( s ) );
339 Vec_IntWriteEntry( s->vReasons, Var, ( int ) Reason );
340 Vec_IntPush( s->vTrail, Lit );
341
342 return true;
343}
344
356static inline void xSAT_SolverNewDecision( xSAT_Solver_t * s, int Lit )
357{
358 assert( Vec_StrEntry( s->vAssigns, xSAT_Lit2Var( Lit ) ) == VarX );
359 s->Stats.nDecisions++;
360 Vec_IntPush( s->vTrailLim, Vec_IntSize( s->vTrail ) );
361 xSAT_SolverEnqueue( s, Lit, CRefUndef );
362}
363
376{
377 int c;
378
379 if ( xSAT_SolverDecisionLevel( s ) <= Level )
380 return;
381
382 for ( c = Vec_IntSize( s->vTrail ) - 1; c >= Vec_IntEntry( s->vTrailLim, Level ); c-- )
383 {
384 int Var = xSAT_Lit2Var( Vec_IntEntry( s->vTrail, c ) );
385
386 Vec_StrWriteEntry( s->vAssigns, Var, VarX );
387 Vec_IntWriteEntry( s->vReasons, Var, ( int ) CRefUndef );
388 Vec_StrWriteEntry( s->vPolarity, Var, ( char )xSAT_LitSign( Vec_IntEntry( s->vTrail, c ) ) );
389
390 if ( !xSAT_HeapInHeap( s->hOrder, Var ) )
391 xSAT_HeapInsert( s->hOrder, Var );
392 }
393
394 s->iQhead = Vec_IntEntry( s->vTrailLim, Level );
395 Vec_IntShrink( s->vTrail, Vec_IntEntry( s->vTrailLim, Level ) );
396 Vec_IntShrink( s->vTrailLim, Level );
397}
398
410static int xSAT_SolverIsLitRemovable( xSAT_Solver_t* s, int Lit, int MinLevel )
411{
412 int top = Vec_IntSize( s->vTagged );
413
414 assert( ( unsigned ) Vec_IntEntry( s->vReasons, xSAT_Lit2Var( Lit ) ) != CRefUndef );
415 Vec_IntClear( s->vStack );
416 Vec_IntPush( s->vStack, xSAT_Lit2Var( Lit ) );
417
418 while ( Vec_IntSize( s->vStack ) )
419 {
420 int i;
421 int v = Vec_IntPop( s->vStack );
422 xSAT_Clause_t* c = xSAT_SolverReadClause(s, ( unsigned ) Vec_IntEntry( s->vReasons, v ) );
423 int * Lits = &( c->pData[0].Lit );
424
425 assert( (unsigned) Vec_IntEntry( s->vReasons, v ) != CRefUndef);
426 if( c->nSize == 2 && Vec_StrEntry( s->vAssigns, xSAT_Lit2Var( Lits[0] ) ) == xSAT_LitSign( xSAT_NegLit( Lits[0] ) ) )
427 {
428 assert( Vec_StrEntry( s->vAssigns, xSAT_Lit2Var( Lits[1] ) ) == xSAT_LitSign( ( Lits[1] ) ) );
429 ABC_SWAP( int, Lits[0], Lits[1] );
430 }
431
432 for ( i = 1; i < c->nSize; i++ )
433 {
434 int v = xSAT_Lit2Var( Lits[i] );
435 if ( !Vec_StrEntry( s->vSeen, v ) && Vec_IntEntry( s->vLevels, v ) )
436 {
437 if ( ( unsigned ) Vec_IntEntry( s->vReasons, v ) != CRefUndef && ( ( 1 << (Vec_IntEntry( s->vLevels, v ) & 31 ) ) & MinLevel ) )
438 {
439 Vec_IntPush( s->vStack, v );
440 Vec_IntPush( s->vTagged, Lits[i] );
441 Vec_StrWriteEntry( s->vSeen, v, 1 );
442 }
443 else
444 {
445 int Lit;
446 Vec_IntForEachEntryStart( s->vTagged, Lit, i, top )
447 Vec_StrWriteEntry( s->vSeen, xSAT_Lit2Var( Lit ), 0 );
448 Vec_IntShrink( s->vTagged, top );
449 return 0;
450 }
451 }
452 }
453 }
454 return 1;
455}
456
468static void xSAT_SolverClaMinimisation( xSAT_Solver_t * s, Vec_Int_t * vLits )
469{
470 int * pLits = Vec_IntArray( vLits );
471 int MinLevel = 0;
472 int i, j;
473
474 for ( i = 1; i < Vec_IntSize( vLits ); i++ )
475 {
476 int Level = Vec_IntEntry( s->vLevels, xSAT_Lit2Var( pLits[i] ) );
477 MinLevel |= 1 << ( Level & 31 );
478 }
479
480 /* Remove reduntant literals */
481 Vec_IntAppend( s->vTagged, vLits );
482 for ( i = j = 1; i < Vec_IntSize( vLits ); i++ )
483 if ( ( unsigned ) Vec_IntEntry( s->vReasons, xSAT_Lit2Var( pLits[i] ) ) == CRefUndef || !xSAT_SolverIsLitRemovable( s, pLits[i], MinLevel ) )
484 pLits[j++] = pLits[i];
485 Vec_IntShrink( vLits, j );
486
487 /* Binary Resolution */
488 if( Vec_IntSize( vLits ) <= 30 && xSAT_SolverClaCalcLBD2( s, vLits ) <= 6 )
489 {
490 int nb, l;
491 int Lit;
492 int FlaseLit = xSAT_NegLit( pLits[0] );
493 xSAT_WatchList_t * ws = xSAT_VecWatchListEntry( s->vBinWatches, FlaseLit );
494 xSAT_Watcher_t * begin = xSAT_WatchListArray( ws );
495 xSAT_Watcher_t * end = begin + xSAT_WatchListSize( ws );
496 xSAT_Watcher_t * pWatcher;
497
498 s->nStamp++;
499 Vec_IntForEachEntry( vLits, Lit, i )
500 Vec_IntWriteEntry( s->vStamp, xSAT_Lit2Var( Lit ), ( int ) s->nStamp );
501
502 nb = 0;
503 for ( pWatcher = begin; pWatcher < end; pWatcher++ )
504 {
505 int ImpLit = pWatcher->Blocker;
506
507 if ( ( unsigned ) Vec_IntEntry( s->vStamp, xSAT_Lit2Var( ImpLit ) ) == s->nStamp && Vec_StrEntry( s->vAssigns, xSAT_Lit2Var( ImpLit ) ) == xSAT_LitSign( ImpLit ) )
508 {
509 nb++;
510 Vec_IntWriteEntry( s->vStamp, xSAT_Lit2Var( ImpLit ), ( int )( s->nStamp - 1 ) );
511 }
512 }
513
514 l = Vec_IntSize( vLits ) - 1;
515 if ( nb > 0 )
516 {
517 for ( i = 1; i < Vec_IntSize( vLits ) - nb; i++ )
518 if ( ( unsigned ) Vec_IntEntry( s->vStamp, xSAT_Lit2Var( pLits[i] ) ) != s->nStamp )
519 {
520 int TempLit = pLits[l];
521 pLits[l] = pLits[i];
522 pLits[i] = TempLit;
523 i--; l--;
524 }
525
526 Vec_IntShrink( vLits, Vec_IntSize( vLits ) - nb );
527 }
528 }
529}
530
542static void xSAT_SolverAnalyze( xSAT_Solver_t* s, unsigned ConfCRef, Vec_Int_t * vLearnt, int * OutBtLevel, unsigned * nLBD )
543{
544 int * trail = Vec_IntArray( s->vTrail );
545 int Count = 0;
546 int p = LitUndef;
547 int Idx = Vec_IntSize( s->vTrail ) - 1;
548 int * Lits;
549 int Lit;
550 int i, j;
551
552 Vec_IntPush( vLearnt, LitUndef );
553 do
554 {
555 xSAT_Clause_t * pCla;
556
557 assert( ConfCRef != CRefUndef );
558 pCla = xSAT_SolverReadClause(s, ConfCRef);
559 Lits = &( pCla->pData[0].Lit );
560
561 if( p != LitUndef && pCla->nSize == 2 && Vec_StrEntry( s->vAssigns, xSAT_Lit2Var( Lits[0] ) ) == xSAT_LitSign( xSAT_NegLit( Lits[0] ) ) )
562 {
563 assert( Vec_StrEntry( s->vAssigns, xSAT_Lit2Var( Lits[1] ) ) == xSAT_LitSign( ( Lits[1] ) ) );
564 ABC_SWAP( int, Lits[0], Lits[1] );
565 }
566
567 if ( pCla->fLearnt )
568 xSAT_SolverClaActBump( s, pCla );
569
570 if ( pCla->fLearnt && pCla->nLBD > 2 )
571 {
572 unsigned int nLevels = xSAT_SolverClaCalcLBD( s, pCla );
573 if ( nLevels + 1 < pCla->nLBD )
574 {
575 if ( pCla->nLBD <= s->Config.nLBDFrozenClause )
576 pCla->fCanBeDel = 0;
577 pCla->nLBD = nLevels;
578 }
579 }
580
581 for ( j = ( p == LitUndef ? 0 : 1 ); j < pCla->nSize; j++ )
582 {
583 int Var = xSAT_Lit2Var( Lits[j] );
584
585 if ( Vec_StrEntry( s->vSeen, Var ) == 0 && Vec_IntEntry( s->vLevels, Var ) > 0 )
586 {
587 Vec_StrWriteEntry( s->vSeen, Var, 1 );
588 xSAT_SolverVarActBump( s, Var );
589 if ( Vec_IntEntry( s->vLevels, Var ) >= xSAT_SolverDecisionLevel( s ) )
590 {
591 Count++;
592 if ( Vec_IntEntry( s->vReasons, Var ) != CRefUndef && xSAT_SolverReadClause( s, Vec_IntEntry( s->vReasons, Var ) )->fLearnt )
593 Vec_IntPush( s->vLastDLevel, Var );
594 }
595 else
596 Vec_IntPush( vLearnt, Lits[j] );
597 }
598 }
599
600 while ( !Vec_StrEntry( s->vSeen, xSAT_Lit2Var( trail[Idx--] ) ) );
601
602 // Next clause to look at
603 p = trail[Idx+1];
604 ConfCRef = ( unsigned ) Vec_IntEntry( s->vReasons, xSAT_Lit2Var( p ) );
605 Vec_StrWriteEntry( s->vSeen, xSAT_Lit2Var( p ), 0 );
606 Count--;
607
608 } while ( Count > 0 );
609
610 Vec_IntArray( vLearnt )[0] = xSAT_NegLit( p );
611 xSAT_SolverClaMinimisation( s, vLearnt );
612
613 // Find the backtrack level
614 Lits = Vec_IntArray( vLearnt );
615 if ( Vec_IntSize( vLearnt ) == 1 )
616 *OutBtLevel = 0;
617 else
618 {
619 int iMax = 1;
620 int Max = Vec_IntEntry( s->vLevels, xSAT_Lit2Var( Lits[1] ) );
621 int Tmp;
622
623 for (i = 2; i < Vec_IntSize( vLearnt ); i++)
624 if ( Vec_IntEntry( s->vLevels, xSAT_Lit2Var( Lits[i]) ) > Max)
625 {
626 Max = Vec_IntEntry( s->vLevels, xSAT_Lit2Var( Lits[i]) );
627 iMax = i;
628 }
629
630 Tmp = Lits[1];
631 Lits[1] = Lits[iMax];
632 Lits[iMax] = Tmp;
633 *OutBtLevel = Vec_IntEntry( s->vLevels, xSAT_Lit2Var( Lits[1] ) );
634 }
635
636 *nLBD = xSAT_SolverClaCalcLBD2( s, vLearnt );
637 if ( Vec_IntSize( s->vLastDLevel ) > 0 )
638 {
639 int Var;
641 {
642 if ( xSAT_SolverReadClause( s, Vec_IntEntry( s->vReasons, Var ) )->nLBD < *nLBD )
643 xSAT_SolverVarActBump( s, Var );
644 }
645
646 Vec_IntClear( s->vLastDLevel );
647 }
648
649 Vec_IntForEachEntry( s->vTagged, Lit, i )
650 Vec_StrWriteEntry( s->vSeen, xSAT_Lit2Var( Lit ), 0 );
651 Vec_IntClear( s->vTagged );
652}
653
666{
667 unsigned hConfl = CRefUndef;
668 int * Lits;
669 int NegLit;
670 int nProp = 0;
671
672 while ( s->iQhead < Vec_IntSize( s->vTrail ) )
673 {
674 int p = Vec_IntEntry( s->vTrail, s->iQhead++ );
675 xSAT_WatchList_t* ws = xSAT_VecWatchListEntry( s->vBinWatches, p );
676 xSAT_Watcher_t* begin = xSAT_WatchListArray( ws );
677 xSAT_Watcher_t* end = begin + xSAT_WatchListSize( ws );
678 xSAT_Watcher_t *i, *j;
679
680 nProp++;
681 for ( i = begin; i < end; i++ )
682 {
683 if ( Vec_StrEntry( s->vAssigns, xSAT_Lit2Var( i->Blocker ) ) == VarX )
684 xSAT_SolverEnqueue( s, i->Blocker, i->CRef );
685 else if ( Vec_StrEntry( s->vAssigns, xSAT_Lit2Var( i->Blocker ) ) == xSAT_LitSign( xSAT_NegLit( i->Blocker ) ) )
686 return i->CRef;
687 }
688
689 ws = xSAT_VecWatchListEntry( s->vWatches, p );
690 begin = xSAT_WatchListArray( ws );
691 end = begin + xSAT_WatchListSize( ws );
692
693 for ( i = j = begin; i < end; )
694 {
695 xSAT_Clause_t * pCla;
697 if ( Vec_StrEntry( s->vAssigns, xSAT_Lit2Var( i->Blocker ) ) == xSAT_LitSign( i->Blocker ) )
698 {
699 *j++ = *i++;
700 continue;
701 }
702
703 pCla = xSAT_SolverReadClause( s, i->CRef );
704 Lits = &( pCla->pData[0].Lit );
705
706 // Make sure the false literal is data[1]:
707 NegLit = xSAT_NegLit( p );
708 if ( Lits[0] == NegLit )
709 {
710 Lits[0] = Lits[1];
711 Lits[1] = NegLit;
712 }
713 assert( Lits[1] == NegLit );
714
715 w.CRef = i->CRef;
716 w.Blocker = Lits[0];
717
718 // If 0th watch is true, then clause is already satisfied.
719 if ( Lits[0] != i->Blocker && Vec_StrEntry( s->vAssigns, xSAT_Lit2Var( Lits[0] ) ) == xSAT_LitSign( Lits[0] ) )
720 *j++ = w;
721 else
722 {
723 // Look for new watch:
724 int * stop = Lits + pCla->nSize;
725 int * k;
726 for ( k = Lits + 2; k < stop; k++ )
727 {
728 if (Vec_StrEntry( s->vAssigns, xSAT_Lit2Var( *k ) ) != !xSAT_LitSign( *k ) )
729 {
730 Lits[1] = *k;
731 *k = NegLit;
732 xSAT_WatchListPush( xSAT_VecWatchListEntry( s->vWatches, xSAT_NegLit( Lits[1] ) ), w );
733 goto next;
734 }
735 }
736
737 *j++ = w;
738
739 // Clause is unit under assignment:
740 if (Vec_StrEntry( s->vAssigns, xSAT_Lit2Var( Lits[0] ) ) == xSAT_LitSign( xSAT_NegLit( Lits[0] ) ) )
741 {
742 hConfl = i->CRef;
743 i++;
744 s->iQhead = Vec_IntSize( s->vTrail );
745 // Copy the remaining watches:
746 while (i < end)
747 *j++ = *i++;
748 }
749 else
750 xSAT_SolverEnqueue( s, Lits[0], i->CRef );
751 }
752 next:
753 i++;
754 }
755
756 s->Stats.nInspects += j - xSAT_WatchListArray( ws );
757 xSAT_WatchListShrink( ws, j - xSAT_WatchListArray( ws ) );
758 }
759
760 s->Stats.nPropagations += nProp;
761 s->nPropSimplify -= nProp;
762
763 return hConfl;
764}
765
778{
779 static abctime TimeTotal = 0;
780 abctime clk = Abc_Clock();
781 int nLearnedOld = Vec_IntSize( s->vLearnts );
782 int i, limit;
783 unsigned CRef;
784 xSAT_Clause_t * pCla;
785 xSAT_Clause_t ** learnts_cls;
786
787 learnts_cls = ABC_ALLOC( xSAT_Clause_t *, nLearnedOld );
788 Vec_IntForEachEntry( s->vLearnts, CRef, i )
789 learnts_cls[i] = xSAT_SolverReadClause(s, CRef);
790
791 limit = nLearnedOld / 2;
792
793 xSAT_UtilSort((void **) learnts_cls, nLearnedOld,
794 (int (*)( const void *, const void * )) xSAT_ClauseCompare);
795
796 if ( learnts_cls[nLearnedOld / 2]->nLBD <= 3 )
798 if ( learnts_cls[nLearnedOld - 1]->nLBD <= 5 )
800
801 Vec_IntClear( s->vLearnts );
802 for ( i = 0; i < nLearnedOld; i++ )
803 {
804 unsigned CRef;
805
806 pCla = learnts_cls[i];
807 CRef = xSAT_MemCRef( s->pMemory, ( unsigned * ) pCla );
808 assert( pCla->fMark == 0 );
809 if ( pCla->fCanBeDel && pCla->nLBD > 2 && pCla->nSize > 2 && (unsigned) Vec_IntEntry( s->vReasons, xSAT_Lit2Var( pCla->pData[0].Lit ) ) != CRef && ( i < limit ) )
810 {
811 pCla->fMark = 1;
812 s->Stats.nLearntLits -= pCla->nSize;
813 xSAT_WatchListRemove( xSAT_VecWatchListEntry( s->vWatches, xSAT_NegLit( pCla->pData[0].Lit ) ), CRef );
814 xSAT_WatchListRemove( xSAT_VecWatchListEntry( s->vWatches, xSAT_NegLit( pCla->pData[1].Lit ) ), CRef );
815 }
816 else
817 {
818 if ( !pCla->fCanBeDel )
819 limit++;
820 pCla->fCanBeDel = 1;
821 Vec_IntPush( s->vLearnts, CRef );
822 }
823 }
824 ABC_FREE( learnts_cls );
825
826 TimeTotal += Abc_Clock() - clk;
827 if ( s->Config.fVerbose )
828 {
829 Abc_Print(1, "reduceDB: Keeping %7d out of %7d clauses (%5.2f %%) ",
830 Vec_IntSize( s->vLearnts ), nLearnedOld, 100.0 * Vec_IntSize( s->vLearnts ) / nLearnedOld );
831 Abc_PrintTime( 1, "Time", TimeTotal );
832 }
834}
835
848{
849 iword conflictC = 0;
850
851 s->Stats.nStarts++;
852 for (;;)
853 {
854 unsigned hConfl = xSAT_SolverPropagate( s );
855
856 if ( hConfl != CRefUndef )
857 {
858 /* Conflict */
859 int BacktrackLevel;
860 unsigned nLBD;
861 unsigned CRef;
862
863 s->Stats.nConflicts++;
864 conflictC++;
865
866 if ( xSAT_SolverDecisionLevel( s ) == 0 )
867 return LBoolFalse;
868
869 xSAT_BQueuePush( s->bqTrail, Vec_IntSize( s->vTrail ) );
870 if ( s->Stats.nConflicts > s->Config.nFirstBlockRestart && xSAT_BQueueIsValid( s->bqLBD ) && ( Vec_IntSize( s->vTrail ) > ( s->Config.R * ( iword ) xSAT_BQueueAvg( s->bqTrail ) ) ) )
871 xSAT_BQueueClean(s->bqLBD);
872
873 Vec_IntClear( s->vLearntClause );
874 xSAT_SolverAnalyze( s, hConfl, s->vLearntClause, &BacktrackLevel, &nLBD );
875
876 s->nSumLBD += nLBD;
877 xSAT_BQueuePush( s->bqLBD, nLBD );
878 xSAT_SolverCancelUntil( s, BacktrackLevel );
879
880 CRef = Vec_IntSize( s->vLearntClause ) == 1 ? CRefUndef : xSAT_SolverClaNew( s, s->vLearntClause , 1 );
881 xSAT_SolverEnqueue( s, Vec_IntEntry( s->vLearntClause , 0 ), CRef );
882
883 xSAT_SolverVarActDecay( s );
884 xSAT_SolverClaActDecay( s );
885 }
886 else
887 {
888 /* No conflict */
889 int NextVar;
890 if ( xSAT_BQueueIsValid( s->bqLBD ) && ( ( ( iword )xSAT_BQueueAvg( s->bqLBD ) * s->Config.K ) > ( s->nSumLBD / s->Stats.nConflicts ) ) )
891 {
892 xSAT_BQueueClean( s->bqLBD );
894 return LBoolUndef;
895 }
896
897 // Simplify the set of problem clauses:
898 if ( xSAT_SolverDecisionLevel( s ) == 0 )
900
901 // Reduce the set of learnt clauses:
902 if ( s->Stats.nConflicts >= s->nConfBeforeReduce )
903 {
904 s->nRC1 = ( s->Stats.nConflicts / s->nRC2 ) + 1;
906 s->nRC2 += s->Config.nIncReduce;
907 s->nConfBeforeReduce = s->nRC1 * s->nRC2;
908 }
909
910 // New variable decision:
911 NextVar = xSAT_SolverDecide( s );
912
913 if ( NextVar == VarUndef )
914 return LBoolTrue;
915
916 xSAT_SolverNewDecision( s, xSAT_Var2Lit( NextVar, ( int ) Vec_StrEntry( s->vPolarity, NextVar ) ) );
917 }
918 }
919
920 return LBoolUndef; // cannot happen
921}
922
934void xSAT_SolverClaRealloc( xSAT_Mem_t * pDest, xSAT_Mem_t * pSrc, unsigned * pCRef )
935{
936 unsigned nNewCRef;
937 xSAT_Clause_t * pNewCla;
938 xSAT_Clause_t * pOldCla = xSAT_MemClauseHand( pSrc, *pCRef );
939
940 if ( pOldCla->fReallocd )
941 {
942 *pCRef = ( unsigned ) pOldCla->nSize;
943 return;
944 }
945 nNewCRef = xSAT_MemAppend( pDest, 3 + pOldCla->fLearnt + pOldCla->nSize );
946 pNewCla = xSAT_MemClauseHand( pDest, nNewCRef );
947 memcpy( pNewCla, pOldCla, (size_t)(( 3 + pOldCla->fLearnt + pOldCla->nSize ) * 4) );
948 pOldCla->fReallocd = 1;
949 pOldCla->nSize = ( unsigned ) nNewCRef;
950 *pCRef = nNewCRef;
951}
952
965{
966 int i;
967 unsigned * pArray;
968 xSAT_Mem_t * pNewMemMngr = xSAT_MemAlloc( xSAT_MemCap( s->pMemory ) - xSAT_MemWastedCap( s->pMemory ) );
969
970 for ( i = 0; i < 2 * Vec_StrSize( s->vAssigns ); i++ )
971 {
972 xSAT_WatchList_t* ws = xSAT_VecWatchListEntry( s->vWatches, i);
973 xSAT_Watcher_t* begin = xSAT_WatchListArray(ws);
974 xSAT_Watcher_t* end = begin + xSAT_WatchListSize(ws);
976
977 for ( w = begin; w != end; w++ )
978 xSAT_SolverClaRealloc( pNewMemMngr, s->pMemory, &(w->CRef) );
979
980 ws = xSAT_VecWatchListEntry( s->vBinWatches, i);
981 begin = xSAT_WatchListArray(ws);
982 end = begin + xSAT_WatchListSize(ws);
983 for ( w = begin; w != end; w++ )
984 xSAT_SolverClaRealloc( pNewMemMngr, s->pMemory, &(w->CRef) );
985 }
986
987 for ( i = 0; i < Vec_IntSize( s->vTrail ); i++ )
988 if ( ( unsigned ) Vec_IntEntry( s->vReasons, xSAT_Lit2Var( Vec_IntEntry( s->vTrail, i ) ) ) != CRefUndef )
989 xSAT_SolverClaRealloc( pNewMemMngr, s->pMemory, ( unsigned * ) &( Vec_IntArray( s->vReasons )[xSAT_Lit2Var( Vec_IntEntry( s->vTrail, i ) )] ) );
990
991 pArray = ( unsigned * ) Vec_IntArray( s->vLearnts );
992 for ( i = 0; i < Vec_IntSize( s->vLearnts ); i++ )
993 xSAT_SolverClaRealloc( pNewMemMngr, s->pMemory, &(pArray[i]) );
994
995 pArray = ( unsigned * ) Vec_IntArray( s->vClauses );
996 for ( i = 0; i < Vec_IntSize( s->vClauses ); i++ )
997 xSAT_SolverClaRealloc( pNewMemMngr, s->pMemory, &(pArray[i]) );
998
999 xSAT_MemFree( s->pMemory );
1000 s->pMemory = pNewMemMngr;
1001}
1002
int nWords
Definition abcNpn.c:127
ABC_INT64_T iword
Definition abc_global.h:244
#define ABC_SWAP(Type, a, b)
Definition abc_global.h:253
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Cube * p
Definition exorList.c:222
int Var
Definition exorList.c:228
RegionAllocator< uint32_t >::Ref CRef
unsigned nLBDFrozenClause
Definition xsatSolver.h:99
Vec_Int_t * vLastDLevel
Definition xsatSolver.h:162
Vec_Str_t * vPolarity
Definition xsatSolver.h:136
Vec_Int_t * vStamp
Definition xsatSolver.h:166
Vec_Int_t * vActivity
Definition xsatSolver.h:131
Vec_Str_t * vSeen
Definition xsatSolver.h:159
xSAT_Mem_t * pMemory
Definition xsatSolver.h:120
Vec_Int_t * vTagged
Definition xsatSolver.h:160
xSAT_SolverOptions_t Config
Definition xsatSolver.h:169
xSAT_VecWatchList_t * vWatches
Definition xsatSolver.h:123
Vec_Int_t * vReasons
Definition xsatSolver.h:134
iword nPropSimplify
Definition xsatSolver.h:146
Vec_Int_t * vLearntClause
Definition xsatSolver.h:158
Vec_Int_t * vTrail
Definition xsatSolver.h:140
unsigned nStamp
Definition xsatSolver.h:165
xSAT_BQueue_t * bqLBD
Definition xsatSolver.h:151
Vec_Int_t * vLevels
Definition xsatSolver.h:133
Vec_Int_t * vTrailLim
Definition xsatSolver.h:141
Vec_Int_t * vClauses
Definition xsatSolver.h:122
Vec_Int_t * vLearnts
Definition xsatSolver.h:121
xSAT_BQueue_t * bqTrail
Definition xsatSolver.h:150
Vec_Int_t * vStack
Definition xsatSolver.h:161
xSAT_Stats_t Stats
Definition xsatSolver.h:170
xSAT_VecWatchList_t * vBinWatches
Definition xsatSolver.h:124
xSAT_Heap_t * hOrder
Definition xsatSolver.h:132
Vec_Str_t * vAssigns
Definition xsatSolver.h:135
iword nLearntLits
Definition xsatSolver.h:114
iword nPropagations
Definition xsatSolver.h:109
unsigned nStarts
Definition xsatSolver.h:105
iword nClauseLits
Definition xsatSolver.h:113
#define assert(ex)
Definition util_old.h:213
char * memcpy()
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
Definition vecInt.h:56
typedefABC_NAMESPACE_HEADER_START struct xSAT_Clause_t_ xSAT_Clause_t
INCLUDES ///.
Definition xsatClause.h:34
typedefABC_NAMESPACE_HEADER_START struct xSAT_Mem_t_ xSAT_Mem_t
INCLUDES ///.
Definition xsatMemory.h:36
void xSAT_SolverReduceDB(xSAT_Solver_t *s)
Definition xsatSolver.c:777
void xSAT_SolverRebuildOrderHeap(xSAT_Solver_t *s)
Definition xsatSolver.c:77
void xSAT_SolverClaRealloc(xSAT_Mem_t *pDest, xSAT_Mem_t *pSrc, unsigned *pCRef)
Definition xsatSolver.c:934
void xSAT_SolverGarbageCollect(xSAT_Solver_t *s)
Definition xsatSolver.c:964
void xSAT_SolverCancelUntil(xSAT_Solver_t *s, int Level)
Definition xsatSolver.c:375
int xSAT_SolverEnqueue(xSAT_Solver_t *s, int Lit, unsigned Reason)
Definition xsatSolver.c:333
char xSAT_SolverSearch(xSAT_Solver_t *s)
Definition xsatSolver.c:847
unsigned xSAT_SolverPropagate(xSAT_Solver_t *s)
Definition xsatSolver.c:665
unsigned xSAT_SolverClaNew(xSAT_Solver_t *s, Vec_Int_t *vLits, int fLearnt)
FUNCTION DECLARATIONS ///.
Definition xsatSolver.c:269
@ VarX
Definition xsatSolver.h:57
#define CRefUndef
Definition xsatSolver.h:73
@ LitUndef
Definition xsatSolver.h:70
@ VarUndef
Definition xsatSolver.h:69
@ LBoolFalse
Definition xsatSolver.h:64
@ LBoolTrue
Definition xsatSolver.h:63
@ LBoolUndef
Definition xsatSolver.h:62
struct xSAT_WatchList_t_ xSAT_WatchList_t
typedefABC_NAMESPACE_HEADER_START struct xSAT_Watcher_t_ xSAT_Watcher_t
INCLUDES ///.
int xSAT_SolverSimplify(xSAT_Solver_t *)
struct xSAT_Solver_t_ xSAT_Solver_t
Definition xsat.h:36