86 int i, k = 0, nFuncs = Vec_WrdSize(vFuncs) /
nWords / 2;
88 for ( i = 0; i < nFuncs; i++ )
90 word * pFunc0 = Vec_WrdEntryP(vFuncs, (2*i+0)*
nWords);
91 word * pFunc1 = Vec_WrdEntryP(vFuncs, (2*i+1)*
nWords);
92 if ( Abc_TtIsConst0(pFunc0,
nWords) || Abc_TtIsConst0(pFunc1,
nWords) )
94 if ( k < i ) Abc_TtCopy( Vec_WrdEntryP(vFuncs, (2*k+0)*
nWords), pFunc0,
nWords, 0 );
95 if ( k < i ) Abc_TtCopy( Vec_WrdEntryP(vFuncs, (2*k+1)*
nWords), pFunc1,
nWords, 0 );
98 Vec_WrdShrink( vFuncs, 2*k*
nWords );
103 int Res = 0, i, nFuncs = Vec_WrdSize(vFuncs) /
nWords / 2;
105 for ( i = 0; i < nFuncs; i++ )
107 word * pFunc0 = Vec_WrdEntryP(vFuncs, (2*i+0)*
nWords);
108 word * pFunc1 = Vec_WrdEntryP(vFuncs, (2*i+1)*
nWords);
109 Res += Abc_TtCountOnesVec(pFunc0,
nWords) * Abc_TtCountOnesVec(pFunc1,
nWords);
112 assert( Res < (1 << 24) );
113 return (nFuncs << 24) | Res;
117 int Value, nFuncs, iSet = Hsh_VecManAdd(
p->pHash,
p->vTemp );
119 Vec_IntPush(
p->vSStarts, Vec_WrdSize(
p->vSFuncs) );
120 Vec_WrdAppend(
p->vSFuncs,
p->vIsfs );
122 assert( Vec_WrdSize(
p->vSFuncs) == 2 * nFuncs *
p->nWords );
124 Vec_IntPush(
p->vSCount, Value >> 24 );
125 Vec_IntPush(
p->vSPairs, Value & 0xFFFFFF );
141 int n, i, iObj,
nWords =
p->nWords;
142 int nDivWords = Abc_Bit6WordNum( Vec_IntSize(
p->vCands) );
144 for ( n = 0; n < 2; n++ )
146 p->vDivs[n] = Vec_WrdStart( 64*
nWords*nDivWords );
147 p->vPats[n] = Vec_WrdStart( 64*
nWords*nDivWords );
151 Abc_TtAndSharp( Vec_WrdEntryP(
p->vDivsC[n], i*
nWords), Vec_WrdEntryP(
p->vSimsC, iObj*
nWords), Vec_WrdEntryP(
p->vSims, iObj*
nWords),
nWords, !n );
154 Abc_TtCopy( Vec_WrdEntryP(
p->vDivs[n], i*
nWords), Vec_WrdEntryP(
p->vSims, iObj*
nWords),
nWords, !n );
163 p->nRounds = nRounds;
167 p->vWeights = vWeights;
173 p->vMatrix = Vec_PtrAlloc( 100 );
174 p->vMask = Vec_WrdAlloc( 100 );
175 p->vRowTemp = Vec_WrdStart( 64*
p->nDivWords );
176 p->vCosts = Vec_IntStart( Vec_IntSize(
p->vCands) );
177 p->pHash = Hsh_VecManStart( 1000 );
178 p->vSFuncs = Vec_WrdAlloc( 1000 );
179 p->vSStarts = Vec_IntAlloc( 1000 );
180 p->vSCount = Vec_IntAlloc( 1000 );
181 p->vSPairs = Vec_IntAlloc( 1000 );
182 p->vSolutions = Vec_WecStart( 16 );
183 p->vTemp = Vec_IntAlloc( 10 );
184 p->vTempSets = Vec_IntAlloc( 10 );
185 p->vTempPairs = Vec_IntAlloc( 10 );
191 assert( Vec_WrdSize(
p->vSims) %
p->nWords == 0 );
192 int n, nDivWords = Abc_Bit6WordNum( Vec_WrdSize(
p->vSims) /
p->nWords );
193 for ( n = 0; n < 2; n++ )
195 p->vDivs[n] = Vec_WrdStart( 64*
p->nWords*nDivWords );
196 p->vPats[n] = Vec_WrdStart( 64*
p->nWords*nDivWords );
197 Abc_TtCopy( Vec_WrdArray(
p->vDivs[n]), Vec_WrdArray(
p->vSims), Vec_WrdSize(
p->vSims), !n );
207 p->nRounds = nRounds;
210 p->vCands = Vec_IntStartNatural( Vec_WrdSize(vSims)/
nWords );
217 p->vMatrix = Vec_PtrAlloc( 100 );
218 p->vMask = Vec_WrdAlloc( 100 );
219 p->vRowTemp = Vec_WrdStart( 64*
p->nDivWords );
220 p->vCosts = Vec_IntStart( Vec_IntSize(
p->vCands) );
221 p->pHash = Hsh_VecManStart( 1000 );
222 p->vSFuncs = Vec_WrdAlloc( 1000 );
223 p->vSStarts = Vec_IntAlloc( 1000 );
224 p->vSCount = Vec_IntAlloc( 1000 );
225 p->vSPairs = Vec_IntAlloc( 1000 );
226 p->vSolutions = Vec_WecStart( 16 );
227 p->vTemp = Vec_IntAlloc( 10 );
228 p->vTempSets = Vec_IntAlloc( 10 );
229 p->vTempPairs = Vec_IntAlloc( 10 );
237 Vec_WrdFreeP( &vTemp );
238 Vec_PtrClear(
p->vMatrix );
243 Vec_WrdFreeP( &
p->vDivs[0] );
244 Vec_WrdFreeP( &
p->vDivs[1] );
245 Vec_WrdFreeP( &
p->vDivsC[0] );
246 Vec_WrdFreeP( &
p->vDivsC[1] );
247 Vec_WrdFreeP( &
p->vPats[0] );
248 Vec_WrdFreeP( &
p->vPats[1] );
249 Vec_PtrFreeP( &
p->vMatrix );
250 Vec_WrdFreeP( &
p->vMask );
251 Vec_WrdFreeP( &
p->vRowTemp );
252 Vec_IntFreeP( &
p->vCosts );
253 Hsh_VecManStop(
p->pHash );
254 Vec_WrdFreeP( &
p->vSFuncs );
255 Vec_IntFreeP( &
p->vSStarts );
256 Vec_IntFreeP( &
p->vSCount );
257 Vec_IntFreeP( &
p->vSPairs );
258 Vec_WecFreeP( &
p->vSolutions );
259 Vec_IntFreeP( &
p->vTemp );
260 Vec_IntFreeP( &
p->vTempSets );
261 Vec_IntFreeP( &
p->vTempPairs );
262 if (
p->vSims == NULL )
263 Vec_IntFreeP( &
p->vCands );
269 nMem += 2*(int)Vec_WrdMemory(
p->vDivs[0] );
270 nMem += 2*(int)Vec_WrdMemory(
p->vPats[0] );
271 nMem += (Vec_PtrSize(
p->vMatrix)+1)*(
int)Vec_WrdMemory(
p->vRowTemp );
272 nMem += (int)Vec_WrdMemory(
p->vMask );
273 nMem += (int)Vec_IntMemory(
p->vCosts );
274 nMem += (int)Hsh_VecManMemory(
p->pHash );
275 nMem += (int)Vec_WrdMemory(
p->vSFuncs );
276 nMem += (int)Vec_IntMemory(
p->vSStarts );
277 nMem += (int)Vec_IntMemory(
p->vSCount );
278 nMem += (int)Vec_IntMemory(
p->vSPairs );
279 nMem += (int)Vec_WecMemory(
p->vSolutions );
280 nMem += (int)Vec_IntMemory(
p->vTemp );
281 nMem += (int)Vec_IntMemory(
p->vTempSets );
282 nMem += (int)Vec_IntMemory(
p->vTempPairs );
299 int i, iObj, Cost = 0;
301 return Vec_IntSize(vRes);
303 Cost += Vec_IntEntry(vWeights, iObj);
312 return Vec_IntSize( Hsh_VecReadEntry(
p->pHash, iSet) );
316 return Vec_IntEntry(
p->vSCount, iSet);
320 return Vec_IntEntry(
p->vSPairs, iSet);
326 Vec_IntWriteEntry( vSet, i, Vec_IntEntry(vCands, iObj) );
336 printf(
"(%d)", iObj );
338 printf(
"(%d)", Vec_IntEntry(pGia->
vWeights, iObj) );
340 printf(
" %s ", Gia_ObjName(pGia, iObj)+2 );
342 printf(
" n%d ", iObj );
354 Vec_Int_t * vSet = Hsh_VecReadEntry(
p->pHash, iSet);
355 printf(
"Set %5d : ", iSet );
358 printf(
"Start %8d ", Vec_IntEntry(
p->vSStarts, iSet) );
360 Vec_IntClearAppend(
p->vTemp, vSet );
366 word * pSet = Vec_WrdEntryP(
p->vSims, Vec_IntEntry(
p->vCands, iObj)*
p->nWords );
367 word * pIsf;
int nFuncs = Vec_IntEntry(
p->vSCount, iSet);
368 int i, n, f, w, nFuncsNew = 0, Mark = Vec_WrdSize(
p->vSFuncs), Res = 0;
369 if ( Vec_WrdSize(
p->vSFuncs) + 4*nFuncs*
p->nWords > Vec_WrdCap(
p->vSFuncs) )
370 Vec_WrdGrow(
p->vSFuncs, 2*Vec_WrdCap(
p->vSFuncs) );
371 pIsf = Vec_WrdEntryP(
p->vSFuncs, Vec_IntEntry(
p->vSStarts, iSet) );
372 for ( i = 0; i < nFuncs; i++ )
374 word * pFunc[2] = { pIsf + (2*i+0)*
p->nWords, pIsf + (2*i+1)*
p->nWords };
375 for ( f = 0; f < 2; f++ )
377 int nOnes[2], Start = Vec_WrdSize(
p->vSFuncs);
378 for ( n = 0; n < 2; n++ )
380 word * pLimit = Vec_WrdLimit(
p->vSFuncs);
382 for ( w = 0; w <
p->nWords; w++ )
383 Vec_WrdPush(
p->vSFuncs, pFunc[n][w] & pSet[w] );
385 for ( w = 0; w <
p->nWords; w++ )
386 Vec_WrdPush(
p->vSFuncs, pFunc[n][w] & ~pSet[w] );
387 nOnes[n] = Abc_TtCountOnesVec( pLimit,
p->nWords );
389 if ( nOnes[0] && nOnes[1] )
390 Res += nOnes[0] * nOnes[1];
392 Vec_WrdShrink(
p->vSFuncs, Start );
395 assert( Res < (1 << 24) );
396 nFuncsNew = (Vec_WrdSize(
p->vSFuncs) - Mark)/2/
p->nWords;
397 assert( nFuncsNew < 128 );
398 assert( nFuncsNew >= 0 && nFuncsNew <= 2*nFuncs );
399 return (nFuncsNew << 24) | Res;
403 word * pDivs0 = Vec_WrdEntryP(
p->vDivs[0], iObj*
p->nWords );
404 word * pDivs1 = Vec_WrdEntryP(
p->vDivs[1], iObj*
p->nWords );
406 int i, f, w, nFuncsNew = 0, Mark = Vec_WrdSize(
p->vSFuncs), Res = 0;
407 if ( Vec_WrdSize(
p->vSFuncs) + 6*nFuncs*
p->nWords > Vec_WrdCap(
p->vSFuncs) )
408 Vec_WrdGrow(
p->vSFuncs, 2*Vec_WrdCap(
p->vSFuncs) );
409 if ( Vec_WrdSize(
p->vSFuncs) == Vec_IntEntry(
p->vSStarts, iSet) )
410 pIsf = Vec_WrdLimit(
p->vSFuncs );
412 pIsf = Vec_WrdEntryP(
p->vSFuncs, Vec_IntEntry(
p->vSStarts, iSet) );
413 for ( i = 0; i < nFuncs; i++ )
415 word * pFunc[2] = { pIsf + (2*i+0)*
p->nWords, pIsf + (2*i+1)*
p->nWords };
416 for ( f = 0; f < 3; f++ )
418 int nOnes[2], Start = Vec_WrdSize(
p->vSFuncs);
419 word * pLimit[2] = { Vec_WrdLimit(
p->vSFuncs), Vec_WrdLimit(
p->vSFuncs) +
p->nWords };
422 for ( w = 0; w <
p->nWords; w++ )
423 Vec_WrdPush(
p->vSFuncs, pFunc[0][w] & pDivs0[w] );
424 for ( w = 0; w <
p->nWords; w++ )
425 Vec_WrdPush(
p->vSFuncs, pFunc[1][w] & ~pDivs1[w] );
429 for ( w = 0; w <
p->nWords; w++ )
430 Vec_WrdPush(
p->vSFuncs, pFunc[0][w] & pDivs1[w] );
431 for ( w = 0; w <
p->nWords; w++ )
432 Vec_WrdPush(
p->vSFuncs, pFunc[1][w] & ~pDivs0[w] );
436 for ( w = 0; w <
p->nWords; w++ )
437 Vec_WrdPush(
p->vSFuncs, pFunc[0][w] & ~pDivs0[w] & ~pDivs1[w] );
438 for ( w = 0; w <
p->nWords; w++ )
439 Vec_WrdPush(
p->vSFuncs, pFunc[1][w] );
441 nOnes[0] = Abc_TtCountOnesVec( pLimit[0],
p->nWords );
442 nOnes[1] = Abc_TtCountOnesVec( pLimit[1],
p->nWords );
443 if ( nOnes[0] && nOnes[1] )
444 Res += nOnes[0] * nOnes[1];
446 Vec_WrdShrink(
p->vSFuncs, Start );
449 assert( Res < (1 << 24) );
450 nFuncsNew = (Vec_WrdSize(
p->vSFuncs) - Mark)/2/
p->nWords;
451 *pnFuncs = nFuncsNew;
456 int iSetNew, nEntries = Hsh_VecSize(
p->pHash );
457 Vec_Int_t * vSet = Hsh_VecReadEntry(
p->pHash, iSet );
458 Vec_IntClear(
p->vTemp );
459 Vec_IntAppend(
p->vTemp, vSet );
460 Vec_IntPushOrder(
p->vTemp, iObj );
461 assert( Vec_IntIsOrdered(
p->vTemp, 0) );
462 iSetNew = Hsh_VecManAdd(
p->pHash,
p->vTemp );
463 if ( iSetNew == nEntries )
466 Vec_IntPush(
p->vSStarts, Vec_WrdSize(
p->vSFuncs) );
468 Vec_IntPush(
p->vSCount, nFuncs );
469 Vec_IntPush(
p->vSPairs, nPairs );
470 assert( Hsh_VecSize(
p->pHash) == Vec_IntSize(
p->vSStarts) );
471 assert( Hsh_VecSize(
p->pHash) == Vec_IntSize(
p->vSCount) );
472 assert( Hsh_VecSize(
p->pHash) == Vec_IntSize(
p->vSPairs) );
495 int nFuncs = Vec_IntEntry(
p->vSCount, iSet);
496 int iFunc = Random % nFuncs;
497 word * pIsf = Vec_WrdEntryP(
p->vSFuncs, Vec_IntEntry(
p->vSStarts, iSet) );
498 word * pFunc[2] = { pIsf + (2*iFunc+0)*
p->nWords, pIsf + (2*iFunc+1)*
p->nWords };
499 int iBit0 = ((Random >> 16) & 1) ? Abc_TtFindFirstBit2(pFunc[0],
p->nWords) : Abc_TtFindLastBit2(pFunc[0],
p->nWords);
500 int iBit1 = ((Random >> 17) & 1) ? Abc_TtFindFirstBit2(pFunc[1],
p->nWords) : Abc_TtFindLastBit2(pFunc[1],
p->nWords);
503 Vec_Int_t * vSet = Hsh_VecReadEntry(
p->pHash, iSet );
int i, iObj;
506 word * pSet = Vec_WrdEntryP(
p->vSims, Vec_IntEntry(
p->vCands, iObj)*
p->nWords );
507 assert( Abc_TtGetBit(pSet, iBit0) == Abc_TtGetBit(pSet, iBit1) );
510 return (iBit0 << 16) | iBit1;
515 int nFuncs = Vec_IntEntry(
p->vSCount, iSet);
516 int iFunc = Random % nFuncs;
517 word * pIsf = Vec_WrdEntryP(
p->vSFuncs, Vec_IntEntry(
p->vSStarts, iSet) );
518 word * pFunc[2] = { pIsf + (2*iFunc+0)*
p->nWords, pIsf + (2*iFunc+1)*
p->nWords };
519 int iBit0 = ((Random >> 16) & 1) ? Abc_TtFindFirstBit2(pFunc[0],
p->nWords) : Abc_TtFindLastBit2(pFunc[0],
p->nWords);
520 int iBit1 = ((Random >> 17) & 1) ? Abc_TtFindFirstBit2(pFunc[1],
p->nWords) : Abc_TtFindLastBit2(pFunc[1],
p->nWords);
523 Vec_Int_t * vSet = Hsh_VecReadEntry(
p->pHash, iSet );
int i, iObj;
526 word * pSet0 = Vec_WrdEntryP(
p->vDivs[0], iObj*
p->nWords );
527 word * pSet1 = Vec_WrdEntryP(
p->vDivs[1], iObj*
p->nWords );
528 int Value00 = Abc_TtGetBit(pSet0, iBit0);
529 int Value01 = Abc_TtGetBit(pSet0, iBit1);
530 int Value10 = Abc_TtGetBit(pSet1, iBit0);
531 int Value11 = Abc_TtGetBit(pSet1, iBit1);
532 assert( !Value00 || !Value11 );
533 assert( !Value01 || !Value10 );
536 return (iBit0 << 16) | iBit1;
541 Vec_IntClear(
p->vTempPairs );
542 for ( i = 0; i < 64; i++ )
545 int iSet = Vec_IntEntry( vSets, Rand % Vec_IntSize(vSets) );
548 return p->vTempPairs;
553 assert( Vec_IntSize(vPairs) == 64 );
556 int iBit0 = Pair >> 16, iBit1 = Pair & 0xFFFF;
557 word * pPat00 = Vec_WrdEntryP(
p->vPats[0], iBit0*
p->nDivWords);
558 word * pPat01 = Vec_WrdEntryP(
p->vPats[0], iBit1*
p->nDivWords);
559 word * pPat10 = Vec_WrdEntryP(
p->vPats[1], iBit0*
p->nDivWords);
560 word * pPat11 = Vec_WrdEntryP(
p->vPats[1], iBit1*
p->nDivWords);
561 word * pPat = Vec_WrdEntryP(
p->vRowTemp, i*
p->nDivWords);
562 Abc_TtAnd( pPat, pPat00, pPat11,
p->nDivWords, 0 );
563 Abc_TtOrAnd( pPat, pPat01, pPat10,
p->nDivWords );
570 Vec_Wrd_t * vRow = Vec_WrdStart( 64*
p->nDivWords );
572 Vec_PtrPush(
p->vMatrix, vRow );
576 Vec_Int_t * vRes = Vec_IntAlloc( 100 );
int i;
577 for ( i = 0; i < 64*
nWords; i++ )
578 if ( Abc_TtGetBit(pSim, i) )
579 Vec_IntPush( vRes, i );
585 Vec_IntClear(
p->vTempPairs );
586 for ( i = 0; i < 64; i++ )
589 int iBit0 = Vec_IntEntry( vBits0, (Random & 0xFFF) % Vec_IntSize(vBits0) );
590 int iBit1 = Vec_IntEntry( vBits1, (Random >> 12) % Vec_IntSize(vBits1) );
591 Vec_IntPush(
p->vTempPairs, (iBit0 << 16) | iBit1 );
593 return p->vTempPairs;
600 for ( b = 0; b < nBatches; b++ )
603 Vec_Wrd_t * vRow = Vec_WrdStart( 64*
p->nDivWords );
605 Vec_PtrPush(
p->vMatrix, vRow );
607 Vec_IntFree( vBits0 );
608 Vec_IntFree( vBits1 );
612 int iDiv, iBit0 = Pair >> 16, iBit1 = Pair & 0xFFFF;
613 word * pPat00 = Vec_WrdEntryP(
p->vPats[0], iBit0*
p->nDivWords);
614 word * pPat01 = Vec_WrdEntryP(
p->vPats[0], iBit1*
p->nDivWords);
615 word * pPat10 = Vec_WrdEntryP(
p->vPats[1], iBit0*
p->nDivWords);
616 word * pPat11 = Vec_WrdEntryP(
p->vPats[1], iBit1*
p->nDivWords);
617 int iDiv1 = Abc_TtFindFirstAndBit2( pPat00, pPat11,
p->nDivWords );
618 int iDiv2 = Abc_TtFindFirstAndBit2( pPat01, pPat10,
p->nDivWords );
621 iDiv = Abc_MinInt( iDiv1, iDiv2 );
626 assert( iDiv >= 0 && iDiv < Vec_IntSize(
p->vCands) );
631 Vec_IntClear(
p->vTempSets );
640 Vec_IntPush(
p->vTempSets, iSet );
642 if ( Vec_IntSize(
p->vTempSets) < 2 )
650 for ( i = 0; i < nSize; i++ )
652 iSetNew =
Supp_ManSubsetAdd(
p, iSetNew, Vec_IntEntry(Hsh_VecReadEntry(
p->pHash, iSet), i), 0 );
659 Vec_IntRandomizeOrder( vPerm );
660 Vec_IntClear(
p->vTempSets );
662 printf(
"Removing items from %d:\n", iSet0 );
664 for ( i = 0; i < nSize; i++ )
666 int Index = Vec_IntEntry( vPerm, i );
669 printf(
"Item %2d : ", Index );
674 Vec_IntFree( vPerm );
677 Vec_IntPush(
p->vTempSets, iSet );
680 Vec_IntFree( vPerm );
686 word Sim, * pMask = Vec_WrdArray(
p->vMask);
687 assert( Vec_WrdSize(
p->vMask) == Vec_PtrSize(
p->vMatrix) );
688 Vec_IntFill(
p->vCosts, Vec_IntSize(
p->vCosts), 0 );
691 Vec_IntAddToEntry(
p->vCosts, k, Abc_TtCountOnes(Sim & pMask[r]) );
692 iDiv = Vec_IntArgMax(
p->vCosts );
694 printf(
"Choosing divisor %d with weight %d.\n", iDiv, Vec_IntEntry(
p->vCosts, iDiv) );
696 pMask[r] &= ~Vec_WrdEntry( vTemp, iDiv );
702 Vec_WrdFill(
p->vMask, Vec_PtrSize(
p->vMatrix), ~(
word)0 );
704 printf(
"\nBuilding a new set:\n" );
709 if ( Abc_TtIsConst0(Vec_WrdArray(
p->vMask), Vec_WrdSize(
p->vMask)) )
713 printf(
"Adding random part:\n" );
733 int i, k, nDivs = Vec_WrdSize(vDivs)/
nWords;
734 for ( i = 0; i < nDivs; i++ )
737 for ( k = 0; k < 64*
nWords; k++ )
738 fprintf( pFile,
"%c",
'0'+Abc_TtGetBit(pSim, k) );
739 fprintf( pFile,
"\n" );
744 int i, k, nDivs = Vec_WrdSize(vDivs[0])/
nWords;
745 for ( i = 0; i < nDivs; i++ )
747 word * pSim0 = Vec_WrdEntryP(vDivs[0], i*
nWords);
748 word * pSim1 = Vec_WrdEntryP(vDivs[1], i*
nWords);
749 for ( k = 0; k < 64*
nWords; k++ )
750 if ( Abc_TtGetBit(pSim0, k) )
751 fprintf( pFile,
"0" );
752 else if ( Abc_TtGetBit(pSim1, k) )
753 fprintf( pFile,
"1" );
755 fprintf( pFile,
"-" );
756 fprintf( pFile,
"\n" );
761 char Buffer[100];
int nDivs = Vec_WrdSize(vDivs)/
nWords;
763 FILE * pFile = fopen( Buffer,
"wb" );
765 printf(
"Cannot open output file.\n" );
766 fprintf( pFile,
"resyn %d %d %d %d\n", 0, nDivs, 1, 64*
nWords );
775 char Buffer[100];
int nDivs = Vec_WrdSize(vDivs[0])/
nWords;
777 FILE * pFile = fopen( Buffer,
"wb" );
779 printf(
"Cannot open output file.\n" );
780 fprintf( pFile,
"resyn %d %d %d %d\n", 0, nDivs, 1, 64*
nWords );
791 int i, iLit, iLitRes = -1, nSupp = Vec_IntSize(vSet);
792 FILE * pFile = fopen( Buffer,
"wb" );
794 printf(
"Cannot open output file.\n" );
795 fprintf( pFile,
"sol name aig %d\n", Vec_IntSize(vRes)/2 );
800 assert( iLit != 2 && iLit != 3 );
803 else if ( iLit-4 < 2*nSupp )
805 int iDiv = Vec_IntEntry(vSet, Abc_Lit2Var(iLit-4));
806 assert( iDiv >= 0 && iDiv < nDivs );
807 iLitRes = Abc_Var2Lit(1+iDiv, Abc_LitIsCompl(iLit));
810 iLitRes = iLit + 2*((nDivs+1)-(nSupp+2));
811 fprintf( pFile,
"%d ", iLitRes );
813 if ( Vec_IntSize(vRes) & 1 )
814 fprintf( pFile,
"%d ", iLitRes );
815 fprintf( pFile,
"\n" );
818 printf(
"Dumped solution info file \"%s\".\n", Buffer );
834 char Buffer[100];
int i, k, Temp, nDivs = Vec_WrdSize(vDivs)/
nWords;
836 FILE * pFile = fopen( Buffer,
"wb" );
838 printf(
"Cannot open output file.\n" );
840 fprintf( pFile,
".i %d\n", nDivs );
841 fprintf( pFile,
".o %d\n", 1 );
842 fprintf( pFile,
".p %d\n", 64*
nWords );
843 for ( i = 0; i < 64*
nWords; i++ ) {
844 for ( k = 0; k < nDivs; k++ )
845 fprintf( pFile,
"%d", Abc_TtGetBit(Vec_WrdEntryP(vDivs, k*
nWords), i) );
847 if ( Abc_TtGetBit(Vec_WrdEntryP(vIsfs, 0*
nWords), i) )
848 fprintf( pFile,
" 0\n" );
849 else if ( Abc_TtGetBit(Vec_WrdEntryP(vIsfs, 1*
nWords), i) )
850 fprintf( pFile,
" 1\n" );
852 fprintf( pFile,
" -\n" );
854 fprintf( pFile,
".e\n" );
856 fprintf( pFile,
"\n.s" );
858 fprintf( pFile,
" %d", Temp );
859 fprintf( pFile,
"\n.a" );
861 fprintf( pFile,
" %d", Temp );
862 fprintf( pFile,
"\n" );
882 int i, k, iSet, nFuncs = 0, Count = 0;
886 Count += Vec_IntSize(vLevel) > 0;
890 printf(
"%3d : ", nFuncs++ );
894 if ( CostBest > Cost )
902 if ( Count == 2 || k < Vec_IntSize(vLevel) )
905 if ( iSolBest > 0 && (CostBest >> 2) < 50 )
907 Vec_Int_t * vDivs2 = Vec_IntAlloc( 100 );
908 Vec_Int_t * vSet = Hsh_VecReadEntry(
p->pHash, iSolBest );
int i, iObj;
910 assert( !vRes || Vec_IntSize(vRes) == 2*(CostBest >> 2)+1 );
911 if ( vRes && pvDivs )
913 Vec_IntClear( *pvDivs );
914 Vec_IntPushTwo( *pvDivs, -1, -1 );
915 Vec_IntPushTwo( vDivs2, -1, -1 );
917 Vec_IntPush( *pvDivs, Vec_IntEntry(
p->vCands, iObj) );
918 Vec_IntPush( vDivs2, iObj );
925 Vec_IntFree( vDivs2 );
944 int i, iObj, iSet = 0;
948 Vec_IntDrop( vSet, 0 );
949 Vec_IntDrop( vSet, 0 );
967Vec_Int_t *
Supp_ManCompute(
Vec_Wrd_t * vIsfs,
Vec_Int_t * vCands,
Vec_Int_t * vWeights,
Vec_Wrd_t * vSims,
Vec_Wrd_t * vSimsC,
int nWords,
Gia_Man_t * pGia,
Vec_Int_t ** pvDivs,
int nIters,
int nRounds,
int fVerbose )
969 int fVeryVerbose = 0;
970 int i, r, iSet, iBest = -1;
981 Vec_IntClear( *pvDivs );
982 Vec_IntPushTwo( *pvDivs, -1, -1 );
983 vRes = Vec_IntAlloc( 1 );
984 Vec_IntPush( vRes, Abc_TtIsConst0(Vec_WrdArray(vIsfs),
nWords) );
988 printf(
"Using %d divisors with %d words. Problem has %d functions and %d minterm pairs.\n",
992 for ( i = 0; i <
p->nIters; i++ )
1000 for ( r = 0; r <
p->nRounds; r++ )
1003 printf(
"\n\nITER %d ROUND %d\n", i, r );
1009 printf(
"\nThe best solution found:\n" );
1021 printf(
"Matrix size %d.\n", Vec_PtrSize(
p->vMatrix) );
1026 printf(
"Explored %d divisor sets. Found %d solutions. Memory usage %.2f MB. ",
1027 Hsh_VecSize(
p->pHash), Vec_WecSizeSize(
p->vSolutions), 1.0*
Supp_ManMemory(
p)/(1<<20) );
1028 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk );
1029 printf(
"The best solution: " );
1031 printf(
"No solution.\n" );
1044 Vec_Wrd_t * vSimsPi = Vec_WrdStartTruthTables( Gia_ManCiNum(
p) );
1046 int i, iPoId,
nWords = Vec_WrdSize(vSimsPi) / Gia_ManCiNum(
p);
1052 for ( i = 0; i < Gia_ManCiNum(
p); i++ )
1053 Vec_IntPush( vCands, 1+i );
1055 iPoId = Gia_ObjId(
p, Gia_ManPo(
p, 0));
1056 Abc_TtCopy( Vec_WrdEntryP(vIsfs, 0*
nWords), Vec_WrdEntryP(vSims, iPoId*
nWords),
nWords, 1 );
1057 Abc_TtCopy( Vec_WrdEntryP(vIsfs, 1*
nWords), Vec_WrdEntryP(vSims, iPoId*
nWords),
nWords, 0 );
1059 vRes =
Supp_ManCompute( vIsfs, vCands, NULL, vSims, NULL,
nWords,
p, NULL, 1, 1, 0 );
1060 Vec_IntPrint( vRes );
1062 Vec_WrdFree( vSimsPi );
1063 Vec_WrdFree( vSims );
1064 Vec_WrdFree( vIsfs );
1065 Vec_IntFree( vCands );
1066 Vec_IntFree( vRes );
1082 FILE * pFile = fopen( pFileName,
"ab" );
1083 if ( pFile == NULL ) {
1084 printf(
"Cannot open file \"%s\" for writing.\n", pFileName );
1088 fprintf( pFile,
"\n.s" );
1090 fprintf( pFile,
" %d", Temp );
1091 fprintf( pFile,
"\n.a" );
1093 fprintf( pFile,
" %d", Temp-2 );
1094 fprintf( pFile,
"\n" );
1111 int i, nAddOn = 2, nIns = Vec_IntSize(vDivs)-2;
1112 int iLit0, iLit1, iTopLit = Vec_IntEntryLast(vRes);
1113 assert( Vec_IntSize(vRes) > 0 );
1114 assert( Vec_IntSize(vRes) % 2 == 1 );
1116 pNew->
pName = Abc_UtilStrsav(
"resub" );
1117 for ( i = 0; i < nIns; i++ )
1118 Gia_ManAppendCi(pNew);
1120 if ( iLit0 < iLit1 )
1121 Gia_ManAppendAnd( pNew, iLit0-nAddOn, iLit1-nAddOn );
1122 else if ( iLit0 > iLit1 )
1123 Gia_ManAppendXor( pNew, iLit0-nAddOn, iLit1-nAddOn );
1126 Gia_ManAppendCo(pNew, iTopLit-nAddOn);
1133 if (
p == NULL )
return NULL;
1135 Vec_Int_t * vDivs = Vec_IntAlloc( 100 );
1136 Vec_Int_t * vRes =
Supp_ManCompute(
p->vSimsOut, NULL, NULL,
p->vSimsIn, NULL,
p->nSimWords, NULL, &vDivs, nIters, nRounds, fVerbose );
1137 if ( fVerbose && vDivs ) printf(
"Divisors: " ), Vec_IntPrint( vDivs );
1138 if ( fVerbose && vRes ) printf(
"Solution: " ), Vec_IntPrint( vRes );
1140 if ( fWriteSol && vDivs && vRes )
1142 Vec_IntFreeP( &vRes );
1143 Vec_IntFreeP( &vDivs );
#define ABC_INFINITY
MACRO DEFINITIONS ///.
unsigned Abc_Random(int fReset)
#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 ///.
void Supp_DeriveDumpProb(Vec_Wrd_t *vIsfs, Vec_Wrd_t *vDivs, int nWords)
int Supp_ArrayWeight(Vec_Int_t *vRes, Vec_Int_t *vWeights)
int Supp_ManFuncInit(Vec_Wrd_t *vFuncs, int nWords)
FUNCTION DEFINITIONS ///.
void Supp_PrintNodes(Gia_Man_t *pGia, Vec_Int_t *vObjs, int Skip, int Limit)
int Supp_ManRandomSolution(Supp_Man_t *p, int iSet, int fVerbose)
Supp_Man_t * Supp_ManCreate2(Vec_Wrd_t *vIsfs, Vec_Wrd_t *vSims, Vec_Int_t *vWeights, int nWords, int nIters, int nRounds)
void Supp_ManAddPatterns(Supp_Man_t *p, Vec_Int_t *vSets)
int Supp_ManSubsetRemove(Supp_Man_t *p, int iSet, int iPos)
void Supp_ManRefine(Supp_Man_t *p, int iSet, int iObj, int *pnFuncs, int *pnPairs)
int Supp_SetPairNum(Supp_Man_t *p, int iSet)
int Supp_ComputePair1(Supp_Man_t *p, int iSet)
void Supp_SetConvert(Vec_Int_t *vSet, Vec_Int_t *vCands)
void Supp_RecordSolution(char *pFileName, Vec_Int_t *vDivs, Vec_Int_t *vRes)
int Supp_SetFuncNum(Supp_Man_t *p, int iSet)
Vec_Int_t * Supp_ManCollectOnes(word *pSim, int nWords)
void Supp_ManDelete(Supp_Man_t *p)
int Supp_ManCostInit(Vec_Wrd_t *vFuncs, int nWords)
int Supp_DeriveLines(Supp_Man_t *p)
void Supp_ManComputeTest(Gia_Man_t *p)
int Supp_ManMinimize(Supp_Man_t *p, int iSet0, int r, int fVerbose)
int Supp_ManMemory(Supp_Man_t *p)
Gia_Man_t * Supp_GenerateGia(Vec_Int_t *vRes, Vec_Int_t *vDivs)
void Supp_DeriveDumpProbC(Vec_Wrd_t *vIsfs, Vec_Wrd_t *vDivs[2], int nWords)
void Supp_ManInit(Supp_Man_t *p)
Vec_Int_t * Supp_ManCompute(Vec_Wrd_t *vIsfs, Vec_Int_t *vCands, Vec_Int_t *vWeights, Vec_Wrd_t *vSims, Vec_Wrd_t *vSimsC, int nWords, Gia_Man_t *pGia, Vec_Int_t **pvDivs, int nIters, int nRounds, int fVerbose)
void Supp_DeriveDumpProb2(Vec_Wrd_t *vIsfs, Vec_Wrd_t *vDivs, int nWords, Vec_Int_t *vSupp, Vec_Int_t *vRes)
void Supp_ManCleanMatrix(Supp_Man_t *p)
int Supp_ManReconstruct(Supp_Man_t *p, int fVerbose)
Vec_Int_t * Supp_ManFindBestSolution(Supp_Man_t *p, Vec_Wec_t *vSols, int fVerbose, Vec_Int_t **pvDivs)
void Supp_DeriveDumpSol(Vec_Int_t *vSet, Vec_Int_t *vRes, int nDivs)
Vec_Int_t * Supp_Compute64Pairs(Supp_Man_t *p, Vec_Int_t *vSets)
int Supp_ManRefine1(Supp_Man_t *p, int iSet, int iObj)
int Supp_DeriveLines2(Supp_Man_t *p)
typedefABC_NAMESPACE_IMPL_START struct Supp_Man_t_ Supp_Man_t
DECLARATIONS ///.
int Supp_SetWeight(Supp_Man_t *p, int iSet)
void Supp_ManAddPatternsFunc(Supp_Man_t *p, int nBatches)
int Supp_ComputePair(Supp_Man_t *p, int iSet)
int Supp_FindNextDiv(Supp_Man_t *p, int Pair)
Vec_Int_t * Supp_Compute64PairsFunc(Supp_Man_t *p, Vec_Int_t *vBits0, Vec_Int_t *vBits1)
void Supp_DeriveDumpSimsC(FILE *pFile, Vec_Wrd_t *vDivs[2], int nWords)
void Supp_DeriveDumpSims(FILE *pFile, Vec_Wrd_t *vDivs, int nWords)
Supp_Man_t * Supp_ManCreate(Vec_Wrd_t *vIsfs, Vec_Int_t *vCands, Vec_Int_t *vWeights, Vec_Wrd_t *vSims, Vec_Wrd_t *vSimsC, int nWords, Gia_Man_t *pGia, int nIters, int nRounds)
int Supp_FindGivenOne(Supp_Man_t *p)
int Supp_SetSize(Supp_Man_t *p, int iSet)
void Supp_PrintOne(Supp_Man_t *p, int iSet)
Gia_Man_t * Supp_ManSolveOne(char *pFileName, int nIters, int nRounds, int fWriteSol, int fVerbose)
int Supp_ManFindNextObj(Supp_Man_t *p, int fVerbose)
void Supp_ManFillBlock(Supp_Man_t *p, Vec_Int_t *vPairs, Vec_Wrd_t *vRes)
void Extra_BitMatrixTransposeP(Vec_Wrd_t *vSimsIn, int nWordsIn, Vec_Wrd_t *vSimsOut, int nWordsOut)
DECLARATIONS ///.
int Supp_ManSubsetAdd(Supp_Man_t *p, int iSet, int iObj, int fVerbose)
Vec_Wrd_t * Gia_ManSimPatSimOut(Gia_Man_t *pGia, Vec_Wrd_t *vSimsPi, int fOuts)
Vec_Int_t * Gia_ManDeriveSolutionOne(Gia_Man_t *p, Vec_Wrd_t *vSims, Vec_Wrd_t *vIsfs, Vec_Int_t *vCands, Vec_Int_t *vSet, int nWords, int Type)
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
struct Gia_Man_t_ Gia_Man_t
int Gia_ManEvalSolutionOne(Gia_Man_t *p, Vec_Wrd_t *vSims, Vec_Wrd_t *vIsfs, Vec_Int_t *vCands, Vec_Int_t *vSet, int nWords, int fVerbose)
typedefABC_NAMESPACE_HEADER_START struct Abc_RData_t_ Abc_RData_t
INCLUDES ///.
unsigned __int64 word
DECLARATIONS ///.
struct Hsh_VecMan_t_ Hsh_VecMan_t
#define Vec_IntForEachEntryDouble(vVec, Entry1, Entry2, i)
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
#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 ///.
#define Vec_WrdForEachEntryStop(vVec, Entry, i, Stop)