ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
msatOrderJ.c
Go to the documentation of this file.
1
20
21#include "msatInt.h"
22
24
25
26/*
27The J-boundary (justification boundary) is defined as a set of unassigned
28variables belonging to the cone of interest, such that for each of them,
29there exist an adjacent assigned variable in the cone of interest.
30*/
31
35
38
39// the variable data structure
46
47// the ring of variables data structure (J-boundary)
53
54// the variable package data structure
55struct Msat_Order_t_
56{
57 Msat_Solver_t * pSat; // the SAT solver
58 Msat_OrderVar_t * pVars; // the storage for variables
59 int nVarsAlloc; // the number of variables allocated
60 Msat_OrderRing_t rVars; // the J-boundary as a ring of variables
61};
62
63//The solver can communicate to the variable order the following parts:
64//- the array of current assignments (pSat->pAssigns)
65//- the array of variable activities (pSat->pdActivity)
66//- the array of variables currently in the cone (pSat->vConeVars)
67//- the array of arrays of variables adjucent to each(pSat->vAdjacents)
68
69#define Msat_OrderVarIsInBoundary( p, i ) ((p)->pVars[i].pNext)
70#define Msat_OrderVarIsAssigned( p, i ) ((p)->pSat->pAssigns[i] != MSAT_VAR_UNASSIGNED)
71#define Msat_OrderVarIsUsedInCone( p, i ) ((p)->pSat->vVarsUsed->pArray[i])
72
73// iterator through the entries in J-boundary
74#define Msat_OrderRingForEachEntry( pRing, pVar, pNext ) \
75 for ( pVar = pRing, \
76 pNext = pVar? pVar->pNext : NULL; \
77 pVar; \
78 pVar = (pNext != pRing)? pNext : NULL, \
79 pNext = pVar? pVar->pNext : NULL )
80
81static void Msat_OrderRingAddLast( Msat_OrderRing_t * pRing, Msat_OrderVar_t * pVar );
82static void Msat_OrderRingRemove( Msat_OrderRing_t * pRing, Msat_OrderVar_t * pVar );
83
84extern clock_t timeSelect;
85extern clock_t timeAssign;
86
90
103{
104 Msat_Order_t * p;
105 p = ALLOC( Msat_Order_t, 1 );
106 memset( p, 0, sizeof(Msat_Order_t) );
107 p->pSat = pSat;
108 Msat_OrderSetBounds( p, pSat->nVarsAlloc );
109 return p;
110}
111
123void Msat_OrderSetBounds( Msat_Order_t * p, int nVarsMax )
124{
125 int i;
126 // add variables if they are missing
127 if ( p->nVarsAlloc < nVarsMax )
128 {
129 p->pVars = REALLOC( Msat_OrderVar_t, p->pVars, nVarsMax );
130 for ( i = p->nVarsAlloc; i < nVarsMax; i++ )
131 {
132 p->pVars[i].pNext = p->pVars[i].pPrev = NULL;
133 p->pVars[i].Num = i;
134 }
135 p->nVarsAlloc = nVarsMax;
136 }
137}
138
151{
152 Msat_OrderVar_t * pVar, * pNext;
153 // quickly undo the ring
154 Msat_OrderRingForEachEntry( p->rVars.pRoot, pVar, pNext )
155 pVar->pNext = pVar->pPrev = NULL;
156 p->rVars.pRoot = NULL;
157 p->rVars.nItems = 0;
158}
159
172{
173 Msat_OrderVar_t * pVar, * pNext;
174 Msat_IntVec_t * vRound;
175 int * pRound, nRound;
176 int * pVars, nVars, i, k;
177 int Counter = 0;
178
179 // go through all the variables in the boundary
180 Msat_OrderRingForEachEntry( p->rVars.pRoot, pVar, pNext )
181 {
182 assert( !Msat_OrderVarIsAssigned(p, pVar->Num) );
183 // go though all the variables in the neighborhood
184 // and check that it is true that there is least one assigned
185 vRound = (Msat_IntVec_t *)Msat_ClauseVecReadEntry( p->pSat->vAdjacents, pVar->Num );
186 nRound = Msat_IntVecReadSize( vRound );
187 pRound = Msat_IntVecReadArray( vRound );
188 for ( i = 0; i < nRound; i++ )
189 {
190 if ( !Msat_OrderVarIsUsedInCone(p, pRound[i]) )
191 continue;
192 if ( Msat_OrderVarIsAssigned(p, pRound[i]) )
193 break;
194 }
195// assert( i != nRound );
196// if ( i == nRound )
197// return 0;
198 if ( i == nRound )
199 Counter++;
200 }
201 if ( Counter > 0 )
202 printf( "%d(%d) ", Counter, p->rVars.nItems );
203
204 // we may also check other unassigned variables in the cone
205 // to make sure that if they are not in J-boundary,
206 // then they do not have an assigned neighbor
207 nVars = Msat_IntVecReadSize( p->pSat->vConeVars );
208 pVars = Msat_IntVecReadArray( p->pSat->vConeVars );
209 for ( i = 0; i < nVars; i++ )
210 {
211 assert( Msat_OrderVarIsUsedInCone(p, pVars[i]) );
212 // skip assigned vars, vars in the boundary, and vars not used in the cone
213 if ( Msat_OrderVarIsAssigned(p, pVars[i]) ||
214 Msat_OrderVarIsInBoundary(p, pVars[i]) )
215 continue;
216 // make sure, it does not have assigned neighbors
217 vRound = (Msat_IntVec_t *)Msat_ClauseVecReadEntry( p->pSat->vAdjacents, pVars[i] );
218 nRound = Msat_IntVecReadSize( vRound );
219 pRound = Msat_IntVecReadArray( vRound );
220 for ( k = 0; k < nRound; k++ )
221 {
222 if ( !Msat_OrderVarIsUsedInCone(p, pRound[k]) )
223 continue;
224 if ( Msat_OrderVarIsAssigned(p, pRound[k]) )
225 break;
226 }
227// assert( k == nRound );
228// if ( k != nRound )
229// return 0;
230 }
231 return 1;
232}
233
246{
247 free( p->pVars );
248 free( p );
249}
250
263{
264 Msat_OrderVar_t * pVar, * pNext, * pVarBest;
265 double * pdActs = p->pSat->pdActivity;
266 double dfActBest;
267// clock_t clk = clock();
268
269 pVarBest = NULL;
270 dfActBest = -1.0;
271 Msat_OrderRingForEachEntry( p->rVars.pRoot, pVar, pNext )
272 {
273 if ( dfActBest < pdActs[pVar->Num] )
274 {
275 dfActBest = pdActs[pVar->Num];
276 pVarBest = pVar;
277 }
278 }
279//timeSelect += clock() - clk;
280//timeAssign += clock() - clk;
281
282//if ( pVarBest && pVarBest->Num % 1000 == 0 )
283//printf( "%d ", p->rVars.nItems );
284
285// Msat_OrderCheck( p );
286 if ( pVarBest )
287 {
288 assert( Msat_OrderVarIsUsedInCone(p, pVarBest->Num) );
289 return pVarBest->Num;
290 }
291 return MSAT_ORDER_UNKNOWN;
292}
293
306{
307 Msat_IntVec_t * vRound;
308 int i;//, clk = clock();
309
310 // make sure the variable is in the boundary
311 assert( Var < p->nVarsAlloc );
312 // if it is not in the boundary (initial decision, random decision), do not remove
314 Msat_OrderRingRemove( &p->rVars, &p->pVars[Var] );
315 // add to the boundary those neighbors that are (1) unassigned, (2) not in boundary
316 // because for them we know that there is a variable (Var) which is assigned
317 vRound = (Msat_IntVec_t *)p->pSat->vAdjacents->pArray[Var];
318 for ( i = 0; i < vRound->nSize; i++ )
319 {
320 if ( !Msat_OrderVarIsUsedInCone(p, vRound->pArray[i]) )
321 continue;
322 if ( Msat_OrderVarIsAssigned(p, vRound->pArray[i]) )
323 continue;
324 if ( Msat_OrderVarIsInBoundary(p, vRound->pArray[i]) )
325 continue;
326 Msat_OrderRingAddLast( &p->rVars, &p->pVars[vRound->pArray[i]] );
327 }
328//timeSelect += clock() - clk;
329// Msat_OrderCheck( p );
330}
331
344{
345 Msat_IntVec_t * vRound, * vRound2;
346 int i, k;//, clk = clock();
347
348 // make sure the variable is not in the boundary
349 assert( Var < p->nVarsAlloc );
351 // go through its neigbors - if one of them is assigned add this var
352 // add to the boundary those neighbors that are not there already
353 // this will also get rid of variable outside of the current cone
354 // because they are unassigned in Msat_SolverPrepare()
355 vRound = (Msat_IntVec_t *)p->pSat->vAdjacents->pArray[Var];
356 for ( i = 0; i < vRound->nSize; i++ )
357 if ( Msat_OrderVarIsAssigned(p, vRound->pArray[i]) )
358 break;
359 if ( i != vRound->nSize )
360 Msat_OrderRingAddLast( &p->rVars, &p->pVars[Var] );
361
362 // unassigning a variable may lead to its adjacents dropping from the boundary
363 for ( i = 0; i < vRound->nSize; i++ )
364 if ( Msat_OrderVarIsInBoundary(p, vRound->pArray[i]) )
365 { // the neighbor is in the J-boundary (and unassigned)
366 assert( !Msat_OrderVarIsAssigned(p, vRound->pArray[i]) );
367 vRound2 = (Msat_IntVec_t *)p->pSat->vAdjacents->pArray[vRound->pArray[i]];
368 // go through its neighbors and determine if there is at least one assigned
369 for ( k = 0; k < vRound2->nSize; k++ )
370 if ( Msat_OrderVarIsAssigned(p, vRound2->pArray[k]) )
371 break;
372 if ( k == vRound2->nSize ) // there is no assigned vars, delete this one
373 Msat_OrderRingRemove( &p->rVars, &p->pVars[vRound->pArray[i]] );
374 }
375//timeSelect += clock() - clk;
376// Msat_OrderCheck( p );
377}
378
391{
392}
393
394
406void Msat_OrderRingAddLast( Msat_OrderRing_t * pRing, Msat_OrderVar_t * pVar )
407{
408//printf( "adding %d\n", pVar->Num );
409 // check that the node is not in a ring
410 assert( pVar->pPrev == NULL );
411 assert( pVar->pNext == NULL );
412 // if the ring is empty, make the node point to itself
413 pRing->nItems++;
414 if ( pRing->pRoot == NULL )
415 {
416 pRing->pRoot = pVar;
417 pVar->pPrev = pVar;
418 pVar->pNext = pVar;
419 return;
420 }
421 // if the ring is not empty, add it as the last entry
422 pVar->pPrev = pRing->pRoot->pPrev;
423 pVar->pNext = pRing->pRoot;
424 pVar->pPrev->pNext = pVar;
425 pVar->pNext->pPrev = pVar;
426
427 // move the root so that it points to the new entry
428// pRing->pRoot = pRing->pRoot->pPrev;
429}
430
442void Msat_OrderRingRemove( Msat_OrderRing_t * pRing, Msat_OrderVar_t * pVar )
443{
444//printf( "removing %d\n", pVar->Num );
445 // check that the var is in a ring
446 assert( pVar->pPrev );
447 assert( pVar->pNext );
448 pRing->nItems--;
449 if ( pRing->nItems == 0 )
450 {
451 assert( pRing->pRoot == pVar );
452 pVar->pPrev = NULL;
453 pVar->pNext = NULL;
454 pRing->pRoot = NULL;
455 return;
456 }
457 // move the root if needed
458 if ( pRing->pRoot == pVar )
459 pRing->pRoot = pVar->pNext;
460 // move the root to the next entry after pVar
461 // this way all the additions to the list will be traversed first
462// pRing->pRoot = pVar->pPrev;
463 // delete the node
464 pVar->pPrev->pNext = pVar->pNext;
465 pVar->pNext->pPrev = pVar->pPrev;
466 pVar->pPrev = NULL;
467 pVar->pNext = NULL;
468}
469
470
474
475
477
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define ALLOC(type, num)
Definition avl.h:27
#define REALLOC(type, obj, num)
Definition avl.h:29
Cube * p
Definition exorList.c:222
int Var
Definition exorList.c:228
ABC_NAMESPACE_IMPL_START abctime timeSelect
DECLARATIONS ///.
Definition fraigMan.c:28
abctime timeAssign
Definition fraigMan.c:29
Msat_Clause_t * Msat_ClauseVecReadEntry(Msat_ClauseVec_t *p, int i)
struct Msat_Order_t_ Msat_Order_t
Definition msatInt.h:59
#define MSAT_ORDER_UNKNOWN
Definition msatInt.h:70
#define Msat_OrderVarIsUsedInCone(p, i)
Definition msatOrderJ.c:71
#define Msat_OrderVarIsAssigned(p, i)
Definition msatOrderJ.c:70
#define Msat_OrderRingForEachEntry(pRing, pVar, pNext)
Definition msatOrderJ.c:74
void Msat_OrderClean(Msat_Order_t *p, Msat_IntVec_t *vCone)
Definition msatOrderJ.c:150
struct Msat_OrderRing_t_ Msat_OrderRing_t
Definition msatOrderJ.c:37
Msat_Order_t * Msat_OrderAlloc(Msat_Solver_t *pSat)
FUNCTION DEFINITIONS ///.
Definition msatOrderJ.c:102
typedefABC_NAMESPACE_IMPL_START struct Msat_OrderVar_t_ Msat_OrderVar_t
DECLARATIONS ///.
Definition msatOrderJ.c:36
void Msat_OrderVarUnassigned(Msat_Order_t *p, int Var)
Definition msatOrderJ.c:343
void Msat_OrderVarAssigned(Msat_Order_t *p, int Var)
Definition msatOrderJ.c:305
int Msat_OrderVarSelect(Msat_Order_t *p)
Definition msatOrderJ.c:262
void Msat_OrderFree(Msat_Order_t *p)
Definition msatOrderJ.c:245
int Msat_OrderCheck(Msat_Order_t *p)
Definition msatOrderJ.c:171
#define Msat_OrderVarIsInBoundary(p, i)
Definition msatOrderJ.c:69
void Msat_OrderSetBounds(Msat_Order_t *p, int nVarsMax)
Definition msatOrderJ.c:123
void Msat_OrderUpdate(Msat_Order_t *p, int Var)
Definition msatOrderJ.c:390
struct Msat_IntVec_t_ Msat_IntVec_t
Definition msat.h:45
typedefABC_NAMESPACE_HEADER_START struct Msat_Solver_t_ Msat_Solver_t
INCLUDES ///.
Definition msat.h:42
int Msat_IntVecReadSize(Msat_IntVec_t *p)
Definition msatVec.c:233
int * Msat_IntVecReadArray(Msat_IntVec_t *p)
Definition msatVec.c:217
Msat_OrderVar_t * pRoot
Definition msatOrderJ.c:50
Msat_OrderVar_t * pNext
Definition msatOrderJ.c:42
Msat_OrderVar_t * pPrev
Definition msatOrderJ.c:43
DECLARATIONS ///.
Definition msatOrderH.c:32
Msat_OrderVar_t * pVars
Definition msatOrderJ.c:58
Msat_Solver_t * pSat
Definition msatOrderH.c:33
Msat_OrderRing_t rVars
Definition msatOrderJ.c:60
#define assert(ex)
Definition util_old.h:213
char * memset()
VOID_HACK free()