ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
xsatSolver.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "misc/util/abc_global.h"
#include "misc/vec/vecStr.h"
#include "xsat.h"
#include "xsatBQueue.h"
#include "xsatClause.h"
#include "xsatHeap.h"
#include "xsatMemory.h"
#include "xsatWatchList.h"
Include dependency graph for xsatSolver.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  xSAT_SolverOptions_t_
 
struct  xSAT_Stats_t_
 
struct  xSAT_Solver_t_
 

Macros

#define false   0
 INCLUDES ///.
 
#define true   1
 
#define CRefUndef   0xFFFFFFFF
 

Typedefs

typedef struct xSAT_SolverOptions_t_ xSAT_SolverOptions_t
 STRUCTURE DEFINITIONS ///.
 
typedef struct xSAT_Stats_t_ xSAT_Stats_t
 

Enumerations

enum  { Var0 = 1 , Var1 = 0 , VarX = 3 }
 
enum  { LBoolUndef = 0 , LBoolTrue = 1 , LBoolFalse = -1 }
 
enum  { VarUndef = -1 , LitUndef = -2 }
 

Functions

unsigned xSAT_SolverClaNew (xSAT_Solver_t *s, Vec_Int_t *vLits, int fLearnt)
 FUNCTION DECLARATIONS ///.
 
char xSAT_SolverSearch (xSAT_Solver_t *s)
 
void xSAT_SolverGarbageCollect (xSAT_Solver_t *s)
 
int xSAT_SolverEnqueue (xSAT_Solver_t *s, int Lit, unsigned From)
 
void xSAT_SolverCancelUntil (xSAT_Solver_t *s, int Level)
 
unsigned xSAT_SolverPropagate (xSAT_Solver_t *s)
 
void xSAT_SolverRebuildOrderHeap (xSAT_Solver_t *s)
 

Macro Definition Documentation

◆ CRefUndef

#define CRefUndef   0xFFFFFFFF

Definition at line 73 of file xsatSolver.h.

◆ false

#define false   0

INCLUDES ///.

CFile****************************************************************

FileName [xsatSolver.h]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [xSAT - A SAT solver written in C. Read the license file for more info.]

Synopsis [Internal definitions of the solver.]

Author [Bruno Schmitt bosch.nosp@m.mitt.nosp@m.@inf..nosp@m.ufrg.nosp@m.s.br]

Affiliation [UC Berkeley / UFRGS]

Date [Ver. 1.0. Started - November 10, 2016.]

Revision []

Definition at line 46 of file xsatSolver.h.

◆ true

#define true   1

Definition at line 49 of file xsatSolver.h.

Typedef Documentation

◆ xSAT_SolverOptions_t

STRUCTURE DEFINITIONS ///.

Definition at line 78 of file xsatSolver.h.

◆ xSAT_Stats_t

typedef struct xSAT_Stats_t_ xSAT_Stats_t

Definition at line 102 of file xsatSolver.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
VarUndef 
LitUndef 

Definition at line 67 of file xsatSolver.h.

68{
69 VarUndef = -1,
70 LitUndef = -2
71};
@ LitUndef
Definition xsatSolver.h:70
@ VarUndef
Definition xsatSolver.h:69

◆ anonymous enum

anonymous enum
Enumerator
LBoolUndef 
LBoolTrue 
LBoolFalse 

Definition at line 60 of file xsatSolver.h.

61{
62 LBoolUndef = 0,
63 LBoolTrue = 1,
64 LBoolFalse = -1
65};
@ LBoolFalse
Definition xsatSolver.h:64
@ LBoolTrue
Definition xsatSolver.h:63
@ LBoolUndef
Definition xsatSolver.h:62

◆ anonymous enum

anonymous enum
Enumerator
Var0 
Var1 
VarX 

Definition at line 53 of file xsatSolver.h.

54{
55 Var0 = 1,
56 Var1 = 0,
57 VarX = 3
58};
@ VarX
Definition xsatSolver.h:57
@ Var1
Definition xsatSolver.h:56
@ Var0
Definition xsatSolver.h:55

Function Documentation

◆ xSAT_SolverCancelUntil()

