136 p->LogN = Abc_Base2Log(Number);
137 p->Power2 = 1 <<
p->LogN;
140 sat_solver_bookmark(
p->pSat );
143 p->vLeaves = Vec_IntAlloc(
p->nVars );
144 p->vAnds = Vec_IntAlloc(
p->nVars );
145 p->vNodes = Vec_IntAlloc(
p->nVars );
146 p->vRoots = Vec_IntAlloc(
p->nVars );
147 p->vRootVars = Vec_IntAlloc(
p->nVars );
148 p->pHash = Hsh_VecManStart( 1000 );
150 p->vArrs = Vec_IntAlloc( 0 );
151 p->vReqs = Vec_IntAlloc( 0 );
152 p->vWindow = Vec_WecAlloc( 128 );
153 p->vPath = Vec_IntAlloc( 32 );
154 p->vEdges = Vec_IntAlloc( 32 );
156 p->vCutsI1 = Vec_WrdAlloc( 1000 );
157 p->vCutsI2 = Vec_WrdAlloc( 1000 );
158 p->vCutsN1 = Vec_WrdAlloc( 1000 );
159 p->vCutsN2 = Vec_WrdAlloc( 1000 );
160 p->vCutsNum = Vec_IntAlloc( 64 );
161 p->vCutsStart = Vec_IntAlloc( 64 );
162 p->vCutsObj = Vec_IntAlloc( 1000 );
163 p->vSolInit = Vec_IntAlloc( 64 );
164 p->vSolCur = Vec_IntAlloc( 64 );
165 p->vSolBest = Vec_IntAlloc( 64 );
166 p->vTempI1 = Vec_WrdAlloc( 32 );
167 p->vTempI2 = Vec_WrdAlloc( 32 );
168 p->vTempN1 = Vec_WrdAlloc( 32 );
169 p->vTempN2 = Vec_WrdAlloc( 32 );
171 p->vLits = Vec_IntAlloc( 64 );
172 p->vAssump = Vec_IntAlloc( 64 );
173 p->vPolar = Vec_IntAlloc( 1000 );
180 p->timeStart = Abc_Clock();
182 sat_solver_bookmark(
p->pSat );
184 Vec_IntClear(
p->vLeaves );
185 Vec_IntClear(
p->vAnds );
186 Vec_IntClear(
p->vNodes );
187 Vec_IntClear(
p->vRoots );
188 Vec_IntClear(
p->vRootVars );
190 Vec_IntClear(
p->vArrs );
191 Vec_IntClear(
p->vReqs );
192 Vec_WecClear(
p->vWindow );
193 Vec_IntClear(
p->vPath );
194 Vec_IntClear(
p->vEdges );
196 Vec_WrdClear(
p->vCutsI1 );
197 Vec_WrdClear(
p->vCutsI2 );
198 Vec_WrdClear(
p->vCutsN1 );
199 Vec_WrdClear(
p->vCutsN2 );
200 Vec_IntClear(
p->vCutsNum );
201 Vec_IntClear(
p->vCutsStart );
202 Vec_IntClear(
p->vCutsObj );
203 Vec_IntClear(
p->vSolInit );
204 Vec_IntClear(
p->vSolCur );
205 Vec_IntClear(
p->vSolBest );
206 Vec_WrdClear(
p->vTempI1 );
207 Vec_WrdClear(
p->vTempI2 );
208 Vec_WrdClear(
p->vTempN1 );
209 Vec_WrdClear(
p->vTempN2 );
211 Vec_IntClear(
p->vLits );
212 Vec_IntClear(
p->vAssump );
213 Vec_IntClear(
p->vPolar );
220 Vec_IntFree(
p->vCardVars );
222 Vec_IntFree(
p->vLeaves );
223 Vec_IntFree(
p->vAnds );
224 Vec_IntFree(
p->vNodes );
225 Vec_IntFree(
p->vRoots );
226 Vec_IntFree(
p->vRootVars );
227 Hsh_VecManStop(
p->pHash );
229 Vec_IntFree(
p->vArrs );
230 Vec_IntFree(
p->vReqs );
231 Vec_WecFree(
p->vWindow );
232 Vec_IntFree(
p->vPath );
233 Vec_IntFree(
p->vEdges );
235 Vec_WrdFree(
p->vCutsI1 );
236 Vec_WrdFree(
p->vCutsI2 );
237 Vec_WrdFree(
p->vCutsN1 );
238 Vec_WrdFree(
p->vCutsN2 );
239 Vec_IntFree(
p->vCutsNum );
240 Vec_IntFree(
p->vCutsStart );
241 Vec_IntFree(
p->vCutsObj );
242 Vec_IntFree(
p->vSolInit );
243 Vec_IntFree(
p->vSolCur );
244 Vec_IntFree(
p->vSolBest );
245 Vec_WrdFree(
p->vTempI1 );
246 Vec_WrdFree(
p->vTempI2 );
247 Vec_WrdFree(
p->vTempN1 );
248 Vec_WrdFree(
p->vTempN2 );
250 Vec_IntFree(
p->vLits );
251 Vec_IntFree(
p->vAssump );
252 Vec_IntFree(
p->vPolar );
271 word CutI1, CutI2, CutN1, CutN2;
273 Vec_WecClear(
p->vWindow );
274 Vec_WecInit(
p->vWindow, Vec_IntSize(
p->vAnds) );
275 assert( Vec_IntSize(
p->vSolCur) > 0 );
278 CutI1 = Vec_WrdEntry(
p->vCutsI1, c );
279 CutI2 = Vec_WrdEntry(
p->vCutsI2, c );
280 CutN1 = Vec_WrdEntry(
p->vCutsN1, c );
281 CutN2 = Vec_WrdEntry(
p->vCutsN2, c );
282 iObj = Vec_IntEntry(
p->vCutsObj, c );
284 vObj = Vec_WecEntry(
p->vWindow, iObj );
285 Vec_IntClear( vObj );
286 assert( Vec_IntSize(vObj) == 0 );
287 for ( b = 0; b < 64; b++ )
288 if ( (CutI1 >> b) & 1 )
289 Vec_IntPush( vObj, Vec_IntEntry(
p->vLeaves, b) );
290 for ( b = 0; b < 64; b++ )
291 if ( (CutI2 >> b) & 1 )
292 Vec_IntPush( vObj, Vec_IntEntry(
p->vLeaves, 64+b) );
293 for ( b = 0; b < 64; b++ )
294 if ( (CutN1 >> b) & 1 )
295 Vec_IntPush( vObj, Vec_IntEntry(
p->vAnds, b) );
296 for ( b = 0; b < 64; b++ )
297 if ( (CutN2 >> b) & 1 )
298 Vec_IntPush( vObj, Vec_IntEntry(
p->vAnds, 64+b) );
316 int k, iFan, Delay = 0;
318 Delay = Abc_MaxInt( Delay, Vec_IntEntry(
p->vArrs, iFan) + 1 );
324 int DelayMax = DelayStart, Delay, iLut, iFan, k;
326 Vec_IntFill(
p->vArrs, Gia_ManObjNum(
p->pGia), 0 );
334 iLut = Gia_ObjId(
p->pGia, pObj );
335 if ( Gia_ObjIsAnd(pObj) )
337 if ( Gia_ObjIsLut2(
p->pGia, iLut) )
339 vFanins = Gia_ObjLutFanins2(
p->pGia, iLut);
341 Vec_IntWriteEntry(
p->vArrs, iLut, Delay );
342 DelayMax = Abc_MaxInt( DelayMax, Delay );
345 else if ( Gia_ObjIsCi(pObj) )
348 Vec_IntWriteEntry(
p->vArrs, iLut, arrTime );
350 else if ( Gia_ObjIsCo(pObj) )
352 int arrTime = Vec_IntEntry(
p->vArrs, Gia_ObjFaninId0(pObj, iLut) );
355 else if ( !Gia_ObjIsConst0(pObj) )
358 Vec_IntFree( vNodes );
364 vFanins = Gia_ObjLutFanins2(
p->pGia, iLut);
366 Vec_IntWriteEntry(
p->vArrs, iLut, Delay );
367 DelayMax = Abc_MaxInt( DelayMax, Delay );
373 Vec_IntDowndateEntry(
p->vReqs, iLut, DelayMax );
382 iLut = Gia_ObjId(
p->pGia, pObj );
383 if ( Gia_ObjIsAnd(pObj) )
385 if ( Gia_ObjIsLut2(
p->pGia, iLut) )
387 Delay = Vec_IntEntry(
p->vReqs, iLut) - 1;
388 vFanins = Gia_ObjLutFanins2(
p->pGia, iLut);
390 Vec_IntDowndateEntry(
p->vReqs, iFan, Delay );
393 else if ( Gia_ObjIsCi(pObj) )
395 int reqTime = Vec_IntEntry(
p->vReqs, iLut );
398 else if ( Gia_ObjIsCo(pObj) )
401 Vec_IntWriteEntry(
p->vReqs, Gia_ObjFaninId0(pObj, iLut), reqTime );
403 else if ( !Gia_ObjIsConst0(pObj) )
406 Vec_IntFree( vNodes );
412 Delay = Vec_IntEntry(
p->vReqs, iLut) - 1;
413 vFanins = Gia_ObjLutFanins2(
p->pGia, iLut);
415 Vec_IntDowndateEntry(
p->vReqs, iFan, Delay );
438 Vec_IntClear(
p->vPath );
443 p->timeTime += Abc_Clock() - clk;
444 if ( DelayMax <= DelayGlo )
448 if ( Vec_IntSize(vArray) > 0 )
449 Vec_IntPush(
p->vPath, Abc_Var2Lit(i, 1) );
467 int k, iFan, Delay = Vec_IntEntry(
p->vArrs, iLut);
469 if ( Vec_IntEntry(
p->vArrs, iFan) + 1 == Delay )
477 int i, iLut = -1, iAnd, Delay, Required;
478 if (
p->pGia->vEdge1 )
480 Vec_IntClear(
p->vPath );
487 vFanins = Vec_WecEntry(
p->vWindow, i );
489 Vec_IntWriteEntry(
p->vArrs, iLut, Delay );
494 Delay = Vec_IntEntry(
p->vArrs, iLut );
495 Required = Vec_IntEntry(
p->vReqs, iLut );
496 if ( Delay > Required )
499 p->timeTime += Abc_Clock() - clk;
500 if ( i == Vec_IntSize(
p->vRoots) )
505 iAnd = Vec_IntFind(
p->vAnds, iLut );
508 assert( iAnd == Vec_IntEntry(
p->vRootVars, i) );
511 Vec_IntPush(
p->vPath, Abc_Var2Lit(iAnd, 1) );
513 vFanins = Vec_WecEntry(
p->vWindow, iAnd );
518 iAnd = Vec_IntFind(
p->vAnds, iLut );
541 word CutI1, CutI2, CutN1, CutN2;
542 int i, c, b, iObj, iTemp;
543 assert( Vec_IntSize(
p->vSolBest) < Vec_IntSize(
p->vSolInit) );
546 vObj = Vec_WecEntry(
p->pGia->vMapping2, iObj);
548 Gia_ObjLutRefDecId(
p->pGia, iTemp );
549 Vec_IntClear( vObj );
553 CutI1 = Vec_WrdEntry(
p->vCutsI1, c );
554 CutI2 = Vec_WrdEntry(
p->vCutsI2, c );
555 CutN1 = Vec_WrdEntry(
p->vCutsN1, c );
556 CutN2 = Vec_WrdEntry(
p->vCutsN2, c );
557 iObj = Vec_IntEntry(
p->vCutsObj, c );
558 iObj = Vec_IntEntry(
p->vAnds, iObj );
559 vObj = Vec_WecEntry(
p->pGia->vMapping2, iObj );
560 Vec_IntClear( vObj );
561 assert( Vec_IntSize(vObj) == 0 );
562 for ( b = 0; b < 64; b++ )
563 if ( (CutI1 >> b) & 1 )
564 Vec_IntPush( vObj, Vec_IntEntry(
p->vLeaves, b) );
565 for ( b = 0; b < 64; b++ )
566 if ( (CutI2 >> b) & 1 )
567 Vec_IntPush( vObj, Vec_IntEntry(
p->vLeaves, 64+b) );
568 for ( b = 0; b < 64; b++ )
569 if ( (CutN1 >> b) & 1 )
570 Vec_IntPush( vObj, Vec_IntEntry(
p->vAnds, b) );
571 for ( b = 0; b < 64; b++ )
572 if ( (CutN2 >> b) & 1 )
573 Vec_IntPush( vObj, Vec_IntEntry(
p->vAnds, 64+b) );
575 Gia_ObjLutRefIncId(
p->pGia, iTemp );
612 for ( b = 0; b < 64; b++ )
613 if ( (CutI1 >> b) & 1 )
614 printf(
"i%d ", b ), Count++;
615 for ( b = 0; b < 64; b++ )
616 if ( (CutI2 >> b) & 1 )
617 printf(
"i%d ", 64+b ), Count++;
619 for ( b = 0; b < 64; b++ )
620 if ( (CutN1 >> b) & 1 )
621 printf(
"n%d ", b ), Count++;
622 for ( b = 0; b < 64; b++ )
623 if ( (CutN2 >> b) & 1 )
624 printf(
"n%d ", 64+b ), Count++;
628static int Sbl_ManFindAndPrintCut(
Sbl_Man_t *
p,
int c )
630 return Sbl_ManPrintCut( Vec_WrdEntry(
p->vCutsI1, c), Vec_WrdEntry(
p->vCutsI2, c), Vec_WrdEntry(
p->vCutsN1, c), Vec_WrdEntry(
p->vCutsN2, c) );
632static inline int Sbl_CutIsFeasible(
word CutI1,
word CutI2,
word CutN1,
word CutN2,
int LutSize )
634 int Count = (CutI1 != 0) + (CutI2 != 0) + (CutN1 != 0) + (CutN2 != 0);
636 CutI1 &= CutI1-1; CutI2 &= CutI2-1; CutN1 &= CutN1-1; CutN2 &= CutN2-1; Count += (CutI1 != 0) + (CutI2 != 0) + (CutN1 != 0) + (CutN2 != 0);
637 CutI1 &= CutI1-1; CutI2 &= CutI2-1; CutN1 &= CutN1-1; CutN2 &= CutN2-1; Count += (CutI1 != 0) + (CutI2 != 0) + (CutN1 != 0) + (CutN2 != 0);
638 CutI1 &= CutI1-1; CutI2 &= CutI2-1; CutN1 &= CutN1-1; CutN2 &= CutN2-1; Count += (CutI1 != 0) + (CutI2 != 0) + (CutN1 != 0) + (CutN2 != 0);
639 CutI1 &= CutI1-1; CutI2 &= CutI2-1; CutN1 &= CutN1-1; CutN2 &= CutN2-1; Count += (CutI1 != 0) + (CutI2 != 0) + (CutN1 != 0) + (CutN2 != 0);
642 CutI1 &= CutI1-1; CutI2 &= CutI2-1; CutN1 &= CutN1-1; CutN2 &= CutN2-1; Count += (CutI1 != 0) + (CutI2 != 0) + (CutN1 != 0) + (CutN2 != 0);
643 CutI1 &= CutI1-1; CutI2 &= CutI2-1; CutN1 &= CutN1-1; CutN2 &= CutN2-1; Count += (CutI1 != 0) + (CutI2 != 0) + (CutN1 != 0) + (CutN2 != 0);
649 assert( vCutsI1->nSize == vCutsN1->nSize );
650 assert( vCutsI2->nSize == vCutsN2->nSize );
651 for ( i = 0; i < vCutsI1->nSize; i++ )
652 if ( (vCutsI1->pArray[i] & CutI1) == vCutsI1->pArray[i] &&
653 (vCutsI2->pArray[i] & CutI2) == vCutsI2->pArray[i] &&
654 (vCutsN1->pArray[i] & CutN1) == vCutsN1->pArray[i] &&
655 (vCutsN2->pArray[i] & CutN2) == vCutsN2->pArray[i] )
657 for ( i = 0; i < vCutsI1->nSize; i++ )
658 if ( (vCutsI1->pArray[i] & CutI1) != CutI1 ||
659 (vCutsI2->pArray[i] & CutI2) != CutI2 ||
660 (vCutsN1->pArray[i] & CutN1) != CutN1 ||
661 (vCutsN2->pArray[i] & CutN2) != CutN2 )
663 Vec_WrdWriteEntry( vCutsI1, k, vCutsI1->pArray[i] );
664 Vec_WrdWriteEntry( vCutsI2, k, vCutsI2->pArray[i] );
665 Vec_WrdWriteEntry( vCutsN1, k, vCutsN1->pArray[i] );
666 Vec_WrdWriteEntry( vCutsN2, k, vCutsN2->pArray[i] );
669 Vec_WrdShrink( vCutsI1, k );
670 Vec_WrdShrink( vCutsI2, k );
671 Vec_WrdShrink( vCutsN1, k );
672 Vec_WrdShrink( vCutsN2, k );
673 Vec_WrdPush( vCutsI1, CutI1 );
674 Vec_WrdPush( vCutsI2, CutI2 );
675 Vec_WrdPush( vCutsN1, CutN1 );
676 Vec_WrdPush( vCutsN2, CutN2 );
679static inline void Sbl_ManComputeCutsOne(
Sbl_Man_t *
p,
int Fan0,
int Fan1,
int Obj )
681 word * pCutsI1 = Vec_WrdArray(
p->vCutsI1);
682 word * pCutsI2 = Vec_WrdArray(
p->vCutsI2);
683 word * pCutsN1 = Vec_WrdArray(
p->vCutsN1);
684 word * pCutsN2 = Vec_WrdArray(
p->vCutsN2);
685 int Start0 = Vec_IntEntry(
p->vCutsStart, Fan0 );
686 int Start1 = Vec_IntEntry(
p->vCutsStart, Fan1 );
687 int Limit0 = Start0 + Vec_IntEntry(
p->vCutsNum, Fan0 );
688 int Limit1 = Start1 + Vec_IntEntry(
p->vCutsNum, Fan1 );
690 assert( Obj >= 0 && Obj < 128 );
691 Vec_WrdClear(
p->vTempI1 );
692 Vec_WrdClear(
p->vTempI2 );
693 Vec_WrdClear(
p->vTempN1 );
694 Vec_WrdClear(
p->vTempN2 );
695 for ( i = Start0; i < Limit0; i++ )
696 for ( k = Start1; k < Limit1; k++ )
697 if ( Sbl_CutIsFeasible(pCutsI1[i] | pCutsI1[k], pCutsI2[i] | pCutsI2[k], pCutsN1[i] | pCutsN1[k], pCutsN2[i] | pCutsN2[k],
p->LutSize) )
698 Sbl_CutPushUncontained(
p->vTempI1,
p->vTempI2,
p->vTempN1,
p->vTempN2, pCutsI1[i] | pCutsI1[k], pCutsI2[i] | pCutsI2[k], pCutsN1[i] | pCutsN1[k], pCutsN2[i] | pCutsN2[k] );
699 Vec_IntPush(
p->vCutsStart, Vec_WrdSize(
p->vCutsI1) );
700 Vec_IntPush(
p->vCutsNum, Vec_WrdSize(
p->vTempI1) + 1 );
701 Vec_WrdAppend(
p->vCutsI1,
p->vTempI1 );
702 Vec_WrdAppend(
p->vCutsI2,
p->vTempI2 );
703 Vec_WrdAppend(
p->vCutsN1,
p->vTempN1 );
704 Vec_WrdAppend(
p->vCutsN2,
p->vTempN2 );
705 Vec_WrdPush(
p->vCutsI1, 0 );
706 Vec_WrdPush(
p->vCutsI2, 0 );
709 Vec_WrdPush(
p->vCutsN1, (((
word)1) << Obj) );
710 Vec_WrdPush(
p->vCutsN2, 0 );
714 Vec_WrdPush(
p->vCutsN1, 0 );
715 Vec_WrdPush(
p->vCutsN2, (((
word)1) << (Obj-64)) );
717 for ( i = 0; i <= Vec_WrdSize(
p->vTempI1); i++ )
718 Vec_IntPush(
p->vCutsObj, Obj );
722 word * pCutsI1 = Vec_WrdArray(
p->vCutsI1);
723 word * pCutsI2 = Vec_WrdArray(
p->vCutsI2);
724 word * pCutsN1 = Vec_WrdArray(
p->vCutsN1);
725 word * pCutsN2 = Vec_WrdArray(
p->vCutsN2);
726 int Start0 = Vec_IntEntry(
p->vCutsStart, Obj );
727 int Limit0 = Start0 + Vec_IntEntry(
p->vCutsNum, Obj );
732 for ( i = Start0; i < Limit0; i++ )
735 if ( pCutsI1[i] == CutI1 && pCutsI2[i] == CutI2 && pCutsN1[i] == CutN1 && pCutsN2[i] == CutN2 )
744 int i, k, Index, Fanin, nObjs = Vec_IntSize(
p->vLeaves) + Vec_IntSize(
p->vAnds);
745 assert( Vec_IntSize(
p->vLeaves) <= 128 && Vec_IntSize(
p->vAnds) <=
p->nVars );
747 Vec_IntClear(
p->vCutsStart );
748 Vec_IntClear(
p->vCutsObj );
749 Vec_IntClear(
p->vCutsNum );
750 Vec_WrdClear(
p->vCutsI1 );
751 Vec_WrdClear(
p->vCutsI2 );
752 Vec_WrdClear(
p->vCutsN1 );
753 Vec_WrdClear(
p->vCutsN2 );
756 Vec_IntPush(
p->vCutsStart, Vec_WrdSize(
p->vCutsI1) );
757 Vec_IntPush(
p->vCutsObj, -1 );
758 Vec_IntPush(
p->vCutsNum, 1 );
761 Vec_WrdPush(
p->vCutsI1, (((
word)1) << i) );
762 Vec_WrdPush(
p->vCutsI2, 0 );
766 Vec_WrdPush(
p->vCutsI1, 0 );
767 Vec_WrdPush(
p->vCutsI2, (((
word)1) << (i-64)) );
769 Vec_WrdPush(
p->vCutsN1, 0 );
770 Vec_WrdPush(
p->vCutsN2, 0 );
776 assert( Gia_ObjIsAnd(pObj) );
777 assert( ~Gia_ObjFanin0(pObj)->Value );
778 assert( ~Gia_ObjFanin1(pObj)->Value );
779 Sbl_ManComputeCutsOne(
p, Gia_ObjFanin0(pObj)->Value, Gia_ObjFanin1(pObj)->Value, i );
780 pObj->
Value = Vec_IntSize(
p->vLeaves) + i;
782 assert( Vec_IntSize(
p->vCutsStart) == nObjs );
783 assert( Vec_IntSize(
p->vCutsNum) == nObjs );
784 assert( Vec_WrdSize(
p->vCutsI1) == Vec_WrdSize(
p->vCutsN1) );
785 assert( Vec_WrdSize(
p->vCutsI2) == Vec_WrdSize(
p->vCutsN2) );
786 assert( Vec_WrdSize(
p->vCutsI1) == Vec_IntSize(
p->vCutsObj) );
788 Vec_IntClear(
p->vRootVars );
791 int Obj = Gia_ObjId(
p->pGia, pObj);
792 if ( Gia_ObjIsCi(pObj) )
794 assert( Gia_ObjIsLut2(
p->pGia, Obj) );
796 Vec_IntPush(
p->vRootVars, pObj->
Value - Vec_IntSize(
p->vLeaves) );
799 Vec_IntClear(
p->vPolar );
800 Vec_IntClear(
p->vSolInit );
803 word CutI1 = 0, CutI2 = 0, CutN1 = 0, CutN2 = 0;
804 int Obj = Gia_ObjId(
p->pGia, pObj);
805 if ( !Gia_ObjIsLut2(
p->pGia, Obj) )
807 assert( (
int)pObj->
Value == Vec_IntSize(
p->vLeaves) + i );
809 Vec_IntPush(
p->vPolar, i );
810 Vec_IntPush(
p->vSolInit, i );
813 vFanins = Gia_ObjLutFanins2(
p->pGia, Obj );
816 Gia_Obj_t * pFanin = Gia_ManObj(
p->pGia, Fanin );
817 assert( (
int)pFanin->
Value < Vec_IntSize(
p->vLeaves) || Gia_ObjIsLut2(
p->pGia, Fanin) );
820 if ( ~pFanin->
Value == 0 )
823 if ( (
int)pFanin->
Value < Vec_IntSize(
p->vLeaves) )
825 if ( (
int)pFanin->
Value < 64 )
828 CutI2 |= ((
word)1 << (pFanin->
Value - 64));
832 if ( pFanin->
Value - Vec_IntSize(
p->vLeaves) < 64 )
833 CutN1 |= ((
word)1 << (pFanin->
Value - Vec_IntSize(
p->vLeaves)));
835 CutN2 |= ((
word)1 << (pFanin->
Value - Vec_IntSize(
p->vLeaves) - 64));
839 Index = Sbl_ManFindCut(
p, Vec_IntSize(
p->vLeaves) + i, CutI1, CutI2, CutN1, CutN2 );
846 Vec_IntPush(
p->vPolar,
p->FirstVar+Index );
853 p->timeCut += Abc_Clock() - clk;
854 return Vec_WrdSize(
p->vCutsI1);
858 int i, k, c, pLits[2],
value;
859 word * pCutsN1 = Vec_WrdArray(
p->vCutsN1);
860 word * pCutsN2 = Vec_WrdArray(
p->vCutsN2);
864 for ( i = 0; i < Vec_IntSize(
p->vAnds); i++ )
866 int Start0 = Vec_IntEntry(
p->vCutsStart, Vec_IntSize(
p->vLeaves) + i );
867 int Limit0 = Start0 + Vec_IntEntry(
p->vCutsNum, Vec_IntSize(
p->vLeaves) + i ) - 1;
869 Vec_IntClear(
p->vLits );
870 Vec_IntPush(
p->vLits, Abc_Var2Lit(i, 1) );
872 for ( k = Start0; k < Limit0; k++ )
874 Vec_IntPush(
p->vLits, Abc_Var2Lit(
p->FirstVar+k, 0) );
881 for ( k = Start0; k < Limit0; k++ )
883 word Cut1 = pCutsN1[k];
884 word Cut2 = pCutsN2[k];
887 pLits[0] = Abc_Var2Lit(
p->FirstVar+k, 1 );
888 pLits[1] = Abc_Var2Lit( i, 0 );
892 for ( c = 0; c < 64 && Cut1; c++, Cut1 >>= 1 )
894 if ( (Cut1 & 1) == 0 )
897 pLits[1] = Abc_Var2Lit( c, 0 );
901 for ( c = 0; c < 64 && Cut2; c++, Cut2 >>= 1 )
903 if ( (Cut2 & 1) == 0 )
906 pLits[1] = Abc_Var2Lit( c+64, 0 );
912 sat_solver_set_polarity(
p->pSat, Vec_IntArray(
p->vPolar), Vec_IntSize(
p->vPolar) );
933 Vec_IntClear(
p->vLeaves );
935 Vec_IntPush(
p->vLeaves, ObjId );
937 Vec_IntClear(
p->vAnds );
939 Vec_IntPush(
p->vAnds, ObjId );
941 Vec_IntClear(
p->vRoots );
943 Vec_IntPush(
p->vRoots, ObjId );
949 Vec_Int_t * vRoots, * vNodes, * vLeaves, * vAnds;
951 p->timeWin += Abc_Clock() - clk;
954 Vec_IntClear(
p->vRoots ); Vec_IntAppend(
p->vRoots, vRoots );
955 Vec_IntClear(
p->vNodes ); Vec_IntAppend(
p->vNodes, vNodes );
956 Vec_IntClear(
p->vLeaves ); Vec_IntAppend(
p->vLeaves, vLeaves );
957 Vec_IntClear(
p->vAnds ); Vec_IntAppend(
p->vAnds, vAnds );
970 abctime clk = Abc_Clock(), clk2;
971 int i, status, Root, Count, StartSol, nConfTotal = 0, nIters = 0;
972 int nEntries = Hsh_VecSize(
p->pHash );
981 if (
p->fVeryVerbose )
982 printf(
"Obj %d: Window with less than %d nodes does not exist.\n", iPivot,
p->nVars );
986 Hsh_VecManAdd(
p->pHash,
p->vAnds );
987 if ( nEntries == Hsh_VecSize(
p->pHash) )
989 if (
p->fVeryVerbose )
990 printf(
"Obj %d: This window was already tried.\n", iPivot );
994 if (
p->fVeryVerbose )
995 printf(
"\nObj = %6d : Leaf = %2d. AND = %2d. Root = %2d. LUT = %2d.\n",
996 iPivot, Vec_IntSize(
p->vLeaves), Vec_IntSize(
p->vAnds), Vec_IntSize(
p->vRoots), Vec_IntSize(
p->vNodes) );
998 if ( Vec_IntSize(
p->vLeaves) > 128 || Vec_IntSize(
p->vAnds) >
p->nVars )
1000 if (
p->fVeryVerbose )
1001 printf(
"Obj %d: Encountered window with %d inputs and %d internal nodes.\n", iPivot, Vec_IntSize(
p->vLeaves), Vec_IntSize(
p->vAnds) );
1005 if ( Vec_IntSize(
p->vAnds) < 10 )
1007 if (
p->fVeryVerbose )
1008 printf(
"Skipping.\n" );
1017 if (
p->fVeryVeryVerbose )
1018 printf(
"All clauses = %d. Multi clauses = %d. Binary clauses = %d. Other clauses = %d.\n\n",
1024 Vec_IntClear(
p->vAssump );
1025 Vec_IntPush(
p->vAssump, -1 );
1027 for ( i = Vec_IntSize(
p->vAnds); i < p->Power2; i++ )
1028 Vec_IntPush(
p->vAssump, Abc_Var2Lit(i, 1) );
1031 Vec_IntPush(
p->vAssump, Abc_Var2Lit(Root, 0) );
1034 StartSol = Vec_IntSize(
p->vSolInit) + 1;
1036 while ( fKeepTrying && StartSol-fKeepTrying > 0 )
1038 int Count = 0, LitCount = 0;
1039 int nConfBef, nConfAft;
1040 if (
p->fVeryVerbose )
1041 printf(
"Trying to find mapping with %d LUTs.\n", StartSol-fKeepTrying );
1044 Vec_IntWriteEntry(
p->vAssump, 0, Abc_Var2Lit(Vec_IntEntry(
p->vCardVars, StartSol-fKeepTrying), 1) );
1047 nConfBef = (int)
p->pSat->stats.conflicts;
1048 status =
sat_solver_solve(
p->pSat, Vec_IntArray(
p->vAssump), Vec_IntLimit(
p->vAssump),
p->nBTLimit, 0, 0, 0 );
1049 p->timeSat += Abc_Clock() - clk2;
1050 nConfAft = (int)
p->pSat->stats.conflicts;
1051 nConfTotal += nConfAft - nConfBef;
1055 p->timeSatSat += Abc_Clock() - clk2;
1057 p->timeSatUns += Abc_Clock() - clk2;
1059 p->timeSatUnd += Abc_Clock() - clk2;
1064 if (
p->fVeryVeryVerbose )
1066 for ( i = 0; i < Vec_IntSize(
p->vAnds); i++ )
1067 printf(
"%d", sat_solver_var_value(
p->pSat, i) );
1069 for ( i = 0; i < Vec_IntSize(
p->vAnds); i++ )
1070 if ( sat_solver_var_value(
p->pSat, i) )
1072 printf(
"%d=%d ", i, sat_solver_var_value(
p->pSat, i) );
1075 printf(
"Count = %d\n", Count );
1081 Vec_IntClear(
p->vSolCur );
1083 if ( sat_solver_var_value(
p->pSat, i) )
1085 if (
p->fVeryVeryVerbose )
1086 printf(
"Cut %3d : Node = %3d %6d ", Count++, Vec_IntEntry(
p->vCutsObj, i-
p->FirstVar), Vec_IntEntry(
p->vAnds, Vec_IntEntry(
p->vCutsObj, i-
p->FirstVar)) );
1087 if (
p->fVeryVeryVerbose )
1088 LitCount += Sbl_ManFindAndPrintCut(
p, i-
p->FirstVar );
1089 Vec_IntPush(
p->vSolCur, i-
p->FirstVar );
1104 if (
p->fVeryVerbose )
1106 printf(
"Critical path of length (%d) is detected: ", Vec_IntSize(
p->vPath) );
1108 printf(
"%d=%d ", i, Vec_IntEntry(
p->vAnds, Abc_Lit2Var(iLit)) );
1117 Vec_IntClear(
p->vSolBest );
1118 Vec_IntAppend(
p->vSolBest,
p->vSolCur );
1124 if (
p->fVeryVerbose )
1128 else if ( status ==
l_True )
1132 printf(
"confl =%8d. ", nConfAft - nConfBef );
1133 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk2 );
1136 printf(
"confl =%8d. ", nConfTotal );
1137 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk );
1138 if (
p->fVeryVeryVerbose && status ==
l_True )
1139 printf(
"LitCount = %d.\n", LitCount );
1151 if ( Vec_IntSize(
p->vSolBest) > 0 && Vec_IntSize(
p->vSolBest) < Vec_IntSize(
p->vSolInit) )
1153 int nDelayCur, nEdgesCur = 0;
1155 if (
p->pGia->vEdge1 )
1163 printf(
"Object %5d : Saved %2d nodes (Conf =%8d) Iter =%3d Delay = %d Edges = %4d\n",
1164 iPivot, Vec_IntSize(
p->vSolInit)-Vec_IntSize(
p->vSolBest), nConfTotal, nIters, nDelayCur, nEdgesCur );
1165 p->timeTotal += Abc_Clock() -
p->timeStart;
1173 p->timeTotal += Abc_Clock() -
p->timeStart;
1178 printf(
"Runtime breakdown:\n" );
1179 p->timeOther =
p->timeTotal -
p->timeWin -
p->timeCut -
p->timeSat -
p->timeTime;
1180 ABC_PRTP(
"Win ",
p->timeWin ,
p->timeTotal );
1181 ABC_PRTP(
"Cut ",
p->timeCut ,
p->timeTotal );
1182 ABC_PRTP(
"Sat ",
p->timeSat,
p->timeTotal );
1183 ABC_PRTP(
" Sat ",
p->timeSatSat,
p->timeTotal );
1184 ABC_PRTP(
" Unsat",
p->timeSatUns,
p->timeTotal );
1185 ABC_PRTP(
" Undec",
p->timeSatUnd,
p->timeTotal );
1186 ABC_PRTP(
"Timing",
p->timeTime ,
p->timeTotal );
1187 ABC_PRTP(
"Other ",
p->timeOther,
p->timeTotal );
1188 ABC_PRTP(
"ALL ",
p->timeTotal,
p->timeTotal );
1190void Gia_ManLutSat(
Gia_Man_t * pGia,
int LutSize,
int nNumber,
int nImproves,
int nBTLimit,
int DelayMax,
int nEdges,
int fDelay,
int fReverse,
int fVerbose,
int fVeryVerbose )
1192 int iLut, nImproveCount = 0;
1194 p->LutSize = LutSize;
1195 p->nBTLimit = nBTLimit;
1196 p->DelayMax = DelayMax;
1199 p->fReverse = fReverse;
1200 p->fVerbose = fVerbose | fVeryVerbose;
1201 p->fVeryVerbose = fVeryVerbose;
1203 printf(
"Parameters: WinSize = %d AIG nodes. Conf = %d. DelayMax = %d.\n",
p->nVars,
p->nBTLimit,
p->DelayMax );
1205 if ( fDelay && pGia->
vEdge1 &&
p->DelayMax == 0 )
1213 if ( ++nImproveCount == nImproves )
1218 printf(
"Tried = %d. Used = %d. HashWin = %d. SmallWin = %d. LargeWin = %d. IterOut = %d. SAT runs = %d.\n",
1219 p->nTried,
p->nImproved,
p->nHashWins,
p->nSmallWins,
p->nLargeWins,
p->nIterOuts,
p->nRuns );
1237Vec_Int_t *
Gia_RunKadical(
char * pFileNameIn,
char * pFileNameOut,
int Seed,
int nBTLimit,
int TimeOut,
int fVerbose,
int * pStatus )
1240 int fVerboseSolver = 0;
1241 abctime clkTotal = Abc_Clock();
1244 char * pKadical =
"kadical.exe";
1246 char * pKadical =
"./kadical";
1247 FILE * pFile = fopen( pKadical,
"rb" );
1248 if ( pFile == NULL )
1253 char Command[1000], * pCommand = (
char *)&Command;
1256 sprintf( pCommand,
"%s --seed=%d -c %d -t %d %s %s > %s", pKadical, Seed, nBTLimit, TimeOut, fVerboseSolver ?
"":
"-q", pFileNameIn, pFileNameOut );
1258 sprintf( pCommand,
"%s --seed=%d -c %d %s %s > %s", pKadical, Seed, nBTLimit, fVerboseSolver ?
"":
"-q", pFileNameIn, pFileNameOut );
1262 sprintf( pCommand,
"%s --seed=%d -t %d %s %s > %s", pKadical, Seed, TimeOut, fVerboseSolver ?
"":
"-q", pFileNameIn, pFileNameOut );
1264 sprintf( pCommand,
"%s --seed=%d %s %s > %s", pKadical, Seed, fVerboseSolver ?
"":
"-q", pFileNameIn, pFileNameOut );
1269 if (
system( pCommand ) == -1 )
1272 fprintf( stdout,
"Command \"%s\" did not succeed.\n", pCommand );
1279 printf(
"The problem has a solution. " ), *pStatus = 0;
1280 else if ( vRes == NULL && TimeOut == 0 )
1281 printf(
"The problem has no solution. " ), *pStatus = 1;
1282 else if ( vRes == NULL )
1283 printf(
"The problem has no solution or reached a resource limit after %d sec. ", TimeOut ), *pStatus = -1;
1284 Abc_PrintTime( 1,
"SAT solver time", Abc_Clock() - clkTotal );
1318 for (
int i = 0; i < nLits; i++ )
1319 Vec_StrPrintF( vStr,
"%d ", Abc_LitIsCompl(pLits[i]) ? -Abc_Lit2Var(pLits[i])-1 : Abc_Lit2Var(pLits[i])+1 );
1320 Vec_StrPrintF( vStr,
"0\n" );
1328 int i, nVars = nIns + 7*nAnds;
1329 Vec_StrPrintF( vStr,
"k %d ", nVars - nBound );
1331 for ( i = 0; i < nIns; i++ )
1334 for ( i = 0; i < 7*nAnds; i++ )
1335 Vec_StrPrintF( vStr,
"-%d ", (1+nIns)*7+i+1 );
1336 Vec_StrPrintF( vStr,
"0\n" );
1341 Vec_Str_t * vStr = Vec_StrAlloc( 10000 );
1343 int i, n, m, Id, pLits[4];
Gia_Obj_t * pObj;
1344 for ( n = 0; n < 7; n++ )
1348 for ( n = 0; n < 7; n++ )
if ( n != 1 )
1355 int fCompl[2] = { Gia_ObjFaninC0(pObj), Gia_ObjFaninC1(pObj) };
1356 int iFans[2] = { Gia_ObjFaninId0(pObj, i), Gia_ObjFaninId1(pObj, i) };
1357 Gia_Obj_t * pFans[2] = { Gia_ObjFanin0(pObj), Gia_ObjFanin1(pObj) };
1359 for ( n = 0; n < 2; n++ ) {
1392 for ( m = 0; m < 2; m++ )
1393 for ( n = 0; n < 2; n++ ) {
1401 if ( !fCompl[0] || !fCompl[1] )
1404 for ( n = 0; n < 2; n++ )
1405 if ( Gia_ObjIsCi(pFans[n]) )
1412 for ( m = 0; m < 2; m++ )
1413 for ( n = 0; n < 2; n++ ) {
1416 pLits[2] = Abc_Var2Lit(
Gia_SatVarReqPos(iFans[n]) + !(m ^ fCompl[n]), 0 );
1428 for ( m = 0; m < 2; m++ )
1429 for ( n = 0; n < 2; n++ )
1430 if ( Gia_ObjIsAnd(pFans[n]) ) {
1433 pLits[2] = Abc_Var2Lit(
Gia_SatVarReqPos(Gia_ObjFaninId0p(
p, pFans[n])) + !(m ^ fCompl[n] ^ Gia_ObjFaninC0(pFans[n])), 0 );
1435 pLits[2] = Abc_Var2Lit(
Gia_SatVarReqPos(Gia_ObjFaninId1p(
p, pFans[n])) + !(m ^ fCompl[n] ^ Gia_ObjFaninC1(pFans[n])), 0 );
1439 Vec_StrPush( vStr,
'\0' );
1461 Vec_Int_t * vMapping = Vec_IntStart( 2*Gia_ManObjNum(
p) );
1465 Vec_IntWriteEntry( vMapping, Abc_Var2Lit(Id, 1), -1 );
1472 Vec_IntWriteEntry( vMapping, Abc_Var2Lit(i,
Gia_SatValAckPos(vRes, i)), -1 );
1476 Gia_Obj_t * pFans[2] = { Gia_ObjFanin0(pObj), Gia_ObjFanin1(pObj) };
1477 Vec_IntWriteEntry( vMapping, Abc_Var2Lit(i, fComp), Vec_IntSize(vMapping) );
1478 if ( fFan0 && fFan1 ) {
1479 assert( Gia_ObjFaninC0(pObj) && Gia_ObjFaninC1(pObj) );
1480 Vec_IntPush( vMapping, 4 );
1481 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId0p(
p, pFans[0]), !(fComp ^ Gia_ObjFaninC0(pObj) ^ Gia_ObjFaninC0(pFans[0]))) );
1482 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId1p(
p, pFans[0]), !(fComp ^ Gia_ObjFaninC0(pObj) ^ Gia_ObjFaninC1(pFans[0]))) );
1483 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId0p(
p, pFans[1]), !(fComp ^ Gia_ObjFaninC1(pObj) ^ Gia_ObjFaninC0(pFans[1]))) );
1484 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId1p(
p, pFans[1]), !(fComp ^ Gia_ObjFaninC1(pObj) ^ Gia_ObjFaninC1(pFans[1]))) );
1486 }
else if ( fFan0 ) {
1487 Vec_IntPush( vMapping, 3 );
1488 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId0p(
p, pFans[0]), !(fComp ^ Gia_ObjFaninC0(pObj) ^ Gia_ObjFaninC0(pFans[0]))) );
1489 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId1p(
p, pFans[0]), !(fComp ^ Gia_ObjFaninC0(pObj) ^ Gia_ObjFaninC1(pFans[0]))) );
1490 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId1p(
p, pObj), !(fComp ^ Gia_ObjFaninC1(pObj))) );
1491 if ( Gia_ObjFaninC0(pObj) )
1495 }
else if ( fFan1 ) {
1496 Vec_IntPush( vMapping, 3 );
1497 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId0p(
p, pFans[1]), !(fComp ^ Gia_ObjFaninC1(pObj) ^ Gia_ObjFaninC0(pFans[1]))) );
1498 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId1p(
p, pFans[1]), !(fComp ^ Gia_ObjFaninC1(pObj) ^ Gia_ObjFaninC1(pFans[1]))) );
1499 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId0p(
p, pObj), !(fComp ^ Gia_ObjFaninC0(pObj))) );
1500 if ( Gia_ObjFaninC1(pObj) )
1505 Vec_IntPush( vMapping, 2 );
1506 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId0p(
p, pObj), !(fComp ^ Gia_ObjFaninC0(pObj))) );
1507 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId1p(
p, pObj), !(fComp ^ Gia_ObjFaninC1(pObj))) );
1515 int i, k, nObjs = Vec_IntSize(vRes)/7, nSteps = Abc_Base10Log(nObjs);
1516 int nCard = Vec_IntSum(vRes) - nIns;
char NumStr[10];
1517 printf(
"Solution with cardinality %d:\n", nCard );
1518 for ( k = 0; k < nSteps; k++ ) {
1520 for ( i = 0; i < nObjs; i++ ) {
1522 printf(
"%c", NumStr[k] );
1526 for ( k = 0; k < 7; k++ ) {
1527 printf(
"%c ",
"pnPNi01"[k] );
1528 for ( i = 0; i < nObjs; i++ )
1529 if ( Vec_IntEntry( vRes, i*7+k ) == 0 )
1538 FILE * pFile = fopen( pFileName,
"wb" );
1539 if ( pFile == NULL ) { printf(
"Cannot open input file \"%s\".\n", pFileName );
return 0; }
1540 fprintf( pFile,
"p knf %d %d\n%s\n", nVars, Vec_StrCountEntry(vStr,
'\n'), Vec_StrArray(vStr) );
1546 Vec_Str_t * vFileName = Vec_StrAlloc( 100 );
int c;
1547 Vec_StrPrintF( vFileName,
"%s", argv[0] + (argv[0][0] ==
'&') );
1548 for ( c = 1; c < argc; c++ )
1549 Vec_StrPrintF( vFileName,
"_%s", argv[c] + (argv[c][0] ==
'-') );
1550 Vec_StrPrintF( vFileName,
".cnf" );
1551 Vec_StrPush( vFileName,
'\0' );
1552 FILE * pFile = fopen( Vec_StrArray(vFileName),
"wb" );
1553 if ( pFile == NULL ) { printf(
"Cannot open output file \"%s\".\n", Vec_StrArray(vFileName) ); Vec_StrFree(vFileName);
return 0; }
1554 Vec_StrFree(vFileName);
1555 fprintf( pFile,
"c This file was generated by ABC command: \"" );
1556 fprintf( pFile,
"%s", argv[0] );
1557 for ( c = 1; c < argc; c++ )
1558 fprintf( pFile,
" %s", argv[c] );
1560 fprintf( pFile,
"c Cardinality CDCL (https://github.com/jreeves3/Cardinality-CDCL) found it to be " );
1562 fprintf( pFile,
"UNSAT" );
1564 fprintf( pFile,
"SAT" );
1566 fprintf( pFile,
"UNDECIDED" );
1567 fprintf( pFile,
" in %.2f sec\n", 1.0*((
double)(Time))/((
double)CLOCKS_PER_SEC) );
1568 fprintf( pFile,
"p knf %d %d\n%s\n", nVars, Vec_StrCountEntry(vStr,
'\n'), Vec_StrArray(vStr) );
1574 abctime clkStart = Abc_Clock();
1576 int Status, Rand = ((((unsigned)rand()) << 12) ^ ((unsigned)rand())) & 0xFFFFFF;
1577 char pFileNameI[32];
sprintf( pFileNameI,
"_%06x_.cnf", Rand );
1578 char pFileNameO[32];
sprintf( pFileNameO,
"_%06x_.out", Rand );
1580 nBound = 5 * Gia_ManAndNum(
p);
1582 int nVars = 7*(Gia_ManObjNum(
p)-Gia_ManCoNum(
p));
1584 Vec_StrFree( vStr );
1588 printf(
"SAT variables = %d. SAT clauses = %d. Cardinality bound = %d. Conflict limit = %d. Timeout = %d.\n",
1589 nVars, Vec_StrCountEntry(vStr,
'\n'), nBound, nBTLimit, nTimeout );
1591 unlink( pFileNameI );
1593 if ( fKeepFile )
Gia_ManDumpCnf2( vStr, nVars, argc, argv, Abc_Clock() - clkStart, Status );
1594 Vec_StrFree( vStr );
1597 Vec_IntFreeP( &
p->vCellMapping );
1598 assert(
p->vCellMapping == NULL );
1599 Vec_IntDrop( vRes, 0 );
1602 Vec_IntFree( vRes );
1603 if ( fVerbose ) Abc_PrintTime( 0,
"Total time", Abc_Clock() - clkStart );
1620#define KSAT_MINTS 64
1621#define KSAT_SPACE (4+3*KSAT_OBJS+3*KSAT_MINTS)
1649 for ( n = nIns; n < nIns+nNodes; n++ ) {
1655 for ( n = nIns; n < nIns+nNodes; n++ ) {
1656 for ( f = 0; f < 2; f++ )
1657 for ( k = 0; k < n; k++ )
1659 for ( k = n+1; k < nIns+nNodes; k++ )
1662 for ( m = 0; m < (1<<nIns); m++ ) {
1663 for ( n = 0; n < nIns; n++ )
1666 for ( n = nIns; n < nIns+nNodes; n++ )
1667 for ( k = 0; k < 3; k++ )
1668 if ( k || n < nIns+nNodes-1 )
1672 if ( pnVars ) *pnVars = nVars;
1679 for (
int k = 0; k < i; k++ )
1689 int i, k, Count = 0;
1690 for ( i = 0; pGuide[i]; i++ )
1691 Count += pGuide[i] -
'0';
1692 if ( Count != nNodes ) {
1693 printf(
"Guidance %s has %d nodes while the problem has %d nodes.\n", pGuide, Count, nNodes );
1697 int FirstThis = nIns;
1698 int FirstNext = FirstThis;
1699 vRes = Vec_IntStartFull( 2*nIns );
1700 for ( i = 0; pGuide[i]; i++ ) {
1701 FirstNext += pGuide[i] -
'0';
1702 for ( k = FirstThis; k < FirstNext; k++ )
1703 Vec_IntPushTwo( vRes, FirstPrev, FirstThis );
1704 FirstPrev = FirstThis;
1705 FirstThis = FirstNext;
1707 assert( Vec_IntSize(vRes) == 2*(nIns + nNodes) );
1717 Vec_Str_t * vStr = Vec_StrAlloc( 10000 );
1719 int i, j, m, n, f, c, a, Start, Stop, nLits = 0, pLits[256] = {0};
1725 for ( j = 0; j < Start; j++ )
1727 for ( f = 0; f < 2; f++ )
1728 for ( j = Stop; j < n; j++ )
1732 assert( n == nIns + nNodes );
1735 for ( n = nIns; n < nIns+nNodes; n++ )
1736 for ( f = 0; f < 2; f++ ) {
1739 for ( i = 0; i < n; i++ )
1740 pLits[nLits++] = Abc_Var2Lit(
Gia_KSatVarFan(pMap, n, f, i), 0 );
1750 Vec_StrPrintF( vStr,
"k %d ", n-1 );
1751 for ( i = 0; i < n; i++ )
1755 for ( n = nIns; n < nIns+nNodes; n++ ) {
1757 for ( i = 0; i < n; i++ ) {
1763 for ( i = 0; i < n; i++ )
1764 for ( j = i+1; j < n; j++ ) {
1775 for ( i = 0; i < n; i++ )
1776 for ( j = 0; j < i; j++ ) {
1782 for ( n = nIns; n < nIns+nNodes-1; n++ ) {
1784 for ( i = n+1; i < nIns+nNodes; i++ ) {
1785 for ( f = 0; f < 2; f++ ) {
1797 for ( i = n+1; i < nIns+nNodes; i++ )
1798 pLits[nLits++] = Abc_Var2Lit(
Gia_KSatVarFan(pMap, n, 2, i), 0 );
1803 for ( n = nIns; n < nIns+nNodes-1; n++ ) {
1804 for ( i = n+1; i < nIns+nNodes; i++ )
1805 for ( j = i+1; j < nIns+nNodes; j++ ) {
1816 if ( !fMultiLevel ) {
1818 for ( i = nIns; i < n; i++ )
1819 for ( f = 0; f < 2; f++ ) {
1859 for ( m = 0; m < (1 << nIns); m++ )
1860 for ( n = nIns; n < nIns+nNodes; n++ ) {
1861 for ( i = 0; i < n; i++ )
1862 for ( f = 0; f < 2; f++ )
1863 for ( c = 0; c < 2; c++ ) {
1869 for ( c = 0; c < 2; c++ )
1870 for ( a = 0; a < 2; a++ ) {
1872 for ( f = 0; f < 2; f++ ) {
1889 if ( nBound && 2*nNodes > nBound ) {
1890 Vec_StrPrintF( vStr,
"k %d ", 2*nNodes-nBound );
1892 for ( n = nIns; n < nIns+nNodes; n++ ) {
1898 Vec_StrPush( vStr,
'\0' );
1899 Vec_IntFreeP( &vRes );
1926 Vec_Int_t * vMapping = Vec_IntStart( 2*Gia_ManObjNum(
p) );
1929 if ( Vec_IntEntry(vRes, Id) )
1930 Vec_IntWriteEntry( vMapping, Abc_Var2Lit(Id, 1), -1 );
1932 assert( Vec_IntEntry(vRes, i) > 0 );
1933 if ( (Vec_IntEntry(vRes, i) & 2) == 0 ) {
1934 assert( (Vec_IntEntry(vRes, i) & 1) == 0 );
1937 Gia_Obj_t * pFans[2] = { Gia_ObjFanin0(pObj), Gia_ObjFanin1(pObj) };
1938 int fComp = ((Vec_IntEntry(vRes, i) >> 2) & 1) != 0;
1939 int fFan0 = ((Vec_IntEntry(vRes, Gia_ObjFaninId0(pObj, i)) >> 1) & 1) == 0 && Gia_ObjIsAnd(pFans[0]);
1940 int fFan1 = ((Vec_IntEntry(vRes, Gia_ObjFaninId1(pObj, i)) >> 1) & 1) == 0 && Gia_ObjIsAnd(pFans[1]);
1941 if ( Vec_IntEntry(vRes, i) & 1 )
1942 Vec_IntWriteEntry( vMapping, Abc_Var2Lit(i, !fComp), -1 );
1943 Vec_IntWriteEntry( vMapping, Abc_Var2Lit(i, fComp), Vec_IntSize(vMapping) );
1944 if ( fFan0 && fFan1 ) {
1945 Vec_IntPush( vMapping, 4 );
1946 if ( !Gia_ObjFaninC0(pObj) && Gia_ObjFaninC1(pObj) ) {
1947 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId0p(
p, pFans[1]), !(fComp ^ Gia_ObjFaninC1(pObj) ^ Gia_ObjFaninC0(pFans[1]))) );
1948 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId1p(
p, pFans[1]), !(fComp ^ Gia_ObjFaninC1(pObj) ^ Gia_ObjFaninC1(pFans[1]))) );
1949 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId0p(
p, pFans[0]), !(fComp ^ Gia_ObjFaninC0(pObj) ^ Gia_ObjFaninC0(pFans[0]))) );
1950 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId1p(
p, pFans[0]), !(fComp ^ Gia_ObjFaninC0(pObj) ^ Gia_ObjFaninC1(pFans[0]))) );
1953 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId0p(
p, pFans[0]), !(fComp ^ Gia_ObjFaninC0(pObj) ^ Gia_ObjFaninC0(pFans[0]))) );
1954 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId1p(
p, pFans[0]), !(fComp ^ Gia_ObjFaninC0(pObj) ^ Gia_ObjFaninC1(pFans[0]))) );
1955 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId0p(
p, pFans[1]), !(fComp ^ Gia_ObjFaninC1(pObj) ^ Gia_ObjFaninC0(pFans[1]))) );
1956 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId1p(
p, pFans[1]), !(fComp ^ Gia_ObjFaninC1(pObj) ^ Gia_ObjFaninC1(pFans[1]))) );
1958 if ( Gia_ObjFaninC0(pObj) && Gia_ObjFaninC1(pObj) )
1960 else if ( !Gia_ObjFaninC0(pObj) && !Gia_ObjFaninC1(pObj) )
1964 }
else if ( fFan0 ) {
1965 Vec_IntPush( vMapping, 3 );
1966 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId0p(
p, pFans[0]), !(fComp ^ Gia_ObjFaninC0(pObj) ^ Gia_ObjFaninC0(pFans[0]))) );
1967 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId1p(
p, pFans[0]), !(fComp ^ Gia_ObjFaninC0(pObj) ^ Gia_ObjFaninC1(pFans[0]))) );
1968 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId1p(
p, pObj), !(fComp ^ Gia_ObjFaninC1(pObj))) );
1969 if ( Gia_ObjFaninC0(pObj) )
1973 }
else if ( fFan1 ) {
1974 Vec_IntPush( vMapping, 3 );
1975 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId0p(
p, pFans[1]), !(fComp ^ Gia_ObjFaninC1(pObj) ^ Gia_ObjFaninC0(pFans[1]))) );
1976 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId1p(
p, pFans[1]), !(fComp ^ Gia_ObjFaninC1(pObj) ^ Gia_ObjFaninC1(pFans[1]))) );
1977 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId0p(
p, pObj), !(fComp ^ Gia_ObjFaninC0(pObj))) );
1978 if ( Gia_ObjFaninC1(pObj) )
1983 Vec_IntPush( vMapping, 2 );
1984 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId0p(
p, pObj), !(fComp ^ Gia_ObjFaninC0(pObj))) );
1985 Vec_IntPush( vMapping, Abc_Var2Lit(Gia_ObjFaninId1p(
p, pObj), !(fComp ^ Gia_ObjFaninC1(pObj))) );
1994 Vec_Int_t * vGuide = Vec_IntStart( 1000 );
1996 pNew->
pName = Abc_UtilStrsav(
"test" );
1997 int i, nSave = 0, pCopy[256] = {0};
1998 for ( i = 1; i <= nIns; i++ )
1999 pCopy[i] = Gia_ManAppendCi( pNew );
2000 for ( i = nIns; i < nIns+nNodes; i++ ) {
2003 if ( iFan0 == iFan1 )
2004 pCopy[i+1] = pCopy[iFan0+1];
2006 pCopy[i+1] = Gia_ManAppendAnd( pNew, pCopy[iFan0+1], pCopy[iFan1+1] );
2008 pCopy[i+1] = Gia_ManAppendOr( pNew, pCopy[iFan0+1], pCopy[iFan1+1] );
2009 pCopy[i+1] = Abc_LitNotCond( pCopy[i+1],
Gia_KSatValInv(pMap, i, vRes) );
2010 if ( iFan0 == iFan1 )
2011 *Vec_IntEntryP(vGuide, Abc_Lit2Var(pCopy[i+1])) ^= 1;
2013 *Vec_IntEntryP(vGuide, Abc_Lit2Var(pCopy[i+1])) ^= 4 | (2*
Gia_KSatValInv(pMap, i, vRes));
2015 *Vec_IntEntryP(vGuide, Abc_Lit2Var(pCopy[i+1])) ^= 8 | (2*
Gia_KSatValInv(pMap, i, vRes));
2017 if ( i == nIns+nNodes-1 )
2020 printf(
"%2d = ", i );
2021 if ( iFan0 == iFan1 )
2022 printf(
"INV( %d )\n", iFan0 );
2024 printf(
"%sAND( %d, %d )\n",
Gia_KSatValInv(pMap, i, vRes) ?
"N":
"", iFan0, iFan1 );
2026 printf(
"%sOR( %d, %d )\n",
Gia_KSatValInv(pMap, i, vRes) ?
"N":
"", iFan0, iFan1 );
2028 if ( i == nIns+nNodes-1 )
2029 printf(
"Solution cost = %d\n", 2*(2*nNodes - nSave) );
2032 Gia_ManAppendCo( pNew, pCopy[nIns+nNodes] );
2034 Vec_IntFree( vGuide );
2041 word pFuncs[256] = {0}, Const[2] = {0, ~(
word)0};
2042 assert( Gia_ManObjNum(
p) <= 256 );
2044 pFuncs[Id] = s_Truths6[i];
2046 pFuncs[i] = (Const[Gia_ObjFaninC0(pObj)] ^ pFuncs[Gia_ObjFaninId0(pObj, i)]) & (Const[Gia_ObjFaninC1(pObj)] ^ pFuncs[Gia_ObjFaninId1(pObj, i)]);
2047 pObj = Gia_ManCo(
p, 0);
2048 return Const[Gia_ObjFaninC0(pObj)] ^ pFuncs[Gia_ObjFaninId0p(
p, pObj)];
2051Gia_Man_t *
Gia_ManKSatMapping(
word Truth,
int nIns,
int nNodes,
int nBound,
int Seed,
int fMultiLevel,
int nBTLimit,
int nTimeout,
int fVerbose,
int fKeepFile,
int argc,
char ** argv,
char * pGuide )
2053 abctime clkStart = Abc_Clock();
2056 int Status, Rand = ((((unsigned)rand()) << 12) ^ ((unsigned)rand())) & 0xFFFFFF;
2057 char pFileNameI[32];
sprintf( pFileNameI,
"_%06x_.cnf", Rand );
2058 char pFileNameO[32];
sprintf( pFileNameO,
"_%06x_.out", Rand );
2059 int nVars = 0, * pMap =
Gia_KSatMapInit( nIns, nNodes, Truth, &nVars );
2062 Vec_StrFree( vStr );
2066 printf(
"Vars = %d. Nodes = %d. Cardinality bound = %d. SAT vars = %d. SAT clauses = %d. Conflict limit = %d. Timeout = %d.\n",
2067 nIns, nNodes, nBound, nVars, Vec_StrCountEntry(vStr,
'\n'), nBTLimit, nTimeout );
2069 unlink( pFileNameI );
2071 if ( fKeepFile )
Gia_ManDumpCnf2( vStr, nVars, argc, argv, Abc_Clock() - clkStart, Status );
2072 Vec_StrFree( vStr );
2075 Vec_IntDrop( vRes, 0 );
2077 printf(
"Verification %s. ", Truth ==
Gia_ManGetTruth(pNew) ?
"passed" :
"failed" );
2078 Abc_PrintTime( 0,
"Total time", Abc_Clock() - clkStart );
2079 Vec_IntFree( vRes );
#define ABC_FALLOC(type, num)
#define ABC_PRTP(a, t, T)
#define ABC_INFINITY
MACRO DEFINITIONS ///.
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
struct Vec_Str_t_ Vec_Str_t
Vec_Int_t * Exa4_ManParse(char *pFileName)
DECLARATIONS ///.
ABC_NAMESPACE_IMPL_START typedef signed char value
#define sat_solver_addclause
int Sbl_ManWindow2(Sbl_Man_t *p, int iPivot)
void Gia_KSatSetAnd(int *pMap, int i, int iVar)
int Gia_KSatValRef(int *pMap, int i, Vec_Int_t *vRes)
void Sbl_ManClean(Sbl_Man_t *p)
int Gia_KSatValAnd(int *pMap, int i, Vec_Int_t *vRes)
void Gia_ManSimplePrintMapping(Vec_Int_t *vRes, int nIns)
int Gia_SatVarFan0(int i)
typedefABC_NAMESPACE_IMPL_START struct Sbl_Man_t_ Sbl_Man_t
DECLARATIONS ///.
int Gia_KSatVarEqu(int *pMap, int i)
Vec_Str_t * Gia_ManSimpleCnf(Gia_Man_t *p, int nBound)
Vec_Int_t * Gia_ManDeriveSimpleMapping(Gia_Man_t *p, Vec_Int_t *vRes)
void Gia_SatDumpLiteral(Vec_Str_t *vStr, int Lit)
int Gia_KSatVarMin(int *pMap, int i, int m, int k)
int Gia_ManDumpCnf(char *pFileName, Vec_Str_t *vStr, int nVars)
int Gia_KSatFindFan(int *pMap, int i, int f, Vec_Int_t *vRes)
Gia_Man_t * Gia_ManKSatMapping(word Truth, int nIns, int nNodes, int nBound, int Seed, int fMultiLevel, int nBTLimit, int nTimeout, int fVerbose, int fKeepFile, int argc, char **argv, char *pGuide)
Sbl_Man_t * Sbl_ManAlloc(Gia_Man_t *pGia, int Number)
FUNCTION DEFINITIONS ///.
int Gia_KSatValMin(int *pMap, int i, int m, int k, Vec_Int_t *vRes)
Vec_Str_t * Gia_ManKSatCnf(int *pMap, int nIns, int nNodes, int nBound, int fMultiLevel, char *pGuide)
int Gia_SatVarFan1(int i)
int Sbl_ManComputeDelay(Sbl_Man_t *p, int iLut, Vec_Int_t *vFanins)
int Gia_SatValReqPos(Vec_Int_t *p, int i)
int Gia_SatValAckPos(Vec_Int_t *p, int i)
int Gia_SatValReqNeg(Vec_Int_t *p, int i)
int Gia_SatValFan0(Vec_Int_t *p, int i)
void Gia_KSatSetFan(int *pMap, int i, int f, int k, int iVar)
sat_solver * Sbm_AddCardinSolver(int LogN, Vec_Int_t **pvVars)
Vec_Int_t * Gia_ManKSatGenLevels(char *pGuide, int nIns, int nNodes)
word Gia_ManGetTruth(Gia_Man_t *p)
int Gia_KSatValInv(int *pMap, int i, Vec_Int_t *vRes)
int Gia_KSatValEqu(int *pMap, int i, Vec_Int_t *vRes)
void Gia_KSatSetInv(int *pMap, int i, int iVar)
Vec_Int_t * Gia_ManDeriveKSatMappingArray(Gia_Man_t *p, Vec_Int_t *vRes)
int Sbl_ManCreateCnf(Sbl_Man_t *p)
int Gia_SatVarAckPos(int i)
void Sbl_ManGetCurrentMapping(Sbl_Man_t *p)
void Gia_KSatSetEqu(int *pMap, int i, int iVar)
int Gia_KSatVarRef(int *pMap, int i)
Gia_Man_t * Gia_ManDeriveKSatMapping(Vec_Int_t *vRes, int *pMap, int nIns, int nNodes, int fVerbose)
int Gia_KSatVarFan(int *pMap, int i, int f, int k)
int Gia_KSatVarAnd(int *pMap, int i)
int Gia_SatVarReqNeg(int i)
int Gia_KSatVarInv(int *pMap, int i)
void Gia_SatDumpClause(Vec_Str_t *vStr, int *pLits, int nLits)
int Gia_SatValInv(Vec_Int_t *p, int i)
int Gia_SatVarAckNeg(int i)
void Gia_KSatSetRef(int *pMap, int i, int iVar)
int Sbl_ManTestSat(Sbl_Man_t *p, int iPivot)
void Sbl_ManUpdateMapping(Sbl_Man_t *p)
int Sbl_ManEvaluateMapping(Sbl_Man_t *p, int DelayGlo)
void Gia_SatDumpKlause(Vec_Str_t *vStr, int nIns, int nAnds, int nBound)
Vec_Int_t * Gia_RunKadical(char *pFileNameIn, char *pFileNameOut, int Seed, int nBTLimit, int TimeOut, int fVerbose, int *pStatus)
int Sbl_ManComputeCuts(Sbl_Man_t *p)
int Gia_SatVarReqPos(int i)
int Gia_ManSimpleMapping(Gia_Man_t *p, int nBound, int Seed, int nBTLimit, int nTimeout, int fVerbose, int fKeepFile, int argc, char **argv)
int Gia_ManDumpCnf2(Vec_Str_t *vStr, int nVars, int argc, char **argv, abctime Time, int Status)
int Sbl_ManEvaluateMappingEdge(Sbl_Man_t *p, int DelayGlo)
int Gia_SatValFan1(Vec_Int_t *p, int i)
void Sbl_ManStop(Sbl_Man_t *p)
int Gia_SatValAckNeg(Vec_Int_t *p, int i)
int Gia_KSatValFan(int *pMap, int i, int f, int k, Vec_Int_t *vRes)
int Sbl_ManCreateTiming(Sbl_Man_t *p, int DelayStart)
int Sbl_ManCriticalFanin(Sbl_Man_t *p, int iLut, Vec_Int_t *vFanins)
void Sbl_ManWindow(Sbl_Man_t *p)
int * Gia_KSatMapInit(int nIns, int nNodes, word Truth, int *pnVars)
void Gia_ManLutSat(Gia_Man_t *pGia, int LutSize, int nNumber, int nImproves, int nBTLimit, int DelayMax, int nEdges, int fDelay, int fReverse, int fVerbose, int fVeryVerbose)
void Sbl_ManPrintRuntime(Sbl_Man_t *p)
void Gia_KSatSetMin(int *pMap, int i, int m, int k, int iVar)
#define Gia_ManForEachLut2Reverse(p, i)
int Gia_ManEvalWindow(Gia_Man_t *p, Vec_Int_t *vLeaves, Vec_Int_t *vNodes, Vec_Wec_t *vWin, Vec_Int_t *vTemp, int fUseTwo)
#define Gia_ManForEachLut2(p, i)
#define Gia_ManForEachAnd(p, pObj, i)
int Gia_ManComputeOneWin(Gia_Man_t *p, int iPivot, Vec_Int_t **pvRoots, Vec_Int_t **pvNodes, Vec_Int_t **pvLeaves, Vec_Int_t **pvAnds)
#define Gia_ManForEachCoDriverId(p, DriverId, i)
#define Gia_ManForEachObjVecReverse(vVec, p, pObj, i)
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
struct Gia_Obj_t_ Gia_Obj_t
int Gia_ManEvalEdgeCount(Gia_Man_t *p)
void Gia_ManFillValue(Gia_Man_t *p)
struct Gia_Man_t_ Gia_Man_t
#define Gia_ManForEachObjVec(vVec, p, pObj, i)
void Gia_ManComputeOneWinStart(Gia_Man_t *p, int nAnds, int fReverse)
int Gia_ManEvalEdgeDelay(Gia_Man_t *p)
#define Gia_ManForEachCo(p, pObj, i)
Vec_Int_t * Gia_ManOrderWithBoxes(Gia_Man_t *p)
#define Gia_ManForEachAndId(p, i)
#define Gia_ManForEachCiId(p, Id, i)
unsigned __int64 word
DECLARATIONS ///.
int sat_solver_nclauses(sat_solver *s)
void sat_solver_setnvars(sat_solver *s, int n)
int sat_solver_nvars(sat_solver *s)
void sat_solver_rollback(sat_solver *s)
void sat_solver_delete(sat_solver *s)
void Tim_ManSetCoArrival(Tim_Man_t *p, int iCo, float Delay)
int Tim_ManBoxNum(Tim_Man_t *p)
typedefABC_NAMESPACE_HEADER_START struct Tim_Man_t_ Tim_Man_t
INCLUDES ///.
void Tim_ManIncrementTravId(Tim_Man_t *p)
DECLARATIONS ///.
void Tim_ManSetCiRequired(Tim_Man_t *p, int iCi, float Delay)
void Tim_ManInitPoRequiredAll(Tim_Man_t *p, float Delay)
float Tim_ManGetCiArrival(Tim_Man_t *p, int iCi)
float Tim_ManGetCoRequired(Tim_Man_t *p, int iCo)
struct Hsh_VecMan_t_ Hsh_VecMan_t
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
#define Vec_IntForEachEntryDoubleStart(vVec, Entry1, Entry2, i, Start)
#define Vec_WecForEachLevel(vGlob, vVec, i)
MACRO DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Wec_t_ Vec_Wec_t
INCLUDES ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.