ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
giaCTas.c
Go to the documentation of this file.
1
20
21#include "gia.h"
22
24
25
26//#define gia_assert(exp) ((void)0)
27//#define gia_assert(exp) (assert(exp))
28
32
33typedef struct Tas_Par_t_ Tas_Par_t;
35{
36 // conflict limits
37 int nBTLimit; // limit on the number of conflicts
38 int nJustLimit; // limit on the size of justification queue
39 // current parameters
40 int nBTThis; // number of conflicts
41 int nBTThisNc; // number of conflicts
42 int nJustThis; // max size of the frontier
43 int nBTTotal; // total number of conflicts
44 int nJustTotal; // total size of the frontier
45 // activity
46 float VarDecay; // variable activity decay
47 int VarInc; // variable increment
48 // decision heuristics
49 int fUseActive; // use most active
50 int fUseHighest; // use node with the highest ID
51 int fUseLowest; // use node with the highest ID
52 int fUseMaxFF; // use node with the largest fanin fanout
53 // other
55};
56
57typedef struct Tas_Cls_t_ Tas_Cls_t;
59{
60 int iNext[2]; // beginning of the queue
61 int nLits; // the number of literals
62 int pLits[0]; // clause literals
63};
64
65typedef struct Tas_Sto_t_ Tas_Sto_t;
67{
68 int iCur; // current position
69 int nSize; // allocated size
70 int * pData; // clause information
71};
72
73typedef struct Tas_Que_t_ Tas_Que_t;
75{
76 int iHead; // beginning of the queue
77 int iTail; // end of the queue
78 int nSize; // allocated size
79 Gia_Obj_t ** pData; // nodes stored in the queue
80};
81
83{
84 Tas_Par_t Pars; // parameters
85 Gia_Man_t * pAig; // AIG manager
86 Tas_Que_t pProp; // propagation queue
87 Tas_Que_t pJust; // justification queue
88 Tas_Que_t pClauses; // clause queue
89 Gia_Obj_t ** pIter; // iterator through clause vars
90 Vec_Int_t * vLevReas; // levels and decisions
91 Vec_Int_t * vModel; // satisfying assignment
92 Vec_Ptr_t * vTemp; // temporary storage
93 // watched clauses
94 Tas_Sto_t pStore; // storage for watched clauses
95 int * pWatches; // watched lists for each literal
96 Vec_Int_t * vWatchLits; // lits whose watched are assigned
97 int nClauses; // the counter of clauses
98 // activity
99 float * pActivity; // variable activity
100 Vec_Int_t * vActiveVars; // variables with activity
101 // SAT calls statistics
102 int nSatUnsat; // the number of proofs
103 int nSatSat; // the number of failure
104 int nSatUndec; // the number of timeouts
105 int nSatTotal; // the number of calls
106 // conflicts
107 int nConfUnsat; // conflicts in unsat problems
108 int nConfSat; // conflicts in sat problems
109 int nConfUndec; // conflicts in undec problems
110 // runtime stats
113 abctime timeSatUndec; // undecided
114 abctime timeTotal; // total runtime
115};
116
117static inline int Tas_VarIsAssigned( Gia_Obj_t * pVar ) { return pVar->fMark0; }
118static inline void Tas_VarAssign( Gia_Obj_t * pVar ) { assert(!pVar->fMark0); pVar->fMark0 = 1; }
119static inline void Tas_VarUnassign( Gia_Obj_t * pVar ) { assert(pVar->fMark0); pVar->fMark0 = 0; pVar->fMark1 = 0; pVar->Value = ~0; }
120static inline int Tas_VarValue( Gia_Obj_t * pVar ) { assert(pVar->fMark0); return pVar->fMark1; }
121static inline void Tas_VarSetValue( Gia_Obj_t * pVar, int v ) { assert(pVar->fMark0); pVar->fMark1 = v; }
122static inline int Tas_VarIsJust( Gia_Obj_t * pVar ) { return Gia_ObjIsAnd(pVar) && !Tas_VarIsAssigned(Gia_ObjFanin0(pVar)) && !Tas_VarIsAssigned(Gia_ObjFanin1(pVar)); }
123static inline int Tas_VarFanin0Value( Gia_Obj_t * pVar ) { return !Tas_VarIsAssigned(Gia_ObjFanin0(pVar)) ? 2 : (Tas_VarValue(Gia_ObjFanin0(pVar)) ^ Gia_ObjFaninC0(pVar)); }
124static inline int Tas_VarFanin1Value( Gia_Obj_t * pVar ) { return !Tas_VarIsAssigned(Gia_ObjFanin1(pVar)) ? 2 : (Tas_VarValue(Gia_ObjFanin1(pVar)) ^ Gia_ObjFaninC1(pVar)); }
125static inline int Tas_VarToLit( Tas_Man_t * p, Gia_Obj_t * pObj ) { assert( Tas_VarIsAssigned(pObj) ); return Abc_Var2Lit( Gia_ObjId(p->pAig, pObj), !Tas_VarValue(pObj) ); }
126static inline int Tas_LitIsTrue( Gia_Obj_t * pObj, int Lit ) { assert( Tas_VarIsAssigned(pObj) ); return Tas_VarValue(pObj) != Abc_LitIsCompl(Lit); }
127
128static inline int Tas_ClsHandle( Tas_Man_t * p, Tas_Cls_t * pClause ) { return ((int *)pClause) - p->pStore.pData; }
129static inline Tas_Cls_t * Tas_ClsFromHandle( Tas_Man_t * p, int h ) { return (Tas_Cls_t *)(p->pStore.pData + h); }
130
131static inline int Tas_VarDecLevel( Tas_Man_t * p, Gia_Obj_t * pVar ) { assert( pVar->Value != ~0 ); return Vec_IntEntry(p->vLevReas, 3*pVar->Value); }
132static inline Gia_Obj_t * Tas_VarReason0( Tas_Man_t * p, Gia_Obj_t * pVar ) { assert( pVar->Value != ~0 ); return pVar + Vec_IntEntry(p->vLevReas, 3*pVar->Value+1); }
133static inline Gia_Obj_t * Tas_VarReason1( Tas_Man_t * p, Gia_Obj_t * pVar ) { assert( pVar->Value != ~0 ); return pVar + Vec_IntEntry(p->vLevReas, 3*pVar->Value+2); }
134static inline int Tas_ClauseDecLevel( Tas_Man_t * p, int hClause ) { return Tas_VarDecLevel( p, p->pClauses.pData[hClause] ); }
135
136static inline int Tas_VarHasReasonCls( Tas_Man_t * p, Gia_Obj_t * pVar ) { assert( pVar->Value != ~0 ); return Vec_IntEntry(p->vLevReas, 3*pVar->Value+1) == 0 && Vec_IntEntry(p->vLevReas, 3*pVar->Value+2) != 0; }
137static inline Tas_Cls_t * Tas_VarReasonCls( Tas_Man_t * p, Gia_Obj_t * pVar ) { assert( pVar->Value != ~0 ); return Tas_ClsFromHandle( p, Vec_IntEntry(p->vLevReas, 3*pVar->Value+2) ); }
138
139#define Tas_QueForEachEntry( Que, pObj, i ) \
140 for ( i = (Que).iHead; (i < (Que).iTail) && ((pObj) = (Que).pData[i]); i++ )
141
142#define Tas_ClauseForEachVar( p, hClause, pObj ) \
143 for ( (p)->pIter = (p)->pClauses.pData + hClause; (pObj = *pIter); (p)->pIter++ )
144#define Tas_ClauseForEachVar1( p, hClause, pObj ) \
145 for ( (p)->pIter = (p)->pClauses.pData+hClause+1; (pObj = *pIter); (p)->pIter++ )
146
150
163{
164 memset( pPars, 0, sizeof(Tas_Par_t) );
165 pPars->nBTLimit = 2000; // limit on the number of conflicts
166 pPars->nJustLimit = 2000; // limit on the size of justification queue
167 pPars->fUseActive = 0; // use node with the highest activity
168 pPars->fUseHighest = 1; // use node with the highest ID
169 pPars->fUseLowest = 0; // use node with the lowest ID
170 pPars->fUseMaxFF = 0; // use node with the largest fanin fanout
171 pPars->fVerbose = 1; // print detailed statistics
172 pPars->VarDecay = (float)0.95; // variable decay
173 pPars->VarInc = 1.0; // variable increment
174}
175
187Tas_Man_t * Tas_ManAlloc( Gia_Man_t * pAig, int nBTLimit )
188{
189 Tas_Man_t * p;
190 p = ABC_CALLOC( Tas_Man_t, 1 );
191 Tas_SetDefaultParams( &p->Pars );
192 p->pAig = pAig;
193 p->Pars.nBTLimit = nBTLimit;
194 p->pProp.nSize = p->pJust.nSize = p->pClauses.nSize = 10000;
195 p->pProp.pData = ABC_ALLOC( Gia_Obj_t *, p->pProp.nSize );
196 p->pJust.pData = ABC_ALLOC( Gia_Obj_t *, p->pJust.nSize );
197 p->pClauses.pData = ABC_ALLOC( Gia_Obj_t *, p->pClauses.nSize );
198 p->pClauses.iHead = p->pClauses.iTail = 1;
199 p->vModel = Vec_IntAlloc( 1000 );
200 p->vLevReas = Vec_IntAlloc( 1000 );
201 p->vTemp = Vec_PtrAlloc( 1000 );
202 p->pStore.iCur = 16;
203 p->pStore.nSize = 10000;
204 p->pStore.pData = ABC_ALLOC( int, p->pStore.nSize );
205 p->pWatches = ABC_CALLOC( int, 2 * Gia_ManObjNum(pAig) );
206 p->vWatchLits = Vec_IntAlloc( 100 );
207 p->pActivity = ABC_CALLOC( float, Gia_ManObjNum(pAig) );
208 p->vActiveVars = Vec_IntAlloc( 100 );
209 return p;
210}
211
224{
225 Vec_IntFree( p->vActiveVars );
226 Vec_IntFree( p->vWatchLits );
227 Vec_IntFree( p->vLevReas );
228 Vec_IntFree( p->vModel );
229 Vec_PtrFree( p->vTemp );
230 ABC_FREE( p->pActivity );
231 ABC_FREE( p->pWatches );
232 ABC_FREE( p->pStore.pData );
233 ABC_FREE( p->pClauses.pData );
234 ABC_FREE( p->pProp.pData );
235 ABC_FREE( p->pJust.pData );
236 ABC_FREE( p );
237}
238
251{
252 return p->vModel;
253}
254
255
256
257
269static inline int Tas_ManCheckLimits( Tas_Man_t * p )
270{
271 return p->Pars.nJustThis > p->Pars.nJustLimit || p->Pars.nBTThis > p->Pars.nBTLimit;
272}
273
285static inline void Tas_ManSaveModel( Tas_Man_t * p, Vec_Int_t * vCex )
286{
287 Gia_Obj_t * pVar;
288 int i;
289 Vec_IntClear( vCex );
290 p->pProp.iHead = 0;
291// printf( "\n" );
292 Tas_QueForEachEntry( p->pProp, pVar, i )
293 {
294 if ( Gia_ObjIsCi(pVar) )
295// Vec_IntPush( vCex, Abc_Var2Lit(Gia_ObjId(p->pAig,pVar), !Tas_VarValue(pVar)) );
296 Vec_IntPush( vCex, Abc_Var2Lit(Gia_ObjCioId(pVar), !Tas_VarValue(pVar)) );
297/*
298 printf( "%5d(%d) = ", Gia_ObjId(p->pAig, pVar), Tas_VarValue(pVar) );
299 if ( Gia_ObjIsCi(pVar) )
300 printf( "pi %d\n", Gia_ObjCioId(pVar) );
301 else
302 {
303 printf( "%5d %d & ", Gia_ObjFaninId0p(p->pAig, pVar), Gia_ObjFaninC0(pVar) );
304 printf( "%5d %d ", Gia_ObjFaninId1p(p->pAig, pVar), Gia_ObjFaninC1(pVar) );
305 printf( "\n" );
306 }
307*/
308 }
309}
310
322static inline int Tas_QueIsEmpty( Tas_Que_t * p )
323{
324 return p->iHead == p->iTail;
325}
326
338static inline void Tas_QuePush( Tas_Que_t * p, Gia_Obj_t * pObj )
339{
340 if ( p->iTail == p->nSize )
341 {
342 p->nSize *= 2;
343 p->pData = ABC_REALLOC( Gia_Obj_t *, p->pData, p->nSize );
344 }
345 p->pData[p->iTail++] = pObj;
346}
347
359static inline int Tas_QueHasNode( Tas_Que_t * p, Gia_Obj_t * pObj )
360{
361 Gia_Obj_t * pTemp;
362 int i;
363 Tas_QueForEachEntry( *p, pTemp, i )
364 if ( pTemp == pObj )
365 return 1;
366 return 0;
367}
368
380static inline void Tas_QueStore( Tas_Que_t * p, int * piHeadOld, int * piTailOld )
381{
382 int i;
383 *piHeadOld = p->iHead;
384 *piTailOld = p->iTail;
385 for ( i = *piHeadOld; i < *piTailOld; i++ )
386 Tas_QuePush( p, p->pData[i] );
387 p->iHead = *piTailOld;
388}
389
401static inline void Tas_QueRestore( Tas_Que_t * p, int iHeadOld, int iTailOld )
402{
403 p->iHead = iHeadOld;
404 p->iTail = iTailOld;
405}
406
418static inline int Tas_QueFinish( Tas_Que_t * p )
419{
420 int iHeadOld = p->iHead;
421 assert( p->iHead < p->iTail );
422 Tas_QuePush( p, NULL );
423 p->iHead = p->iTail;
424 return iHeadOld;
425}
426
427
439static inline int Tas_VarFaninFanoutMax( Tas_Man_t * p, Gia_Obj_t * pObj )
440{
441 int Count0, Count1;
442 assert( !Gia_IsComplement(pObj) );
443 assert( Gia_ObjIsAnd(pObj) );
444 Count0 = Gia_ObjRefNum( p->pAig, Gia_ObjFanin0(pObj) );
445 Count1 = Gia_ObjRefNum( p->pAig, Gia_ObjFanin1(pObj) );
446 return Abc_MaxInt( Count0, Count1 );
447}
448
449
450
462static inline Gia_Obj_t * Tas_ManFindActive( Tas_Man_t * p )
463{
464 Gia_Obj_t * pObj, * pObjMax = NULL;
465 float BestCost = 0.0;
466 int i, ObjId;
467 Tas_QueForEachEntry( p->pJust, pObj, i )
468 {
469 assert( Gia_ObjIsAnd(pObj) );
470 ObjId = Gia_ObjId( p->pAig, pObj );
471 if ( pObjMax == NULL ||
472 p->pActivity[Gia_ObjFaninId0(pObj,ObjId)] > BestCost ||
473 (p->pActivity[Gia_ObjFaninId0(pObj,ObjId)] == BestCost && pObjMax < Gia_ObjFanin0(pObj)) )
474 {
475 pObjMax = Gia_ObjFanin0(pObj);
476 BestCost = p->pActivity[Gia_ObjFaninId0(pObj,ObjId)];
477 }
478 if ( p->pActivity[Gia_ObjFaninId1(pObj,ObjId)] > BestCost ||
479 (p->pActivity[Gia_ObjFaninId1(pObj,ObjId)] == BestCost && pObjMax < Gia_ObjFanin1(pObj)) )
480 {
481 pObjMax = Gia_ObjFanin1(pObj);
482 BestCost = p->pActivity[Gia_ObjFaninId1(pObj,ObjId)];
483 }
484 }
485 return pObjMax;
486}
487
499static inline Gia_Obj_t * Tas_ManDecideHighestFanin( Tas_Man_t * p )
500{
501 Gia_Obj_t * pObj, * pObjMax = NULL;
502 int i, ObjId;
503 Tas_QueForEachEntry( p->pJust, pObj, i )
504 {
505 assert( Gia_ObjIsAnd(pObj) );
506 ObjId = Gia_ObjId( p->pAig, pObj );
507 if ( pObjMax == NULL || pObjMax < Gia_ObjFanin0(pObj) )
508 pObjMax = Gia_ObjFanin0(pObj);
509 if ( pObjMax < Gia_ObjFanin1(pObj) )
510 pObjMax = Gia_ObjFanin1(pObj);
511 }
512 return pObjMax;
513}
514
526static inline Gia_Obj_t * Tas_ManDecideHighest( Tas_Man_t * p )
527{
528 Gia_Obj_t * pObj, * pObjMax = NULL;
529 int i;
530 Tas_QueForEachEntry( p->pJust, pObj, i )
531 {
532//printf( "%d %6.2f ", Gia_ObjId(p->pAig, pObj), p->pActivity[Gia_ObjId(p->pAig, pObj)] );
533 if ( pObjMax == NULL || pObjMax < pObj )
534 pObjMax = pObj;
535 }
536//printf( "\n" );
537 return pObjMax;
538}
539
551static inline Gia_Obj_t * Tas_ManDecideHighestA( Tas_Man_t * p )
552{
553 Gia_Obj_t * pObj, * pObjMax = NULL;
554 int i;
555 Tas_QueForEachEntry( p->pJust, pObj, i )
556 {
557 if ( pObjMax == NULL ||
558 p->pActivity[Gia_ObjId(p->pAig, pObjMax)] < p->pActivity[Gia_ObjId(p->pAig, pObj)] )
559 pObjMax = pObj;
560 }
561 return pObjMax;
562}
563
575static inline Gia_Obj_t * Tas_ManDecideLowest( Tas_Man_t * p )
576{
577 Gia_Obj_t * pObj, * pObjMin = NULL;
578 int i;
579 Tas_QueForEachEntry( p->pJust, pObj, i )
580 if ( pObjMin == NULL || pObjMin > pObj )
581 pObjMin = pObj;
582 return pObjMin;
583}
584
596static inline Gia_Obj_t * Tas_ManDecideMaxFF( Tas_Man_t * p )
597{
598 Gia_Obj_t * pObj, * pObjMax = NULL;
599 int i, iMaxFF = 0, iCurFF;
600 assert( p->pAig->pRefs != NULL );
601 Tas_QueForEachEntry( p->pJust, pObj, i )
602 {
603 iCurFF = Tas_VarFaninFanoutMax( p, pObj );
604 assert( iCurFF > 0 );
605 if ( iMaxFF < iCurFF )
606 {
607 iMaxFF = iCurFF;
608 pObjMax = pObj;
609 }
610 }
611 return pObjMax;
612}
613
614
615
627static inline void Tas_ManCancelUntil( Tas_Man_t * p, int iBound )
628{
629 Gia_Obj_t * pVar;
630 int i;
631 assert( iBound <= p->pProp.iTail );
632 p->pProp.iHead = iBound;
633 Tas_QueForEachEntry( p->pProp, pVar, i )
634 Tas_VarUnassign( pVar );
635 p->pProp.iTail = iBound;
636 Vec_IntShrink( p->vLevReas, 3*iBound );
637}
638
642
654static inline void Tas_ManAssign( Tas_Man_t * p, Gia_Obj_t * pObj, int Level, Gia_Obj_t * pRes0, Gia_Obj_t * pRes1 )
655{
656 Gia_Obj_t * pObjR = Gia_Regular(pObj);
657 assert( Gia_ObjIsCand(pObjR) );
658 assert( !Tas_VarIsAssigned(pObjR) );
659 Tas_VarAssign( pObjR );
660 Tas_VarSetValue( pObjR, !Gia_IsComplement(pObj) );
661 assert( pObjR->Value == ~0 );
662 pObjR->Value = p->pProp.iTail;
663 Tas_QuePush( &p->pProp, pObjR );
664 Vec_IntPush( p->vLevReas, Level );
665 if ( pRes0 == NULL && pRes1 != 0 ) // clause
666 {
667 Vec_IntPush( p->vLevReas, 0 );
668 Vec_IntPush( p->vLevReas, Tas_ClsHandle( p, (Tas_Cls_t *)pRes1 ) );
669 }
670 else
671 {
672 Vec_IntPush( p->vLevReas, pRes0 ? pRes0-pObjR : 0 );
673 Vec_IntPush( p->vLevReas, pRes1 ? pRes1-pObjR : 0 );
674 }
675 assert( Vec_IntSize(p->vLevReas) == 3 * p->pProp.iTail );
676 s_Counter2++;
677}
678
679
691static inline int Tas_ManClauseSize( Tas_Man_t * p, int hClause )
692{
693 Tas_Que_t * pQue = &(p->pClauses);
694 Gia_Obj_t ** pIter;
695 for ( pIter = pQue->pData + hClause; *pIter; pIter++ );
696 return pIter - pQue->pData - hClause ;
697}
698
710static inline void Tas_ManPrintClause( Tas_Man_t * p, int Level, int hClause )
711{
712 Tas_Que_t * pQue = &(p->pClauses);
713 Gia_Obj_t * pObj;
714 int i;
715 assert( Tas_QueIsEmpty( pQue ) );
716 printf( "Level %2d : ", Level );
717 for ( i = hClause; (pObj = pQue->pData[i]); i++ )
718 printf( "%d=%d(%d) ", Gia_ObjId(p->pAig, pObj), Tas_VarValue(pObj), Tas_VarDecLevel(p, pObj) );
719 printf( "\n" );
720}
721
733static inline void Tas_ManPrintClauseNew( Tas_Man_t * p, int Level, int hClause )
734{
735 Tas_Que_t * pQue = &(p->pClauses);
736 Gia_Obj_t * pObj;
737 int i;
738 assert( Tas_QueIsEmpty( pQue ) );
739 printf( "Level %2d : ", Level );
740 for ( i = hClause; (pObj = pQue->pData[i]); i++ )
741 printf( "%c%d ", Tas_VarValue(pObj)? '+':'-', Gia_ObjId(p->pAig, pObj) );
742 printf( "\n" );
743}
744
756static inline void Tas_ManDeriveReason( Tas_Man_t * p, int Level )
757{
758 Tas_Que_t * pQue = &(p->pClauses);
759 Gia_Obj_t * pObj, * pReason;
760 int i, k, j, iLitLevel, iLitLevel2;//, Id;
761 assert( pQue->pData[pQue->iHead] == NULL );
762 assert( pQue->iHead + 1 < pQue->iTail );
763/*
764 for ( i = pQue->iHead + 1; i < pQue->iTail; i++ )
765 {
766 pObj = pQue->pData[i];
767 assert( pObj->fPhase == 0 );
768 }
769*/
770 // compact literals
771 Vec_PtrClear( p->vTemp );
772 for ( i = k = pQue->iHead + 1; i < pQue->iTail; i++ )
773 {
774 pObj = pQue->pData[i];
775 if ( pObj->fPhase ) // unassigned - seen again
776 continue;
777 // assigned - seen first time
778 pObj->fPhase = 1;
779 Vec_PtrPush( p->vTemp, pObj );
780 // bump activity
781// Id = Gia_ObjId( p->pAig, pObj );
782// if ( p->pActivity[Id] == 0.0 )
783// Vec_IntPush( p->vActiveVars, Id );
784// p->pActivity[Id] += p->Pars.VarInc;
785 // check decision level
786 iLitLevel = Tas_VarDecLevel( p, pObj );
787 if ( iLitLevel < Level )
788 {
789 pQue->pData[k++] = pObj;
790 continue;
791 }
792 assert( iLitLevel == Level );
793 if ( Tas_VarHasReasonCls( p, pObj ) )
794 {
795 Tas_Cls_t * pCls = Tas_VarReasonCls( p, pObj );
796 pReason = Gia_ManObj( p->pAig, Abc_Lit2Var(pCls->pLits[0]) );
797 assert( pReason == pObj );
798 for ( j = 1; j < pCls->nLits; j++ )
799 {
800 pReason = Gia_ManObj( p->pAig, Abc_Lit2Var(pCls->pLits[j]) );
801 iLitLevel2 = Tas_VarDecLevel( p, pReason );
802 assert( Tas_VarIsAssigned( pReason ) );
803 assert( !Tas_LitIsTrue( pReason, pCls->pLits[j] ) );
804 Tas_QuePush( pQue, pReason );
805 }
806 }
807 else
808 {
809 pReason = Tas_VarReason0( p, pObj );
810 if ( pReason == pObj ) // no reason
811 {
812 assert( pQue->pData[pQue->iHead] == NULL || Level == 0 );
813 if ( pQue->pData[pQue->iHead] == NULL )
814 pQue->pData[pQue->iHead] = pObj;
815 else
816 Tas_QuePush( pQue, pObj );
817 continue;
818 }
819 Tas_QuePush( pQue, pReason );
820 pReason = Tas_VarReason1( p, pObj );
821 if ( pReason != pObj ) // second reason
822 Tas_QuePush( pQue, pReason );
823 }
824 }
825 assert( pQue->pData[pQue->iHead] != NULL );
826 if ( pQue->pData[pQue->iHead] == NULL )
827 printf( "Tas_ManDeriveReason(): Failed to derive the clause!!!\n" );
828 pQue->iTail = k;
829 // clear the marks
830 Vec_PtrForEachEntry( Gia_Obj_t *, p->vTemp, pObj, i )
831 pObj->fPhase = 0;
832}
833
845static inline int Tas_ManAnalyze( Tas_Man_t * p, int Level, Gia_Obj_t * pVar, Gia_Obj_t * pFan0, Gia_Obj_t * pFan1 )
846{
847 Tas_Que_t * pQue = &(p->pClauses);
848 assert( Tas_VarIsAssigned(pVar) );
849 assert( Tas_VarIsAssigned(pFan0) );
850 assert( pFan1 == NULL || Tas_VarIsAssigned(pFan1) );
851 assert( Tas_QueIsEmpty( pQue ) );
852 Tas_QuePush( pQue, NULL );
853 Tas_QuePush( pQue, pVar );
854 Tas_QuePush( pQue, pFan0 );
855 if ( pFan1 )
856 Tas_QuePush( pQue, pFan1 );
857 Tas_ManDeriveReason( p, Level );
858 return Tas_QueFinish( pQue );
859}
860
861
873static inline int Tas_ManResolve( Tas_Man_t * p, int Level, int hClause0, int hClause1 )
874{
875 Tas_Que_t * pQue = &(p->pClauses);
876 Gia_Obj_t * pObj;
877 int i, LevelMax = -1, LevelCur;
878 assert( pQue->pData[hClause0] != NULL );
879 assert( pQue->pData[hClause0] == pQue->pData[hClause1] );
880/*
881 for ( i = hClause0 + 1; (pObj = pQue->pData[i]); i++ )
882 assert( pObj->fPhase == 0 );
883 for ( i = hClause1 + 1; (pObj = pQue->pData[i]); i++ )
884 assert( pObj->fPhase == 0 );
885*/
886 assert( Tas_QueIsEmpty( pQue ) );
887 Tas_QuePush( pQue, NULL );
888 for ( i = hClause0 + 1; (pObj = pQue->pData[i]); i++ )
889 {
890 if ( pObj->fPhase ) // unassigned - seen again
891 continue;
892 // assigned - seen first time
893 pObj->fPhase = 1;
894 Tas_QuePush( pQue, pObj );
895 LevelCur = Tas_VarDecLevel( p, pObj );
896 if ( LevelMax < LevelCur )
897 LevelMax = LevelCur;
898 }
899 for ( i = hClause1 + 1; (pObj = pQue->pData[i]); i++ )
900 {
901 if ( pObj->fPhase ) // unassigned - seen again
902 continue;
903 // assigned - seen first time
904 pObj->fPhase = 1;
905 Tas_QuePush( pQue, pObj );
906 LevelCur = Tas_VarDecLevel( p, pObj );
907 if ( LevelMax < LevelCur )
908 LevelMax = LevelCur;
909 }
910 for ( i = pQue->iHead + 1; i < pQue->iTail; i++ )
911 pQue->pData[i]->fPhase = 0;
912 Tas_ManDeriveReason( p, LevelMax );
913 return Tas_QueFinish( pQue );
914}
915
916
917
929static inline Tas_Cls_t * Tas_ManAllocCls( Tas_Man_t * p, int nSize )
930{
931 Tas_Cls_t * pCls;
932 if ( p->pStore.iCur + nSize > p->pStore.nSize )
933 {
934 p->pStore.nSize *= 2;
935 p->pStore.pData = ABC_REALLOC( int, p->pStore.pData, p->pStore.nSize );
936 }
937 pCls = Tas_ClsFromHandle( p, p->pStore.iCur ); p->pStore.iCur += nSize;
938 memset( pCls, 0, sizeof(int) * nSize );
939 p->nClauses++;
940 return pCls;
941}
942
954static inline void Tas_ManWatchClause( Tas_Man_t * p, Tas_Cls_t * pClause, int Lit )
955{
956 assert( Abc_Lit2Var(Lit) < Gia_ManObjNum(p->pAig) );
957 assert( pClause->nLits >= 2 );
958 assert( pClause->pLits[0] == Lit || pClause->pLits[1] == Lit );
959 if ( pClause->pLits[0] == Lit )
960 pClause->iNext[0] = p->pWatches[Abc_LitNot(Lit)];
961 else
962 pClause->iNext[1] = p->pWatches[Abc_LitNot(Lit)];
963 if ( p->pWatches[Abc_LitNot(Lit)] == 0 )
964 Vec_IntPush( p->vWatchLits, Abc_LitNot(Lit) );
965 p->pWatches[Abc_LitNot(Lit)] = Tas_ClsHandle( p, pClause );
966}
967
979static inline Tas_Cls_t * Tas_ManCreateCls( Tas_Man_t * p, int hClause )
980{
981 Tas_Cls_t * pClause;
982 Tas_Que_t * pQue = &(p->pClauses);
983 Gia_Obj_t * pObj;
984 int i, nLits = 0;
985 assert( Tas_QueIsEmpty( pQue ) );
986 assert( pQue->pData[hClause] != NULL );
987 for ( i = hClause; (pObj = pQue->pData[i]); i++ )
988 nLits++;
989 if ( nLits == 1 )
990 return NULL;
991 // create this clause
992 pClause = Tas_ManAllocCls( p, nLits + 3 );
993 pClause->nLits = nLits;
994 for ( i = hClause; (pObj = pQue->pData[i]); i++ )
995 {
996 assert( Tas_VarIsAssigned( pObj ) );
997 pClause->pLits[i-hClause] = Abc_LitNot( Tas_VarToLit(p, pObj) );
998 }
999 // add the clause as watched one
1000 if ( nLits >= 2 )
1001 {
1002 Tas_ManWatchClause( p, pClause, pClause->pLits[0] );
1003 Tas_ManWatchClause( p, pClause, pClause->pLits[1] );
1004 }
1005 // increment activity
1006// p->Pars.VarInc /= p->Pars.VarDecay;
1007 return pClause;
1008}
1009
1021static inline int Tas_ManCreateFromCls( Tas_Man_t * p, Tas_Cls_t * pCls, int Level )
1022{
1023 Tas_Que_t * pQue = &(p->pClauses);
1024 Gia_Obj_t * pObj;
1025 int i;
1026 assert( Tas_QueIsEmpty( pQue ) );
1027 Tas_QuePush( pQue, NULL );
1028 for ( i = 0; i < pCls->nLits; i++ )
1029 {
1030 pObj = Gia_ManObj( p->pAig, Abc_Lit2Var(pCls->pLits[i]) );
1031 assert( Tas_VarIsAssigned(pObj) );
1032 assert( !Tas_LitIsTrue( pObj, pCls->pLits[i] ) );
1033 Tas_QuePush( pQue, pObj );
1034 }
1035 Tas_ManDeriveReason( p, Level );
1036 return Tas_QueFinish( pQue );
1037}
1038
1050static inline int Tas_ManPropagateWatch( Tas_Man_t * p, int Level, int Lit )
1051{
1052 Gia_Obj_t * pObj;
1053 Tas_Cls_t * pCur;
1054 int * piPrev, iCur, iTemp;
1055 int i, LitF = Abc_LitNot(Lit);
1056 // iterate through the clauses
1057 piPrev = p->pWatches + Lit;
1058 for ( iCur = p->pWatches[Lit]; iCur; iCur = *piPrev )
1059 {
1060 pCur = Tas_ClsFromHandle( p, iCur );
1061 // make sure the false literal is in the second literal of the clause
1062 if ( pCur->pLits[0] == LitF )
1063 {
1064 pCur->pLits[0] = pCur->pLits[1];
1065 pCur->pLits[1] = LitF;
1066 iTemp = pCur->iNext[0];
1067 pCur->iNext[0] = pCur->iNext[1];
1068 pCur->iNext[1] = iTemp;
1069 }
1070 assert( pCur->pLits[1] == LitF );
1071
1072 // if the first literal is true, the clause is satisfied
1073// if ( pCur->pLits[0] == p->pAssigns[Abc_Lit2Var(pCur->pLits[0])] )
1074 pObj = Gia_ManObj( p->pAig, Abc_Lit2Var(pCur->pLits[0]) );
1075 if ( Tas_VarIsAssigned(pObj) && Tas_LitIsTrue( pObj, pCur->pLits[0] ) )
1076 {
1077 piPrev = &pCur->iNext[1];
1078 continue;
1079 }
1080
1081 // look for a new literal to watch
1082 for ( i = 2; i < (int)pCur->nLits; i++ )
1083 {
1084 // skip the case when the literal is false
1085// if ( Abc_LitNot(pCur->pLits[i]) == p->pAssigns[Abc_Lit2Var(pCur->pLits[i])] )
1086 pObj = Gia_ManObj( p->pAig, Abc_Lit2Var(pCur->pLits[i]) );
1087 if ( Tas_VarIsAssigned(pObj) && !Tas_LitIsTrue( pObj, pCur->pLits[i] ) )
1088 continue;
1089 // the literal is either true or unassigned - watch it
1090 pCur->pLits[1] = pCur->pLits[i];
1091 pCur->pLits[i] = LitF;
1092 // remove this clause from the watch list of Lit
1093 *piPrev = pCur->iNext[1];
1094 // add this clause to the watch list of pCur->pLits[i] (now it is pCur->pLits[1])
1095 Tas_ManWatchClause( p, pCur, pCur->pLits[1] );
1096 break;
1097 }
1098 if ( i < (int)pCur->nLits ) // found new watch
1099 continue;
1100
1101 // clause is unit - enqueue new implication
1102 pObj = Gia_ManObj( p->pAig, Abc_Lit2Var(pCur->pLits[0]) );
1103 if ( !Tas_VarIsAssigned(pObj) )
1104 {
1105/*
1106 {
1107 int iLitLevel, iPlace;
1108 for ( i = 1; i < (int)pCur->nLits; i++ )
1109 {
1110 pObj = Gia_ManObj( p->pAig, Abc_Lit2Var(pCur->pLits[i]) );
1111 iLitLevel = Tas_VarDecLevel( p, pObj );
1112 iPlace = pObj->Value;
1113 printf( "Lit = %d. Level = %d. Place = %d.\n", pCur->pLits[i], iLitLevel, iPlace );
1114 i = i;
1115 }
1116 }
1117*/
1118 Tas_ManAssign( p, Gia_ObjFromLit(p->pAig, pCur->pLits[0]), Level, NULL, (Gia_Obj_t *)pCur );
1119 piPrev = &pCur->iNext[1];
1120 continue;
1121 }
1122 // conflict detected - return the conflict clause
1123 assert( !Tas_LitIsTrue( pObj, pCur->pLits[0] ) );
1124 return Tas_ManCreateFromCls( p, pCur, Level );
1125 }
1126 return 0;
1127}
1128
1129
1130
1142static inline int Tas_ManPropagateOne( Tas_Man_t * p, Gia_Obj_t * pVar, int Level )
1143{
1144 int Value0, Value1, hClause;
1145 assert( !Gia_IsComplement(pVar) );
1146 assert( Tas_VarIsAssigned(pVar) );
1147 s_Counter3++;
1148 if ( (hClause = Tas_ManPropagateWatch( p, Level, Tas_VarToLit(p, pVar) )) )
1149 return hClause;
1150 if ( Gia_ObjIsCi(pVar) )
1151 return 0;
1152/*
1153 if ( pVar->iDiff0 == 570869 && pVar->iDiff1 == 546821 && Level == 3 )
1154 {
1155 Gia_Obj_t * pFan0 = Gia_ObjFanin0(pVar);
1156 Gia_Obj_t * pFan1 = Gia_ObjFanin1(pVar);
1157 int s = 0;
1158 }
1159*/
1160 assert( Gia_ObjIsAnd(pVar) );
1161 Value0 = Tas_VarFanin0Value(pVar);
1162 Value1 = Tas_VarFanin1Value(pVar);
1163 if ( Tas_VarValue(pVar) )
1164 { // value is 1
1165 if ( Value0 == 0 || Value1 == 0 ) // one is 0
1166 {
1167 if ( Value0 == 0 && Value1 != 0 )
1168 return Tas_ManAnalyze( p, Level, pVar, Gia_ObjFanin0(pVar), NULL );
1169 if ( Value0 != 0 && Value1 == 0 )
1170 return Tas_ManAnalyze( p, Level, pVar, Gia_ObjFanin1(pVar), NULL );
1171 assert( Value0 == 0 && Value1 == 0 );
1172 return Tas_ManAnalyze( p, Level, pVar, Gia_ObjFanin0(pVar), Gia_ObjFanin1(pVar) );
1173 }
1174 if ( Value0 == 2 ) // first is unassigned
1175 Tas_ManAssign( p, Gia_ObjChild0(pVar), Level, pVar, NULL );
1176 if ( Value1 == 2 ) // first is unassigned
1177 Tas_ManAssign( p, Gia_ObjChild1(pVar), Level, pVar, NULL );
1178 return 0;
1179 }
1180 // value is 0
1181 if ( Value0 == 0 || Value1 == 0 ) // one is 0
1182 return 0;
1183 if ( Value0 == 1 && Value1 == 1 ) // both are 1
1184 return Tas_ManAnalyze( p, Level, pVar, Gia_ObjFanin0(pVar), Gia_ObjFanin1(pVar) );
1185 if ( Value0 == 1 || Value1 == 1 ) // one is 1
1186 {
1187 if ( Value0 == 2 ) // first is unassigned
1188 Tas_ManAssign( p, Gia_Not(Gia_ObjChild0(pVar)), Level, pVar, Gia_ObjFanin1(pVar) );
1189 if ( Value1 == 2 ) // second is unassigned
1190 Tas_ManAssign( p, Gia_Not(Gia_ObjChild1(pVar)), Level, pVar, Gia_ObjFanin0(pVar) );
1191 return 0;
1192 }
1193 assert( Tas_VarIsJust(pVar) );
1194 assert( !Tas_QueHasNode( &p->pJust, pVar ) );
1195 Tas_QuePush( &p->pJust, pVar );
1196 return 0;
1197}
1198
1210static inline int Tas_ManPropagateTwo( Tas_Man_t * p, Gia_Obj_t * pVar, int Level )
1211{
1212 int Value0, Value1;
1213 s_Counter4++;
1214 assert( !Gia_IsComplement(pVar) );
1215 assert( Gia_ObjIsAnd(pVar) );
1216 assert( Tas_VarIsAssigned(pVar) );
1217 assert( !Tas_VarValue(pVar) );
1218 Value0 = Tas_VarFanin0Value(pVar);
1219 Value1 = Tas_VarFanin1Value(pVar);
1220 // value is 0
1221 if ( Value0 == 0 || Value1 == 0 ) // one is 0
1222 return 0;
1223 if ( Value0 == 1 && Value1 == 1 ) // both are 1
1224 return Tas_ManAnalyze( p, Level, pVar, Gia_ObjFanin0(pVar), Gia_ObjFanin1(pVar) );
1225 assert( Value0 == 1 || Value1 == 1 );
1226 if ( Value0 == 2 ) // first is unassigned
1227 Tas_ManAssign( p, Gia_Not(Gia_ObjChild0(pVar)), Level, pVar, Gia_ObjFanin1(pVar) );
1228 if ( Value1 == 2 ) // first is unassigned
1229 Tas_ManAssign( p, Gia_Not(Gia_ObjChild1(pVar)), Level, pVar, Gia_ObjFanin0(pVar) );
1230 return 0;
1231}
1232
1244int Tas_ManPropagate( Tas_Man_t * p, int Level )
1245{
1246 int hClause;
1247 Gia_Obj_t * pVar;
1248 int i, k;//, nIter = 0;
1249 while ( 1 )
1250 {
1251// nIter++;
1252 Tas_QueForEachEntry( p->pProp, pVar, i )
1253 {
1254 if ( (hClause = Tas_ManPropagateOne( p, pVar, Level )) )
1255 return hClause;
1256 }
1257 p->pProp.iHead = p->pProp.iTail;
1258 k = p->pJust.iHead;
1259 Tas_QueForEachEntry( p->pJust, pVar, i )
1260 {
1261 if ( Tas_VarIsJust( pVar ) )
1262 p->pJust.pData[k++] = pVar;
1263 else if ( (hClause = Tas_ManPropagateTwo( p, pVar, Level )) )
1264 return hClause;
1265 }
1266 if ( k == p->pJust.iTail )
1267 break;
1268 p->pJust.iTail = k;
1269 }
1270// printf( "%d ", nIter );
1271 return 0;
1272}
1273
1285int Tas_ManSolve_rec( Tas_Man_t * p, int Level )
1286{
1287 Tas_Que_t * pQue = &(p->pClauses);
1288 Gia_Obj_t * pVar = NULL, * pDecVar = NULL;
1289 int hClause, hLearn0, hLearn1;
1290 int iPropHead, iJustHead, iJustTail;
1291 // propagate assignments
1292 assert( !Tas_QueIsEmpty(&p->pProp) );
1293 if ( (hClause = Tas_ManPropagate( p, Level )) )
1294 {
1295 Tas_ManCreateCls( p, hClause );
1296 return hClause;
1297 }
1298 // check for satisfying assignment
1299 assert( Tas_QueIsEmpty(&p->pProp) );
1300 if ( Tas_QueIsEmpty(&p->pJust) )
1301 return 0;
1302 // quit using resource limits
1303 p->Pars.nJustThis = Abc_MaxInt( p->Pars.nJustThis, p->pJust.iTail - p->pJust.iHead );
1304 if ( Tas_ManCheckLimits( p ) )
1305 return 0;
1306 // remember the state before branching
1307 iPropHead = p->pProp.iHead;
1308 Tas_QueStore( &p->pJust, &iJustHead, &iJustTail );
1309 // find the decision variable
1310 if ( p->Pars.fUseActive )
1311 pVar = NULL, pDecVar = Tas_ManFindActive( p );
1312 else if ( p->Pars.fUseHighest )
1313// pVar = NULL, pDecVar = Tas_ManDecideHighestFanin( p );
1314 pVar = Tas_ManDecideHighest( p );
1315 else if ( p->Pars.fUseLowest )
1316 pVar = Tas_ManDecideLowest( p );
1317 else if ( p->Pars.fUseMaxFF )
1318 pVar = Tas_ManDecideMaxFF( p );
1319 else assert( 0 );
1320 // chose decision variable using fanout count
1321 if ( pVar != NULL )
1322 {
1323 assert( Tas_VarIsJust( pVar ) );
1324 if ( Gia_ObjRefNum(p->pAig, Gia_ObjFanin0(pVar)) > Gia_ObjRefNum(p->pAig, Gia_ObjFanin1(pVar)) )
1325 pDecVar = Gia_Not(Gia_ObjChild0(pVar));
1326 else
1327 pDecVar = Gia_Not(Gia_ObjChild1(pVar));
1328// pDecVar = Gia_NotCond( pDecVar, Gia_Regular(pDecVar)->fMark1 ^ !Gia_IsComplement(pDecVar) );
1329 }
1330 // decide on first fanin
1331 Tas_ManAssign( p, pDecVar, Level+1, NULL, NULL );
1332 if ( !(hLearn0 = Tas_ManSolve_rec( p, Level+1 )) )
1333 return 0;
1334 if ( pQue->pData[hLearn0] != Gia_Regular(pDecVar) )
1335 return hLearn0;
1336 Tas_ManCancelUntil( p, iPropHead );
1337 Tas_QueRestore( &p->pJust, iJustHead, iJustTail );
1338 // decide on second fanin
1339 Tas_ManAssign( p, Gia_Not(pDecVar), Level+1, NULL, NULL );
1340 if ( !(hLearn1 = Tas_ManSolve_rec( p, Level+1 )) )
1341 return 0;
1342 if ( pQue->pData[hLearn1] != Gia_Regular(pDecVar) )
1343 return hLearn1;
1344 hClause = Tas_ManResolve( p, Level, hLearn0, hLearn1 );
1345 Tas_ManCreateCls( p, hClause );
1346// Tas_ManPrintClauseNew( p, Level, hClause );
1347// if ( Level > Tas_ClauseDecLevel(p, hClause) )
1348// p->Pars.nBTThisNc++;
1349 p->Pars.nBTThis++;
1350 return hClause;
1351}
1352
1366int Tas_ManSolve( Tas_Man_t * p, Gia_Obj_t * pObj, Gia_Obj_t * pObj2 )
1367{
1368 int i, Entry, RetValue = 0;
1369 s_Counter2 = 0;
1370 Vec_IntClear( p->vModel );
1371 if ( pObj == Gia_ManConst0(p->pAig) || pObj2 == Gia_ManConst0(p->pAig) || pObj == Gia_Not(pObj2) )
1372 return 1;
1373 if ( pObj == Gia_ManConst1(p->pAig) && (pObj2 == NULL || pObj2 == Gia_ManConst1(p->pAig)) )
1374 return 0;
1375 assert( !p->pProp.iHead && !p->pProp.iTail );
1376 assert( !p->pJust.iHead && !p->pJust.iTail );
1377 assert( p->pClauses.iHead == 1 && p->pClauses.iTail == 1 );
1378 p->Pars.nBTThis = p->Pars.nJustThis = p->Pars.nBTThisNc = 0;
1379 Tas_ManAssign( p, pObj, 0, NULL, NULL );
1380 if ( pObj2 && !Tas_VarIsAssigned(Gia_Regular(pObj2)) )
1381 Tas_ManAssign( p, pObj2, 0, NULL, NULL );
1382 if ( !Tas_ManSolve_rec(p, 0) && !Tas_ManCheckLimits(p) )
1383 Tas_ManSaveModel( p, p->vModel );
1384 else
1385 RetValue = 1;
1386 Tas_ManCancelUntil( p, 0 );
1387 p->pJust.iHead = p->pJust.iTail = 0;
1388 p->pClauses.iHead = p->pClauses.iTail = 1;
1389 // clauses
1390 if ( p->nClauses > 0 )
1391 {
1392 p->pStore.iCur = 16;
1393 Vec_IntForEachEntry( p->vWatchLits, Entry, i )
1394 p->pWatches[Entry] = 0;
1395 Vec_IntClear( p->vWatchLits );
1396 p->nClauses = 0;
1397 }
1398 // activity
1399 Vec_IntForEachEntry( p->vActiveVars, Entry, i )
1400 p->pActivity[Entry] = 0.0;
1401 Vec_IntClear( p->vActiveVars );
1402 // statistics
1403 p->Pars.nBTTotal += p->Pars.nBTThis;
1404 p->Pars.nJustTotal = Abc_MaxInt( p->Pars.nJustTotal, p->Pars.nJustThis );
1405 if ( Tas_ManCheckLimits( p ) )
1406 RetValue = -1;
1407 return RetValue;
1408}
1409
1424{
1425 Gia_Obj_t * pObj;
1426 int i, Entry, RetValue = 0;
1427 s_Counter2 = 0;
1428 s_Counter3 = 0;
1429 s_Counter4 = 0;
1430 Vec_IntClear( p->vModel );
1431 Vec_PtrForEachEntry( Gia_Obj_t *, vObjs, pObj, i )
1432 if ( pObj == Gia_ManConst0(p->pAig) )
1433 return 1;
1434 assert( !p->pProp.iHead && !p->pProp.iTail );
1435 assert( !p->pJust.iHead && !p->pJust.iTail );
1436 assert( p->pClauses.iHead == 1 && p->pClauses.iTail == 1 );
1437 p->Pars.nBTThis = p->Pars.nJustThis = p->Pars.nBTThisNc = 0;
1438 Vec_PtrForEachEntry( Gia_Obj_t *, vObjs, pObj, i )
1439 if ( pObj != Gia_ManConst1(p->pAig) && !Tas_VarIsAssigned(Gia_Regular(pObj)) )
1440 Tas_ManAssign( p, pObj, 0, NULL, NULL );
1441 if ( !Tas_ManSolve_rec(p, 0) && !Tas_ManCheckLimits(p) )
1442 Tas_ManSaveModel( p, p->vModel );
1443 else
1444 RetValue = 1;
1445 Tas_ManCancelUntil( p, 0 );
1446 p->pJust.iHead = p->pJust.iTail = 0;
1447 p->pClauses.iHead = p->pClauses.iTail = 1;
1448 // clauses
1449 if ( p->nClauses > 0 )
1450 {
1451 p->pStore.iCur = 16;
1452 Vec_IntForEachEntry( p->vWatchLits, Entry, i )
1453 p->pWatches[Entry] = 0;
1454 Vec_IntClear( p->vWatchLits );
1455 p->nClauses = 0;
1456 }
1457 // activity
1458 Vec_IntForEachEntry( p->vActiveVars, Entry, i )
1459 p->pActivity[Entry] = 0.0;
1460 Vec_IntClear( p->vActiveVars );
1461 // statistics
1462 p->Pars.nBTTotal += p->Pars.nBTThis;
1463 p->Pars.nJustTotal = Abc_MaxInt( p->Pars.nJustTotal, p->Pars.nJustThis );
1464 if ( Tas_ManCheckLimits( p ) )
1465 RetValue = -1;
1466
1467// printf( "%d ", Gia_ManObjNum(p->pAig) );
1468// printf( "%d ", p->Pars.nBTThis );
1469// printf( "%d ", p->Pars.nJustThis );
1470// printf( "%d ", s_Counter2 );
1471// printf( "%d ", s_Counter3 );
1472// printf( "%d ", s_Counter4 );
1473 return RetValue;
1474}
1475
1488{
1489 printf( "CO = %8d ", Gia_ManCoNum(p->pAig) );
1490 printf( "AND = %8d ", Gia_ManAndNum(p->pAig) );
1491 printf( "Conf = %6d ", p->Pars.nBTLimit );
1492 printf( "JustMax = %5d ", p->Pars.nJustLimit );
1493 printf( "\n" );
1494 printf( "Unsat calls %6d (%6.2f %%) Ave conf = %8.1f ",
1495 p->nSatUnsat, p->nSatTotal? 100.0*p->nSatUnsat/p->nSatTotal :0.0, p->nSatUnsat? 1.0*p->nConfUnsat/p->nSatUnsat :0.0 );
1496 ABC_PRTP( "Time", p->timeSatUnsat, p->timeTotal );
1497 printf( "Sat calls %6d (%6.2f %%) Ave conf = %8.1f ",
1498 p->nSatSat, p->nSatTotal? 100.0*p->nSatSat/p->nSatTotal :0.0, p->nSatSat? 1.0*p->nConfSat/p->nSatSat : 0.0 );
1499 ABC_PRTP( "Time", p->timeSatSat, p->timeTotal );
1500 printf( "Undef calls %6d (%6.2f %%) Ave conf = %8.1f ",
1501 p->nSatUndec, p->nSatTotal? 100.0*p->nSatUndec/p->nSatTotal :0.0, p->nSatUndec? 1.0*p->nConfUndec/p->nSatUndec : 0.0 );
1502 ABC_PRTP( "Time", p->timeSatUndec, p->timeTotal );
1503 ABC_PRT( "Total time", p->timeTotal );
1504}
1505
1517Vec_Int_t * Tas_ManSolveMiterNc( Gia_Man_t * pAig, int nConfs, Vec_Str_t ** pvStatus, int fVerbose )
1518{
1519 extern void Gia_ManCollectTest( Gia_Man_t * pAig );
1520 extern void Cec_ManSatAddToStore( Vec_Int_t * vCexStore, Vec_Int_t * vCex, int Out );
1521 Tas_Man_t * p;
1522 Vec_Int_t * vCex, * vVisit, * vCexStore;
1523 Vec_Str_t * vStatus;
1524 Gia_Obj_t * pRoot;//, * pRootCopy;
1525// Gia_Man_t * pAigCopy = Gia_ManDup( pAig ), * pAigTemp;
1526
1527 int i, status;
1528 abctime clk, clkTotal = Abc_Clock();
1529 assert( Gia_ManRegNum(pAig) == 0 );
1530// Gia_ManCollectTest( pAig );
1531 // prepare AIG
1532 Gia_ManCreateRefs( pAig );
1533 Gia_ManCleanMark0( pAig );
1534 Gia_ManCleanMark1( pAig );
1535 Gia_ManFillValue( pAig ); // maps nodes into trail ids
1536 Gia_ManCleanPhase( pAig ); // maps nodes into trail ids
1537 // create logic network
1538 p = Tas_ManAlloc( pAig, nConfs );
1539 p->pAig = pAig;
1540 // create resulting data-structures
1541 vStatus = Vec_StrAlloc( Gia_ManPoNum(pAig) );
1542 vCexStore = Vec_IntAlloc( 10000 );
1543 vVisit = Vec_IntAlloc( 100 );
1544 vCex = Tas_ReadModel( p );
1545 // solve for each output
1546 Gia_ManForEachCo( pAig, pRoot, i )
1547 {
1548// printf( "%d=", i );
1549
1550 Vec_IntClear( vCex );
1551 if ( Gia_ObjIsConst0(Gia_ObjFanin0(pRoot)) )
1552 {
1553 if ( Gia_ObjFaninC0(pRoot) )
1554 {
1555// printf( "Constant 1 output of SRM!!!\n" );
1556 Cec_ManSatAddToStore( vCexStore, vCex, i ); // trivial counter-example
1557 Vec_StrPush( vStatus, 0 );
1558 }
1559 else
1560 {
1561// printf( "Constant 0 output of SRM!!!\n" );
1562 Vec_StrPush( vStatus, 1 );
1563 }
1564 continue;
1565 }
1566 clk = Abc_Clock();
1567// p->Pars.fUseActive = 1;
1568 p->Pars.fUseHighest = 1;
1569 p->Pars.fUseLowest = 0;
1570 status = Tas_ManSolve( p, Gia_ObjChild0(pRoot), NULL );
1571// printf( "\n" );
1572/*
1573 if ( status == -1 )
1574 {
1575 p->Pars.fUseHighest = 0;
1576 p->Pars.fUseLowest = 1;
1577 status = Tas_ManSolve( p, Gia_ObjChild0(pRoot) );
1578 }
1579*/
1580 Vec_StrPush( vStatus, (char)status );
1581 if ( status == -1 )
1582 {
1583// printf( "Unsolved %d.\n", i );
1584
1585 p->nSatUndec++;
1586 p->nConfUndec += p->Pars.nBTThis;
1587 Cec_ManSatAddToStore( vCexStore, NULL, i ); // timeout
1588 p->timeSatUndec += Abc_Clock() - clk;
1589 continue;
1590 }
1591
1592// pRootCopy = Gia_ManCo( pAigCopy, i );
1593// pRootCopy->iDiff0 = Gia_ObjId( pAigCopy, pRootCopy );
1594// pRootCopy->fCompl0 = 0;
1595
1596 if ( status == 1 )
1597 {
1598 p->nSatUnsat++;
1599 p->nConfUnsat += p->Pars.nBTThis;
1600 p->timeSatUnsat += Abc_Clock() - clk;
1601 continue;
1602 }
1603 p->nSatSat++;
1604 p->nConfSat += p->Pars.nBTThis;
1605// Gia_SatVerifyPattern( pAig, pRoot, vCex, vVisit );
1606 Cec_ManSatAddToStore( vCexStore, vCex, i );
1607 p->timeSatSat += Abc_Clock() - clk;
1608
1609// printf( "%d ", Vec_IntSize(vCex) );
1610 }
1611// pAigCopy = Gia_ManCleanup( pAigTemp = pAigCopy );
1612// Gia_ManStop( pAigTemp );
1613// Gia_DumpAiger( pAigCopy, "test", 0, 2 );
1614// Gia_ManStop( pAigCopy );
1615
1616 Vec_IntFree( vVisit );
1617 p->nSatTotal = Gia_ManPoNum(pAig);
1618 p->timeTotal = Abc_Clock() - clkTotal;
1619 if ( fVerbose )
1621// printf( "RecCalls = %8d. RecClause = %8d. RecNonChro = %8d.\n", p->nRecCall, p->nRecClause, p->nRecNonChro );
1622 Tas_ManStop( p );
1623 *pvStatus = vStatus;
1624
1625// printf( "Total number of cex literals = %d. (Ave = %d)\n",
1626// Vec_IntSize(vCexStore)-2*p->nSatUndec-2*p->nSatSat,
1627// (Vec_IntSize(vCexStore)-2*p->nSatUndec-2*p->nSatSat)/p->nSatSat );
1628 return vCexStore;
1629}
1630
1642int Tas_StorePatternTry( Vec_Ptr_t * vInfo, Vec_Ptr_t * vPres, int iBit, int * pLits, int nLits )
1643{
1644 unsigned * pInfo, * pPres;
1645 int i;
1646 for ( i = 0; i < nLits; i++ )
1647 {
1648 pInfo = (unsigned *)Vec_PtrEntry(vInfo, Abc_Lit2Var(pLits[i]));
1649 pPres = (unsigned *)Vec_PtrEntry(vPres, Abc_Lit2Var(pLits[i]));
1650 if ( Abc_InfoHasBit( pPres, iBit ) &&
1651 Abc_InfoHasBit( pInfo, iBit ) == Abc_LitIsCompl(pLits[i]) )
1652 return 0;
1653 }
1654 for ( i = 0; i < nLits; i++ )
1655 {
1656 pInfo = (unsigned *)Vec_PtrEntry(vInfo, Abc_Lit2Var(pLits[i]));
1657 pPres = (unsigned *)Vec_PtrEntry(vPres, Abc_Lit2Var(pLits[i]));
1658 Abc_InfoSetBit( pPres, iBit );
1659 if ( Abc_InfoHasBit( pInfo, iBit ) == Abc_LitIsCompl(pLits[i]) )
1660 Abc_InfoXorBit( pInfo, iBit );
1661 }
1662 return 1;
1663}
1664
1676int Tas_StorePattern( Vec_Ptr_t * vSimInfo, Vec_Ptr_t * vPres, Vec_Int_t * vCex )
1677{
1678 int k;
1679 for ( k = 1; k < 32; k++ )
1680 if ( Tas_StorePatternTry( vSimInfo, vPres, k, (int *)Vec_IntArray(vCex), Vec_IntSize(vCex) ) )
1681 break;
1682 return (int)(k < 32);
1683}
1684
1696void Tas_ManSolveMiterNc2( Gia_Man_t * pAig, int nConfs, Gia_Man_t * pAigOld, Vec_Ptr_t * vOldRoots, Vec_Ptr_t * vSimInfo )
1697{
1698 int nPatMax = 1000;
1699 int fVerbose = 1;
1700 extern void Gia_ManCollectTest( Gia_Man_t * pAig );
1701 extern void Cec_ManSatAddToStore( Vec_Int_t * vCexStore, Vec_Int_t * vCex, int Out );
1702 Tas_Man_t * p;
1703 Vec_Ptr_t * vPres;
1704 Vec_Int_t * vCex, * vVisit, * vCexStore;
1705 Vec_Str_t * vStatus;
1706 Gia_Obj_t * pRoot, * pOldRoot;
1707 int i, status;
1708 abctime clk, clkTotal = Abc_Clock();
1709 int Tried = 0, Stored = 0, Step = Gia_ManCoNum(pAig) / nPatMax;
1710 assert( Gia_ManRegNum(pAig) == 0 );
1711// Gia_ManCollectTest( pAig );
1712 // prepare AIG
1713 Gia_ManCreateRefs( pAig );
1714 Gia_ManCleanMark0( pAig );
1715 Gia_ManCleanMark1( pAig );
1716 Gia_ManFillValue( pAig ); // maps nodes into trail ids
1717 Gia_ManCleanPhase( pAig ); // maps nodes into trail ids
1718 // create logic network
1719 p = Tas_ManAlloc( pAig, nConfs );
1720 p->pAig = pAig;
1721 // create resulting data-structures
1722 vStatus = Vec_StrAlloc( Gia_ManPoNum(pAig) );
1723 vCexStore = Vec_IntAlloc( 10000 );
1724 vVisit = Vec_IntAlloc( 100 );
1725 vCex = Tas_ReadModel( p );
1726 // solve for each output
1727 vPres = Vec_PtrAllocSimInfo( Gia_ManCiNum(pAig), 1 );
1728 Vec_PtrCleanSimInfo( vPres, 0, 1 );
1729
1730 Gia_ManForEachCo( pAig, pRoot, i )
1731 {
1732 assert( !Gia_ObjIsConst0(Gia_ObjFanin0(pRoot)) );
1733 Vec_IntClear( vCex );
1734 clk = Abc_Clock();
1735 p->Pars.fUseHighest = 1;
1736 p->Pars.fUseLowest = 0;
1737 status = Tas_ManSolve( p, Gia_ObjChild0(pRoot), NULL );
1738 Vec_StrPush( vStatus, (char)status );
1739 if ( status == -1 )
1740 {
1741 p->nSatUndec++;
1742 p->nConfUndec += p->Pars.nBTThis;
1743// Cec_ManSatAddToStore( vCexStore, NULL, i ); // timeout
1744 p->timeSatUndec += Abc_Clock() - clk;
1745
1746 i += Step;
1747 continue;
1748 }
1749 if ( status == 1 )
1750 {
1751 p->nSatUnsat++;
1752 p->nConfUnsat += p->Pars.nBTThis;
1753 p->timeSatUnsat += Abc_Clock() - clk;
1754 // record proved
1755 pOldRoot = (Gia_Obj_t *)Vec_PtrEntry( vOldRoots, i );
1756 assert( !Gia_ObjProved( pAigOld, Gia_ObjId(pAigOld, pOldRoot) ) );
1757 Gia_ObjSetProved( pAigOld, Gia_ObjId(pAigOld, pOldRoot) );
1758
1759 i += Step;
1760 continue;
1761 }
1762 p->nSatSat++;
1763 p->nConfSat += p->Pars.nBTThis;
1764// Gia_SatVerifyPattern( pAig, pRoot, vCex, vVisit );
1765// Cec_ManSatAddToStore( vCexStore, vCex, i );
1766
1767 // save pattern
1768 Tried++;
1769 Stored += Tas_StorePattern( vSimInfo, vPres, vCex );
1770 p->timeSatSat += Abc_Clock() - clk;
1771 i += Step;
1772 }
1773 printf( "Tried = %d Stored = %d\n", Tried, Stored );
1774 Vec_IntFree( vVisit );
1775 p->nSatTotal = Gia_ManPoNum(pAig);
1776 p->timeTotal = Abc_Clock() - clkTotal;
1777 if ( fVerbose )
1779 Tas_ManStop( p );
1780 Vec_PtrFree( vPres );
1781 Vec_StrFree( vStatus );
1782}
1783
1784
1788
1789
1791
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_PRT(a, t)
Definition abc_global.h:255
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_PRTP(a, t, T)
Definition abc_global.h:258
#define ABC_REALLOC(type, obj, num)
Definition abc_global.h:268
#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
struct Vec_Str_t_ Vec_Str_t
Definition bblif.c:46
void Cec_ManSatAddToStore(Vec_Int_t *vCexStore, Vec_Int_t *vCex, int Out)
Definition cecSolve.c:996
Cube * p
Definition exorList.c:222
void Tas_ManSatPrintStats(Tas_Man_t *p)
Definition giaCTas.c:1487
#define Tas_QueForEachEntry(Que, pObj, i)
Definition giaCTas.c:139
Vec_Int_t * Tas_ManSolveMiterNc(Gia_Man_t *pAig, int nConfs, Vec_Str_t **pvStatus, int fVerbose)
Definition giaCTas.c:1517
int Tas_ManPropagate(Tas_Man_t *p, int Level)
Definition giaCTas.c:1244
struct Tas_Sto_t_ Tas_Sto_t
Definition giaCTas.c:65
Tas_Man_t * Tas_ManAlloc(Gia_Man_t *pAig, int nBTLimit)
Definition giaCTas.c:187
struct Tas_Que_t_ Tas_Que_t
Definition giaCTas.c:73
Vec_Int_t * Tas_ReadModel(Tas_Man_t *p)
Definition giaCTas.c:250
int Tas_ManSolveArray(Tas_Man_t *p, Vec_Ptr_t *vObjs)
Definition giaCTas.c:1423
void Tas_SetDefaultParams(Tas_Par_t *pPars)
FUNCTION DEFINITIONS ///.
Definition giaCTas.c:162
int s_Counter2
Definition giaCTas.c:639
int Tas_ManSolve_rec(Tas_Man_t *p, int Level)
Definition giaCTas.c:1285
typedefABC_NAMESPACE_IMPL_START struct Tas_Par_t_ Tas_Par_t
DECLARATIONS ///.
Definition giaCTas.c:33
void Tas_ManStop(Tas_Man_t *p)
Definition giaCTas.c:223
int Tas_StorePattern(Vec_Ptr_t *vSimInfo, Vec_Ptr_t *vPres, Vec_Int_t *vCex)
Definition giaCTas.c:1676
int Tas_ManSolve(Tas_Man_t *p, Gia_Obj_t *pObj, Gia_Obj_t *pObj2)
Definition giaCTas.c:1366
void Tas_ManSolveMiterNc2(Gia_Man_t *pAig, int nConfs, Gia_Man_t *pAigOld, Vec_Ptr_t *vOldRoots, Vec_Ptr_t *vSimInfo)
Definition giaCTas.c:1696
int s_Counter4
Definition giaCTas.c:641
int s_Counter3
Definition giaCTas.c:640
int Tas_StorePatternTry(Vec_Ptr_t *vInfo, Vec_Ptr_t *vPres, int iBit, int *pLits, int nLits)
Definition giaCTas.c:1642
struct Tas_Cls_t_ Tas_Cls_t
Definition giaCTas.c:57
void Gia_ManCollectTest(Gia_Man_t *p)
Definition giaDfs.c:232
struct Tas_Man_t_ Tas_Man_t
Definition gia.h:1821
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
void Gia_ManFillValue(Gia_Man_t *p)
Definition giaUtil.c:369
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
void Gia_ManCleanPhase(Gia_Man_t *p)
Definition giaUtil.c:472
void Gia_ManCleanMark0(Gia_Man_t *p)
Definition giaUtil.c:256
void Gia_ManCreateRefs(Gia_Man_t *p)
Definition giaUtil.c:779
#define Gia_ManForEachCo(p, pObj, i)
Definition gia.h:1236
void Gia_ManCleanMark1(Gia_Man_t *p)
Definition giaUtil.c:313
unsigned fMark1
Definition gia.h:86
unsigned Value
Definition gia.h:89
unsigned fPhase
Definition gia.h:87
unsigned fMark0
Definition gia.h:81
int nLits
Definition giaCTas.c:61
int iNext[2]
Definition giaCTas.c:60
int pLits[0]
Definition giaCTas.c:62
Gia_Man_t * pAig
Definition giaCTas.c:85
Vec_Ptr_t * vTemp
Definition giaCTas.c:92
Vec_Int_t * vModel
Definition giaCTas.c:91
int nConfUnsat
Definition giaCTas.c:107
Tas_Que_t pJust
Definition giaCTas.c:87
int * pWatches
Definition giaCTas.c:95
int nConfUndec
Definition giaCTas.c:109
abctime timeSatSat
Definition giaCTas.c:112
int nSatSat
Definition giaCTas.c:103
Tas_Par_t Pars
Definition giaCTas.c:84
abctime timeSatUndec
Definition giaCTas.c:113
int nSatUndec
Definition giaCTas.c:104
Tas_Que_t pProp
Definition giaCTas.c:86
Vec_Int_t * vWatchLits
Definition giaCTas.c:96
int nSatUnsat
Definition giaCTas.c:102
float * pActivity
Definition giaCTas.c:99
Tas_Sto_t pStore
Definition giaCTas.c:94
int nConfSat
Definition giaCTas.c:108
Vec_Int_t * vLevReas
Definition giaCTas.c:90
Vec_Int_t * vActiveVars
Definition giaCTas.c:100
Gia_Obj_t ** pIter
Definition giaCTas.c:89
Tas_Que_t pClauses
Definition giaCTas.c:88
abctime timeSatUnsat
Definition giaCTas.c:111
int nClauses
Definition giaCTas.c:97
int nSatTotal
Definition giaCTas.c:105
abctime timeTotal
Definition giaCTas.c:114
int VarInc
Definition giaCTas.c:47
int nJustLimit
Definition giaCTas.c:38
int nBTThis
Definition giaCTas.c:40
int nBTThisNc
Definition giaCTas.c:41
int fUseHighest
Definition giaCTas.c:50
int fUseMaxFF
Definition giaCTas.c:52
float VarDecay
Definition giaCTas.c:46
int fVerbose
Definition giaCTas.c:54
int nJustThis
Definition giaCTas.c:42
int fUseActive
Definition giaCTas.c:49
int nBTTotal
Definition giaCTas.c:43
int nBTLimit
Definition giaCTas.c:37
int fUseLowest
Definition giaCTas.c:51
int nJustTotal
Definition giaCTas.c:44
int iTail
Definition giaCTas.c:77
int nSize
Definition giaCTas.c:78
Gia_Obj_t ** pData
Definition giaCTas.c:79
int iHead
Definition giaCTas.c:76
int * pData
Definition giaCTas.c:70
int iCur
Definition giaCTas.c:68
int nSize
Definition giaCTas.c:69
#define assert(ex)
Definition util_old.h:213
char * memset()
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55