ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
xsatSolverAPI.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 "xsatSolver.h"
30
32
34{
35 1, //.fVerbose = 1,
36
37 0, //.nConfLimit = 0,
38 0, //.nInsLimit = 0,
39 0, //.nRuntimeLimit = 0,
40
41 0.8, //.K = 0.8,
42 1.4, //.R = 1.4,
43 10000, //.nFirstBlockRestart = 10000,
44 50, //.nSizeLBDQueue = 50,
45 5000, //.nSizeTrailQueue = 5000,
46
47 2000, //.nConfFirstReduce = 2000,
48 300, //.nIncReduce = 300,
49 1000, //.nSpecialIncReduce = 1000,
50
51 30 //.nLBDFrozenClause = 30
52};
53
54
67{
68 xSAT_Solver_t * s = (xSAT_Solver_t *) ABC_CALLOC( char, sizeof( xSAT_Solver_t ) );
70
71 s->pMemory = xSAT_MemAlloc(0);
72 s->vClauses = Vec_IntAlloc(0);
73 s->vLearnts = Vec_IntAlloc(0);
74 s->vWatches = xSAT_VecWatchListAlloc( 0 );
75 s->vBinWatches = xSAT_VecWatchListAlloc( 0 );
76
77 s->vTrailLim = Vec_IntAlloc(0);
78 s->vTrail = Vec_IntAlloc( 0 );
79
80 s->vActivity = Vec_IntAlloc( 0 );
81 s->hOrder = xSAT_HeapAlloc( s->vActivity );
82
83 s->vPolarity = Vec_StrAlloc( 0 );
84 s->vTags = Vec_StrAlloc( 0 );
85 s->vAssigns = Vec_StrAlloc( 0 );
86 s->vLevels = Vec_IntAlloc( 0 );
87 s->vReasons = Vec_IntAlloc( 0 );
88 s->vStamp = Vec_IntAlloc( 0 );
89
90 s->vTagged = Vec_IntAlloc(0);
91 s->vStack = Vec_IntAlloc(0);
92
93 s->vSeen = Vec_StrAlloc( 0 );
94 s->vLearntClause = Vec_IntAlloc(0);
95 s->vLastDLevel = Vec_IntAlloc(0);
96
97
98 s->bqTrail = xSAT_BQueueNew( s->Config.nSizeTrailQueue );
99 s->bqLBD = xSAT_BQueueNew( s->Config.nSizeLBDQueue );
100
101 s->nVarActInc = (1 << 5);
102 s->nClaActInc = (1 << 11);
103
105 s->nRC1 = 1;
107 return s;
108}
109
122{
123 xSAT_MemFree( s->pMemory );
124 Vec_IntFree( s->vClauses );
125 Vec_IntFree( s->vLearnts );
126 xSAT_VecWatchListFree( s->vWatches );
127 xSAT_VecWatchListFree( s->vBinWatches );
128
129 xSAT_HeapFree(s->hOrder);
130 Vec_IntFree( s->vTrailLim );
131 Vec_IntFree( s->vTrail );
132 Vec_IntFree( s->vTagged );
133 Vec_IntFree( s->vStack );
134
135 Vec_StrFree( s->vSeen );
136 Vec_IntFree( s->vLearntClause );
137 Vec_IntFree( s->vLastDLevel );
138
139 Vec_IntFree( s->vActivity );
140 Vec_StrFree( s->vPolarity );
141 Vec_StrFree( s->vTags );
142 Vec_StrFree( s->vAssigns );
143 Vec_IntFree( s->vLevels );
144 Vec_IntFree( s->vReasons );
145 Vec_IntFree( s->vStamp );
146
147 xSAT_BQueueFree(s->bqLBD);
148 xSAT_BQueueFree(s->bqTrail);
149
150 ABC_FREE(s);
151}
152
165{
166 int i, j;
167 unsigned CRef;
168 assert( xSAT_SolverDecisionLevel(s) == 0 );
169
171 return false;
172
173 if ( s->nAssignSimplify == Vec_IntSize( s->vTrail ) || s->nPropSimplify > 0 )
174 return true;
175
176 j = 0;
177 Vec_IntForEachEntry( s->vClauses, CRef, i )
178 {
179 xSAT_Clause_t * pCla = xSAT_SolverReadClause( s, CRef );
180 if ( xSAT_SolverIsClauseSatisfied( s, pCla ) )
181 {
182 pCla->fMark = 1;
183 s->Stats.nClauseLits -= pCla->nSize;
184
185 if ( pCla->nSize == 2 )
186 {
187 xSAT_WatchListRemove( xSAT_VecWatchListEntry( s->vBinWatches, xSAT_NegLit(pCla->pData[0].Lit) ), CRef );
188 xSAT_WatchListRemove( xSAT_VecWatchListEntry( s->vBinWatches, xSAT_NegLit(pCla->pData[1].Lit) ), CRef );
189 }
190 else
191 {
192 xSAT_WatchListRemove( xSAT_VecWatchListEntry( s->vWatches, xSAT_NegLit(pCla->pData[0].Lit) ), CRef );
193 xSAT_WatchListRemove( xSAT_VecWatchListEntry( s->vWatches, xSAT_NegLit(pCla->pData[1].Lit) ), CRef );
194 }
195 }
196 else
197 Vec_IntWriteEntry( s->vClauses, j++, CRef );
198 }
199 Vec_IntShrink( s->vClauses, j );
201
202 s->nAssignSimplify = Vec_IntSize( s->vTrail );
204
205 return true;
206}
207
220{
221 int Var = Vec_IntSize( s->vActivity );
222
223 xSAT_VecWatchListPush( s->vWatches );
224 xSAT_VecWatchListPush( s->vWatches );
225 xSAT_VecWatchListPush( s->vBinWatches );
226 xSAT_VecWatchListPush( s->vBinWatches );
227
228 Vec_IntPush( s->vActivity, 0 );
229 Vec_IntPush( s->vLevels, 0 );
230 Vec_StrPush( s->vAssigns, VarX );
231 Vec_StrPush( s->vPolarity, 1 );
232 Vec_StrPush( s->vTags, 0 );
233 Vec_IntPush( s->vReasons, ( int ) CRefUndef );
234 Vec_IntPush( s->vStamp, 0 );
235 Vec_StrPush( s->vSeen, 0 );
236
237 xSAT_HeapInsert( s->hOrder, Var );
238}
239
252{
253 int i, j;
254 int Lit, PrevLit;
255 int MaxVar;
256
257 Vec_IntSort( vLits, 0 );
258 MaxVar = xSAT_Lit2Var( Vec_IntEntryLast( vLits ) );
259 while ( MaxVar >= Vec_IntSize( s->vActivity ) )
261
262 j = 0;
263 PrevLit = LitUndef;
264 Vec_IntForEachEntry( vLits, Lit, i )
265 {
266 if ( Lit == xSAT_NegLit( PrevLit ) || Vec_StrEntry( s->vAssigns, xSAT_Lit2Var( Lit ) ) == xSAT_LitSign( Lit ) )
267 return true;
268 else if ( Lit != PrevLit && Vec_StrEntry( s->vAssigns, xSAT_Lit2Var( Lit ) ) == VarX )
269 {
270 PrevLit = Lit;
271 Vec_IntWriteEntry( vLits, j++, Lit );
272 }
273 }
274 Vec_IntShrink( vLits, j );
275
276 if ( Vec_IntSize( vLits ) == 0 )
277 return false;
278 if ( Vec_IntSize( vLits ) == 1 )
279 {
280 xSAT_SolverEnqueue( s, Vec_IntEntry( vLits, 0 ), CRefUndef );
281 return ( xSAT_SolverPropagate( s ) == CRefUndef );
282 }
283
284 xSAT_SolverClaNew( s, vLits, 0 );
285 return true;
286}
287
300{
301 char status = LBoolUndef;
302
303 assert(s);
304 if ( s->Config.fVerbose )
305 {
306 printf( "==========================================[ BLACK MAGIC ]================================================\n" );
307 printf( "| | | |\n" );
308 printf( "| - Restarts: | - Reduce Clause DB: | - Minimize Asserting: |\n" );
309 printf( "| * LBD Queue : %6d | * First : %6d | * size < %3d |\n", s->Config.nSizeLBDQueue, s->Config.nConfFirstReduce, 0 );
310 printf( "| * Trail Queue : %6d | * Inc : %6d | * lbd < %3d |\n", s->Config.nSizeTrailQueue, s->Config.nIncReduce, 0 );
311 printf( "| * K : %6.2f | * Special : %6d | |\n", s->Config.K, s->Config.nSpecialIncReduce );
312 printf( "| * R : %6.2f | * Protected : (lbd)< %2d | |\n", s->Config.R, s->Config.nLBDFrozenClause );
313 printf( "| | | |\n" );
314 printf( "=========================================================================================================\n" );
315 }
316
317 while ( status == LBoolUndef )
318 status = xSAT_SolverSearch( s );
319
320 if ( s->Config.fVerbose )
321 printf( "=========================================================================================================\n" );
322
324 return status;
325}
326
339{
340 printf( "starts : %10d\n", s->Stats.nStarts );
341 printf( "conflicts : %10ld\n", s->Stats.nConflicts );
342 printf( "decisions : %10ld\n", s->Stats.nDecisions );
343 printf( "propagations : %10ld\n", s->Stats.nPropagations );
344}
345
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#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
int Var
Definition exorList.c:228
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 * vTags
Definition xsatSolver.h:137
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
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
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
typedefABC_NAMESPACE_HEADER_START struct xSAT_Clause_t_ xSAT_Clause_t
INCLUDES ///.
Definition xsatClause.h:34
int xSAT_SolverSolve(xSAT_Solver_t *s)
xSAT_Solver_t * xSAT_SolverCreate()
int xSAT_SolverSimplify(xSAT_Solver_t *s)
ABC_NAMESPACE_IMPL_START xSAT_SolverOptions_t DefaultConfig
INCLUDES ///.
void xSAT_SolverPrintStats(xSAT_Solver_t *s)
int xSAT_SolverAddClause(xSAT_Solver_t *s, Vec_Int_t *vLits)
void xSAT_SolverDestroy(xSAT_Solver_t *s)
void xSAT_SolverAddVariable(xSAT_Solver_t *s, int Sign)
void xSAT_SolverRebuildOrderHeap(xSAT_Solver_t *s)
Definition xsatSolver.c:77
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
struct xSAT_SolverOptions_t_ xSAT_SolverOptions_t
STRUCTURE DEFINITIONS ///.
Definition xsatSolver.h:78
@ LBoolUndef
Definition xsatSolver.h:62
struct xSAT_Solver_t_ xSAT_Solver_t
Definition xsat.h:36