void xSAT_SolverCancelUntil ( xSAT_Solver_t * s,
int Level )
extern

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 375 of file xsatSolver.c.

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}
int Var
Definition exorList.c:228
Vec_Str_t * vPolarity
Definition xsatSolver.h:136
Vec_Int_t * vReasons
Definition xsatSolver.h:134
Vec_Int_t * vTrail
Definition xsatSolver.h:140
Vec_Int_t * vTrailLim
Definition xsatSolver.h:141
xSAT_Heap_t * hOrder
Definition xsatSolver.h:132
Vec_Str_t * vAssigns
Definition xsatSolver.h:135
#define CRefUndef
Definition xsatSolver.h:73
Here is the caller graph for this function:

◆ xSAT_SolverClaNew()

unsigned xSAT_SolverClaNew ( xSAT_Solver_t * s,
Vec_Int_t * vLits,
int fLearnt )
extern

FUNCTION DECLARATIONS ///.

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 269 of file xsatSolver.c.

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}
int nWords
Definition abcNpn.c:127
RegionAllocator< uint32_t >::Ref CRef
xSAT_Mem_t * pMemory
Definition xsatSolver.h:120
xSAT_VecWatchList_t * vWatches
Definition xsatSolver.h:123
Vec_Int_t * vClauses
Definition xsatSolver.h:122
Vec_Int_t * vLearnts
Definition xsatSolver.h:121
xSAT_Stats_t Stats
Definition xsatSolver.h:170
xSAT_VecWatchList_t * vBinWatches
Definition xsatSolver.h:124
iword nLearntLits
Definition xsatSolver.h:114
iword nClauseLits
Definition xsatSolver.h:113
#define assert(ex)
Definition util_old.h:213
char * memcpy()
typedefABC_NAMESPACE_HEADER_START struct xSAT_Clause_t_ xSAT_Clause_t
INCLUDES ///.
Definition xsatClause.h:34
typedefABC_NAMESPACE_HEADER_START struct xSAT_Watcher_t_ xSAT_Watcher_t
INCLUDES ///.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ xSAT_SolverEnqueue()

int xSAT_SolverEnqueue ( xSAT_Solver_t * s,
int Lit,
unsigned Reason )
extern

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 333 of file xsatSolver.c.

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}
Vec_Int_t * vLevels
Definition xsatSolver.h:133
Here is the caller graph for this function:

◆ xSAT_SolverGarbageCollect()

void xSAT_SolverGarbageCollect ( xSAT_Solver_t * s)
extern

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 964 of file xsatSolver.c.

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}
typedefABC_NAMESPACE_HEADER_START struct xSAT_Mem_t_ xSAT_Mem_t
INCLUDES ///.
Definition xsatMemory.h:36
void xSAT_SolverClaRealloc(xSAT_Mem_t *pDest, xSAT_Mem_t *pSrc, unsigned *pCRef)
Definition xsatSolver.c:934
struct xSAT_WatchList_t_ xSAT_WatchList_t
Here is the call graph for this function:
Here is the caller graph for this function:

◆ xSAT_SolverPropagate()

unsigned xSAT_SolverPropagate ( xSAT_Solver_t * s)
extern

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 665 of file xsatSolver.c.

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}
Cube * p
Definition exorList.c:222
iword nPropSimplify
Definition xsatSolver.h:146
iword nPropagations
Definition xsatSolver.h:109
int xSAT_SolverEnqueue(xSAT_Solver_t *s, int Lit, unsigned Reason)
Definition xsatSolver.c:333
Here is the call graph for this function:
Here is the caller graph for this function:

◆ xSAT_SolverRebuildOrderHeap()

void xSAT_SolverRebuildOrderHeap ( xSAT_Solver_t * s)
extern

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 77 of file xsatSolver.c.

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}
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Here is the caller graph for this function:

◆ xSAT_SolverSearch()

char xSAT_SolverSearch ( xSAT_Solver_t * s)
extern

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 847 of file xsatSolver.c.

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}
ABC_INT64_T iword
Definition abc_global.h:244
xSAT_SolverOptions_t Config
Definition xsatSolver.h:169
Vec_Int_t * vLearntClause
Definition xsatSolver.h:158
xSAT_BQueue_t * bqLBD
Definition xsatSolver.h:151
xSAT_BQueue_t * bqTrail
Definition xsatSolver.h:150
unsigned nStarts
Definition xsatSolver.h:105
void xSAT_SolverReduceDB(xSAT_Solver_t *s)
Definition xsatSolver.c:777
void xSAT_SolverCancelUntil(xSAT_Solver_t *s, int Level)
Definition xsatSolver.c:375
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
int xSAT_SolverSimplify(xSAT_Solver_t *)
Here is the call graph for this function:
Here is the caller graph for this function: