ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
giaSupps.c
Go to the documentation of this file.
1
20
21#include "aig/gia/gia.h"
22#include "base/main/mainInt.h"
23#include "base/io/ioResub.h"
24#include "misc/util/utilTruth.h"
25#include "misc/extra/extra.h"
26#include "misc/vec/vecHsh.h"
27
29
33
34typedef struct Supp_Man_t_ Supp_Man_t;
36{
37 // user data
38 int nIters; // optimization rounds
39 int nRounds; // optimization rounds
40 int nWords; // the number of simulation words
41 int nDivWords; // the number of divisor words
42 Vec_Wrd_t * vIsfs; // functions to synthesize
43 Vec_Int_t * vCands; // candidate divisors
44 Vec_Int_t * vWeights; // divisor weights (optional)
45 Vec_Wrd_t * vSims; // simulation values
46 Vec_Wrd_t * vSimsC; // simulation values
47 Gia_Man_t * pGia; // used for object names
48 // computed data
49 Vec_Wrd_t * vDivs[2]; // simulation values
50 Vec_Wrd_t * vDivsC[2]; // simulation values
51 Vec_Wrd_t * vPats[2]; // simulation values
52 Vec_Ptr_t * vMatrix; // simulation values
53 Vec_Wrd_t * vMask; // simulation values
54 Vec_Wrd_t * vRowTemp; // simulation values
55 Vec_Int_t * vCosts; // candidate costs
56 Hsh_VecMan_t * pHash; // subsets considered
57 Vec_Wrd_t * vSFuncs; // ISF storage
58 Vec_Int_t * vSStarts; // subset function starts
59 Vec_Int_t * vSCount; // subset function count
60 Vec_Int_t * vSPairs; // subset pair count
61 Vec_Int_t * vTemp; // temporary
62 Vec_Int_t * vTempSets; // temporary
63 Vec_Int_t * vTempPairs; // temporary
64 Vec_Wec_t * vSolutions; // solutions for each node count
65};
66
67extern void Extra_BitMatrixTransposeP( Vec_Wrd_t * vSimsIn, int nWordsIn, Vec_Wrd_t * vSimsOut, int nWordsOut );
68
72
84int Supp_ManFuncInit( Vec_Wrd_t * vFuncs, int nWords )
85{
86 int i, k = 0, nFuncs = Vec_WrdSize(vFuncs) / nWords / 2;
87 assert( 2 * nFuncs * nWords == Vec_WrdSize(vFuncs) );
88 for ( i = 0; i < nFuncs; i++ )
89 {
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) )
93 continue;
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 );
96 k++;
97 }
98 Vec_WrdShrink( vFuncs, 2*k*nWords );
99 return k;
100}
102{
103 int Res = 0, i, nFuncs = Vec_WrdSize(vFuncs) / nWords / 2;
104 assert( 2 * nFuncs * nWords == Vec_WrdSize(vFuncs) );
105 for ( i = 0; i < nFuncs; i++ )
106 {
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);
110 }
111 assert( nFuncs < 128 );
112 assert( Res < (1 << 24) );
113 return (nFuncs << 24) | Res;
114}
116{
117 int Value, nFuncs, iSet = Hsh_VecManAdd( p->pHash, p->vTemp ); // empty set
118 assert( iSet == 0 );
119 Vec_IntPush( p->vSStarts, Vec_WrdSize(p->vSFuncs) );
120 Vec_WrdAppend( p->vSFuncs, p->vIsfs );
121 nFuncs = Supp_ManFuncInit( p->vSFuncs, p->nWords );
122 assert( Vec_WrdSize(p->vSFuncs) == 2 * nFuncs * p->nWords );
123 Value = Supp_ManCostInit(p->vSFuncs, p->nWords);
124 Vec_IntPush( p->vSCount, Value >> 24 );
125 Vec_IntPush( p->vSPairs, Value & 0xFFFFFF );
126}
127
140{
141 int n, i, iObj, nWords = p->nWords;
142 int nDivWords = Abc_Bit6WordNum( Vec_IntSize(p->vCands) );
143 //Vec_IntPrint( p->vCands );
144 for ( n = 0; n < 2; n++ )
145 {
146 p->vDivs[n] = Vec_WrdStart( 64*nWords*nDivWords );
147 p->vPats[n] = Vec_WrdStart( 64*nWords*nDivWords );
148 //p->vDivsC[n] = Vec_WrdStart( 64*nWords*nDivWords );
149 if ( p->vSimsC )
150 Vec_IntForEachEntry( p->vCands, iObj, i )
151 Abc_TtAndSharp( Vec_WrdEntryP(p->vDivsC[n], i*nWords), Vec_WrdEntryP(p->vSimsC, iObj*nWords), Vec_WrdEntryP(p->vSims, iObj*nWords), nWords, !n );
152 else
153 Vec_IntForEachEntry( p->vCands, iObj, i )
154 Abc_TtCopy( Vec_WrdEntryP(p->vDivs[n], i*nWords), Vec_WrdEntryP(p->vSims, iObj*nWords), nWords, !n );
155 Extra_BitMatrixTransposeP( p->vDivs[n], nWords, p->vPats[n], nDivWords );
156 }
157 return nDivWords;
158}
159Supp_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 )
160{
162 p->nIters = nIters;
163 p->nRounds = nRounds;
164 p->nWords = nWords;
165 p->vIsfs = vIsfs;
166 p->vCands = vCands;
167 p->vWeights = vWeights;
168 p->vSims = vSims;
169 p->vSimsC = vSimsC;
170 p->pGia = pGia;
171 // computed data
172 p->nDivWords = Supp_DeriveLines( p );
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 );
186 Supp_ManInit( p );
187 return p;
188}
190{
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++ )
194 {
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 );
198 Extra_BitMatrixTransposeP( p->vDivs[n], p->nWords, p->vPats[n], nDivWords );
199 }
200 return nDivWords;
201}
202Supp_Man_t * Supp_ManCreate2( Vec_Wrd_t * vIsfs, Vec_Wrd_t * vSims, Vec_Int_t * vWeights, int nWords, int nIters, int nRounds )
203{
205 assert( Vec_WrdSize(vSims)%nWords == 0 );
206 p->nIters = nIters;
207 p->nRounds = nRounds;
208 p->nWords = nWords;
209 p->vIsfs = vIsfs;
210 p->vCands = Vec_IntStartNatural( Vec_WrdSize(vSims)/nWords );
211 p->vWeights = NULL;
212 p->vSims = vSims;
213 p->vSimsC = NULL;
214 p->pGia = NULL;
215 // computed data
216 p->nDivWords = Supp_DeriveLines2( p );
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 );
230 Supp_ManInit( p );
231 return p;
232}
234{
235 Vec_Wrd_t * vTemp; int i;
236 Vec_PtrForEachEntry( Vec_Wrd_t *, p->vMatrix, vTemp, i )
237 Vec_WrdFreeP( &vTemp );
238 Vec_PtrClear( p->vMatrix );
239}
241{
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 );
264 ABC_FREE( p );
265}
267{
268 int nMem = sizeof(Supp_Man_t);
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 );
283 return nMem;
284}
285
297int Supp_ArrayWeight( Vec_Int_t * vRes, Vec_Int_t * vWeights )
298{
299 int i, iObj, Cost = 0;
300 if ( !vWeights )
301 return Vec_IntSize(vRes);
302 Vec_IntForEachEntry( vRes, iObj, i )
303 Cost += Vec_IntEntry(vWeights, iObj);
304 return Cost;
305}
306int Supp_SetWeight( Supp_Man_t * p, int iSet )
307{
308 return Supp_ArrayWeight( Hsh_VecReadEntry(p->pHash, iSet), p->vWeights );
309}
310int Supp_SetSize( Supp_Man_t * p, int iSet )
311{
312 return Vec_IntSize( Hsh_VecReadEntry(p->pHash, iSet) );
313}
314int Supp_SetFuncNum( Supp_Man_t * p, int iSet )
315{
316 return Vec_IntEntry(p->vSCount, iSet);
317}
318int Supp_SetPairNum( Supp_Man_t * p, int iSet )
319{
320 return Vec_IntEntry(p->vSPairs, iSet);
321}
322void Supp_SetConvert( Vec_Int_t * vSet, Vec_Int_t * vCands )
323{
324 int i, iObj;
325 Vec_IntForEachEntry( vSet, iObj, i )
326 Vec_IntWriteEntry( vSet, i, Vec_IntEntry(vCands, iObj) );
327}
328void Supp_PrintNodes( Gia_Man_t * pGia, Vec_Int_t * vObjs, int Skip, int Limit )
329{
330 int i, iObj;
331 //printf( "Considering %d targets: ", Vec_IntSize(vObjs) );
332 Vec_IntForEachEntryStart( vObjs, iObj, i, Skip )
333 {
334 if ( iObj < 0 )
335 continue;
336 printf( "(%d)", iObj );
337 if ( pGia && pGia->vWeights && Vec_IntEntry(pGia->vWeights, iObj) > 0 )
338 printf( "(%d)", Vec_IntEntry(pGia->vWeights, iObj) );
339 if ( pGia )
340 printf( " %s ", Gia_ObjName(pGia, iObj)+2 );
341 else
342 printf( " n%d ", iObj );
343 if ( i >= Limit )
344 {
345 printf( "... " );
346 break;
347 }
348 }
349 printf( "Cost = %d", Supp_ArrayWeight(vObjs, pGia ? pGia->vWeights : NULL) );
350 printf( "\n" );
351}
352void Supp_PrintOne( Supp_Man_t * p, int iSet )
353{
354 Vec_Int_t * vSet = Hsh_VecReadEntry(p->pHash, iSet);
355 printf( "Set %5d : ", iSet );
356 printf( "Funcs %2d ", Supp_SetFuncNum(p, iSet) );
357 printf( "Pairs %4d ", Supp_SetPairNum(p, iSet) );
358 printf( "Start %8d ", Vec_IntEntry(p->vSStarts, iSet) );
359 printf( "Weight %4d ", Supp_ArrayWeight(vSet, p->vWeights) );
360 Vec_IntClearAppend( p->vTemp, vSet );
361 Supp_SetConvert( p->vTemp, p->vCands );
362 Supp_PrintNodes( p->pGia, p->vTemp, 0, 6 );
363}
364int Supp_ManRefine1( Supp_Man_t * p, int iSet, int iObj )
365{
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++ )
373 {
374 word * pFunc[2] = { pIsf + (2*i+0)*p->nWords, pIsf + (2*i+1)*p->nWords };
375 for ( f = 0; f < 2; f++ )
376 {
377 int nOnes[2], Start = Vec_WrdSize(p->vSFuncs);
378 for ( n = 0; n < 2; n++ )
379 {
380 word * pLimit = Vec_WrdLimit(p->vSFuncs);
381 if ( f )
382 for ( w = 0; w < p->nWords; w++ )
383 Vec_WrdPush( p->vSFuncs, pFunc[n][w] & pSet[w] );
384 else
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 );
388 }
389 if ( nOnes[0] && nOnes[1] )
390 Res += nOnes[0] * nOnes[1];
391 else
392 Vec_WrdShrink( p->vSFuncs, Start );
393 }
394 }
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;
400}
401void Supp_ManRefine( Supp_Man_t * p, int iSet, int iObj, int * pnFuncs, int * pnPairs )
402{
403 word * pDivs0 = Vec_WrdEntryP( p->vDivs[0], iObj*p->nWords );
404 word * pDivs1 = Vec_WrdEntryP( p->vDivs[1], iObj*p->nWords );
405 word * pIsf; int nFuncs = Supp_SetFuncNum(p, iSet);
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 );
411 else
412 pIsf = Vec_WrdEntryP( p->vSFuncs, Vec_IntEntry(p->vSStarts, iSet) );
413 for ( i = 0; i < nFuncs; i++ )
414 {
415 word * pFunc[2] = { pIsf + (2*i+0)*p->nWords, pIsf + (2*i+1)*p->nWords };
416 for ( f = 0; f < 3; f++ )
417 {
418 int nOnes[2], Start = Vec_WrdSize(p->vSFuncs);
419 word * pLimit[2] = { Vec_WrdLimit(p->vSFuncs), Vec_WrdLimit(p->vSFuncs) + p->nWords };
420 if ( f == 0 )
421 {
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] );
426 }
427 else if ( f == 1 )
428 {
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] );
433 }
434 else
435 {
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] );
440 }
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];
445 else
446 Vec_WrdShrink( p->vSFuncs, Start );
447 }
448 }
449 assert( Res < (1 << 24) );
450 nFuncsNew = (Vec_WrdSize(p->vSFuncs) - Mark)/2/p->nWords;
451 *pnFuncs = nFuncsNew;
452 *pnPairs = Res;
453}
454int Supp_ManSubsetAdd( Supp_Man_t * p, int iSet, int iObj, int fVerbose )
455{
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 ) // new entry
464 {
465 int nFuncs, nPairs;
466 Vec_IntPush( p->vSStarts, Vec_WrdSize(p->vSFuncs) );
467 Supp_ManRefine( p, iSet, iObj, &nFuncs, &nPairs );
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) );
473 if ( Supp_SetFuncNum(p, iSetNew) == 0 && Supp_SetSize(p, iSetNew) < Vec_WecSize(p->vSolutions) )
474 Vec_WecPush( p->vSolutions, Supp_SetSize(p, iSetNew), iSetNew );
475 if ( fVerbose )
476 Supp_PrintOne( p, iSetNew );
477 }
478 return iSetNew;
479}
480
493{
494 int Random = 0xFFFFFF & Abc_Random(0);
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);
501 if ( 1 )
502 {
503 Vec_Int_t * vSet = Hsh_VecReadEntry( p->pHash, iSet ); int i, iObj;
504 Vec_IntForEachEntry( vSet, iObj, i )
505 {
506 word * pSet = Vec_WrdEntryP( p->vSims, Vec_IntEntry(p->vCands, iObj)*p->nWords );
507 assert( Abc_TtGetBit(pSet, iBit0) == Abc_TtGetBit(pSet, iBit1) );
508 }
509 }
510 return (iBit0 << 16) | iBit1;
511}
512int Supp_ComputePair( Supp_Man_t * p, int iSet )
513{
514 int Random = 0xFFFFFF & Abc_Random(0);
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);
521 if ( 1 )
522 {
523 Vec_Int_t * vSet = Hsh_VecReadEntry( p->pHash, iSet ); int i, iObj;
524 Vec_IntForEachEntry( vSet, iObj, i )
525 {
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 );
534 }
535 }
536 return (iBit0 << 16) | iBit1;
537}
539{
540 int i;
541 Vec_IntClear( p->vTempPairs );
542 for ( i = 0; i < 64; i++ )
543 {
544 int Rand = 0xFFFFFF & Abc_Random(0);
545 int iSet = Vec_IntEntry( vSets, Rand % Vec_IntSize(vSets) );
546 Vec_IntPush( p->vTempPairs, Supp_ComputePair(p, iSet) );
547 }
548 return p->vTempPairs;
549}
551{
552 int i, Pair;
553 assert( Vec_IntSize(vPairs) == 64 );
554 Vec_IntForEachEntry( vPairs, Pair, i )
555 {
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 );
564 }
565 Extra_BitMatrixTransposeP( p->vRowTemp, p->nDivWords, vRes, 1 );
566}
568{
569 Vec_Int_t * vPairs = Supp_Compute64Pairs( p, vSets );
570 Vec_Wrd_t * vRow = Vec_WrdStart( 64*p->nDivWords );
571 Supp_ManFillBlock( p, vPairs, vRow );
572 Vec_PtrPush( p->vMatrix, vRow );
573}
575{
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 );
580 return vRes;
581}
583{
584 int i;
585 Vec_IntClear( p->vTempPairs );
586 for ( i = 0; i < 64; i++ )
587 {
588 int Random = 0xFFFFFF & Abc_Random(0);
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 );
592 }
593 return p->vTempPairs;
594}
595void Supp_ManAddPatternsFunc( Supp_Man_t * p, int nBatches )
596{
597 int b;
598 Vec_Int_t * vBits0 = Supp_ManCollectOnes( Vec_WrdEntryP(p->vSFuncs, 0*p->nWords), p->nWords );
599 Vec_Int_t * vBits1 = Supp_ManCollectOnes( Vec_WrdEntryP(p->vSFuncs, 1*p->nWords), p->nWords );
600 for ( b = 0; b < nBatches; b++ )
601 {
602 Vec_Int_t * vPairs = Supp_Compute64PairsFunc( p, vBits0, vBits1 );
603 Vec_Wrd_t * vRow = Vec_WrdStart( 64*p->nDivWords );
604 Supp_ManFillBlock( p, vPairs, vRow );
605 Vec_PtrPush( p->vMatrix, vRow );
606 }
607 Vec_IntFree( vBits0 );
608 Vec_IntFree( vBits1 );
609}
610int Supp_FindNextDiv( Supp_Man_t * p, int Pair )
611{
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 );
619 iDiv1 = iDiv1 == -1 ? ABC_INFINITY : iDiv1;
620 iDiv2 = iDiv2 == -1 ? ABC_INFINITY : iDiv2;
621 iDiv = Abc_MinInt( iDiv1, iDiv2 );
622 // return -1 if the pair cannot be distinguished by any divisor
623 // in this case the original resub problem has no solution
624 if ( iDiv == ABC_INFINITY )
625 return -1;
626 assert( iDiv >= 0 && iDiv < Vec_IntSize(p->vCands) );
627 return iDiv;
628}
629int Supp_ManRandomSolution( Supp_Man_t * p, int iSet, int fVerbose )
630{
631 Vec_IntClear( p->vTempSets );
632 while ( Supp_SetFuncNum(p, iSet) > 0 )
633 {
634 int Pair = Supp_ComputePair( p, iSet );
635 int iDiv = Supp_FindNextDiv( p, Pair );
636 if ( iDiv == -1 )
637 return -1;
638 iSet = Supp_ManSubsetAdd( p, iSet, iDiv, fVerbose );
639 if ( Supp_SetFuncNum(p, iSet) > 0 )
640 Vec_IntPush( p->vTempSets, iSet );
641 }
642 if ( Vec_IntSize(p->vTempSets) < 2 )
643 return iSet;
644 Supp_ManAddPatterns( p, p->vTempSets );
645 return iSet;
646}
647int Supp_ManSubsetRemove( Supp_Man_t * p, int iSet, int iPos )
648{
649 int i, iSetNew = 0, nSize = Supp_SetSize(p, iSet);
650 for ( i = 0; i < nSize; i++ )
651 if ( i != iPos && Supp_SetFuncNum(p, iSetNew) > 0 )
652 iSetNew = Supp_ManSubsetAdd( p, iSetNew, Vec_IntEntry(Hsh_VecReadEntry(p->pHash, iSet), i), 0 );
653 return iSetNew;
654}
655int Supp_ManMinimize( Supp_Man_t * p, int iSet0, int r, int fVerbose )
656{
657 int i, nSize = Supp_SetSize(p, iSet0);
658 Vec_Int_t * vPerm = Vec_IntStartNatural( Supp_SetSize(p, iSet0) );
659 Vec_IntRandomizeOrder( vPerm );
660 Vec_IntClear( p->vTempSets );
661 if ( fVerbose )
662 printf( "Removing items from %d:\n", iSet0 );
663 // make sure we first try to remove items with higher weight
664 for ( i = 0; i < nSize; i++ )
665 {
666 int Index = Vec_IntEntry( vPerm, i );
667 int iSet = Supp_ManSubsetRemove( p, iSet0, Index );
668 if ( fVerbose )
669 printf( "Item %2d : ", Index );
670 if ( fVerbose )
671 Supp_PrintOne( p, iSet );
672 if ( Supp_SetFuncNum(p, iSet) == 0 )
673 {
674 Vec_IntFree( vPerm );
675 return Supp_ManMinimize( p, iSet, r, fVerbose );
676 }
677 Vec_IntPush( p->vTempSets, iSet );
678 }
679 Supp_ManAddPatterns( p, p->vTempSets );
680 Vec_IntFree( vPerm );
681 return iSet0;
682}
683int Supp_ManFindNextObj( Supp_Man_t * p, int fVerbose )
684{
685 Vec_Wrd_t * vTemp; int r, k, iDiv;
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 );
689 Vec_PtrForEachEntry( Vec_Wrd_t *, p->vMatrix, vTemp, r )
690 Vec_WrdForEachEntryStop( vTemp, Sim, k, Vec_IntSize(p->vCosts) )
691 Vec_IntAddToEntry( p->vCosts, k, Abc_TtCountOnes(Sim & pMask[r]) );
692 iDiv = Vec_IntArgMax( p->vCosts );
693 if ( fVerbose )
694 printf( "Choosing divisor %d with weight %d.\n", iDiv, Vec_IntEntry(p->vCosts, iDiv) );
695 Vec_PtrForEachEntry( Vec_Wrd_t *, p->vMatrix, vTemp, r )
696 pMask[r] &= ~Vec_WrdEntry( vTemp, iDiv );
697 return iDiv;
698}
699int Supp_ManReconstruct( Supp_Man_t * p, int fVerbose )
700{
701 int iSet = 0;
702 Vec_WrdFill( p->vMask, Vec_PtrSize(p->vMatrix), ~(word)0 );
703 if ( fVerbose )
704 printf( "\nBuilding a new set:\n" );
705 while ( Supp_SetPairNum(p, iSet) )
706 {
707 int iDiv = Supp_ManFindNextObj( p, fVerbose );
708 iSet = Supp_ManSubsetAdd( p, iSet, iDiv, fVerbose );
709 if ( Abc_TtIsConst0(Vec_WrdArray(p->vMask), Vec_WrdSize(p->vMask)) )
710 break;
711 }
712 if ( fVerbose )
713 printf( "Adding random part:\n" );
714 return Supp_ManRandomSolution( p, iSet, fVerbose );
715}
716
717
729static int s_Counter = 0;
730
731void Supp_DeriveDumpSims( FILE * pFile, Vec_Wrd_t * vDivs, int nWords )
732{
733 int i, k, nDivs = Vec_WrdSize(vDivs)/nWords;
734 for ( i = 0; i < nDivs; i++ )
735 {
736 word * pSim = Vec_WrdEntryP(vDivs, i*nWords);
737 for ( k = 0; k < 64*nWords; k++ )
738 fprintf( pFile, "%c", '0'+Abc_TtGetBit(pSim, k) );
739 fprintf( pFile, "\n" );
740 }
741}
742void Supp_DeriveDumpSimsC( FILE * pFile, Vec_Wrd_t * vDivs[2], int nWords )
743{
744 int i, k, nDivs = Vec_WrdSize(vDivs[0])/nWords;
745 for ( i = 0; i < nDivs; i++ )
746 {
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" );
754 else
755 fprintf( pFile, "-" );
756 fprintf( pFile, "\n" );
757 }
758}
759void Supp_DeriveDumpProb( Vec_Wrd_t * vIsfs, Vec_Wrd_t * vDivs, int nWords )
760{
761 char Buffer[100]; int nDivs = Vec_WrdSize(vDivs)/nWords;
762 int RetValue = sprintf( Buffer, "%02d.resub", s_Counter );
763 FILE * pFile = fopen( Buffer, "wb" );
764 if ( pFile == NULL )
765 printf( "Cannot open output file.\n" );
766 fprintf( pFile, "resyn %d %d %d %d\n", 0, nDivs, 1, 64*nWords );
767 //fprintf( pFile, "%d %d %d %d\n", 0, nDivs, 1, 64*nWords );
768 Supp_DeriveDumpSims( pFile, vDivs, nWords );
769 Supp_DeriveDumpSims( pFile, vIsfs, nWords );
770 fclose ( pFile );
771 RetValue = 0;
772}
773void Supp_DeriveDumpProbC( Vec_Wrd_t * vIsfs, Vec_Wrd_t * vDivs[2], int nWords )
774{
775 char Buffer[100]; int nDivs = Vec_WrdSize(vDivs[0])/nWords;
776 int RetValue = sprintf( Buffer, "%02d.resub", s_Counter );
777 FILE * pFile = fopen( Buffer, "wb" );
778 if ( pFile == NULL )
779 printf( "Cannot open output file.\n" );
780 fprintf( pFile, "resyn %d %d %d %d\n", 0, nDivs, 1, 64*nWords );
781 //fprintf( pFile, "%d %d %d %d\n", 0, nDivs, 1, 64*nWords );
782 Supp_DeriveDumpSimsC( pFile, vDivs, nWords );
783 Supp_DeriveDumpSims( pFile, vIsfs, nWords );
784 fclose ( pFile );
785 RetValue = 0;
786}
787void Supp_DeriveDumpSol( Vec_Int_t * vSet, Vec_Int_t * vRes, int nDivs )
788{
789 char Buffer[100];
790 int RetValue = sprintf( Buffer, "%02d.sol", s_Counter );
791 int i, iLit, iLitRes = -1, nSupp = Vec_IntSize(vSet);
792 FILE * pFile = fopen( Buffer, "wb" );
793 if ( pFile == NULL )
794 printf( "Cannot open output file.\n" );
795 fprintf( pFile, "sol name aig %d\n", Vec_IntSize(vRes)/2 );
796 //Vec_IntPrint( vSet );
797 //Vec_IntPrint( vRes );
798 Vec_IntForEachEntry( vRes, iLit, i )
799 {
800 assert( iLit != 2 && iLit != 3 );
801 if ( iLit < 2 )
802 iLitRes = iLit;
803 else if ( iLit-4 < 2*nSupp )
804 {
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));
808 }
809 else
810 iLitRes = iLit + 2*((nDivs+1)-(nSupp+2));
811 fprintf( pFile, "%d ", iLitRes );
812 }
813 if ( Vec_IntSize(vRes) & 1 )
814 fprintf( pFile, "%d ", iLitRes );
815 fprintf( pFile, "\n" );
816 fclose( pFile );
817 RetValue = 0;
818 printf( "Dumped solution info file \"%s\".\n", Buffer );
819}
820
832void Supp_DeriveDumpProb2( Vec_Wrd_t * vIsfs, Vec_Wrd_t * vDivs, int nWords, Vec_Int_t * vSupp, Vec_Int_t * vRes )
833{
834 char Buffer[100]; int i, k, Temp, nDivs = Vec_WrdSize(vDivs)/nWords;
835 int RetValue = sprintf( Buffer, "%02d.pla", s_Counter );
836 FILE * pFile = fopen( Buffer, "wb" );
837 if ( pFile == NULL )
838 printf( "Cannot open output file.\n" );
839// fprintf( pFile, "resyn %d %d %d %d\n", 0, nDivs, 1, 64*nWords );
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) );
846// fprintf( pFile, " %d\n", Abc_TtGetBit(Vec_WrdEntryP(vIsfs, 1*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" );
851 else
852 fprintf( pFile, " -\n" );
853 }
854 fprintf( pFile, ".e\n" );
855
856 fprintf( pFile, "\n.s" );
857 Vec_IntForEachEntryStart( vSupp, Temp, i, 2 )
858 fprintf( pFile, " %d", Temp );
859 fprintf( pFile, "\n.a" );
860 Vec_IntForEachEntry( vRes, Temp, i )
861 fprintf( pFile, " %d", Temp );
862 fprintf( pFile, "\n" );
863 fclose ( pFile );
864 RetValue = 0;
865}
866
867
879Vec_Int_t * Supp_ManFindBestSolution( Supp_Man_t * p, Vec_Wec_t * vSols, int fVerbose, Vec_Int_t ** pvDivs )
880{
881 Vec_Int_t * vLevel, * vRes = NULL;
882 int i, k, iSet, nFuncs = 0, Count = 0;
883 int iSolBest = -1, Cost, CostBest = ABC_INFINITY;
884 Vec_WecForEachLevel( vSols, vLevel, i )
885 {
886 Count += Vec_IntSize(vLevel) > 0;
887 Vec_IntForEachEntry( vLevel, iSet, k )
888 {
889 if ( fVerbose )
890 printf( "%3d : ", nFuncs++ );
891 Cost = Gia_ManEvalSolutionOne( p->pGia, p->vSims, p->vIsfs, p->vCands, Hsh_VecReadEntry(p->pHash, iSet), p->nWords, fVerbose );
892 if ( Cost == -1 )
893 continue;
894 if ( CostBest > Cost )
895 {
896 CostBest = Cost;
897 iSolBest = iSet;
898 }
899 if ( nFuncs > 5 )
900 break;
901 }
902 if ( Count == 2 || k < Vec_IntSize(vLevel) )
903 break;
904 }
905 if ( iSolBest > 0 && (CostBest >> 2) < 50 )
906 {
907 Vec_Int_t * vDivs2 = Vec_IntAlloc( 100 );
908 Vec_Int_t * vSet = Hsh_VecReadEntry( p->pHash, iSolBest ); int i, iObj;
909 vRes = Gia_ManDeriveSolutionOne( p->pGia, p->vSims, p->vIsfs, p->vCands, vSet, p->nWords, CostBest & 3 );
910 assert( !vRes || Vec_IntSize(vRes) == 2*(CostBest >> 2)+1 );
911 if ( vRes && pvDivs )
912 {
913 Vec_IntClear( *pvDivs );
914 Vec_IntPushTwo( *pvDivs, -1, -1 );
915 Vec_IntPushTwo( vDivs2, -1, -1 );
916 Vec_IntForEachEntry( vSet, iObj, i ) {
917 Vec_IntPush( *pvDivs, Vec_IntEntry(p->vCands, iObj) );
918 Vec_IntPush( vDivs2, iObj );
919 }
920 }
921 //Supp_DeriveDumpProbC( p->vIsfs, p->vDivsC, p->nWords );
922 //Supp_DeriveDumpProb( p->vIsfs, p->vDivs[1], p->nWords );
923 //Supp_DeriveDumpSol( vSet, vRes, Vec_WrdSize(p->vDivs[1])/p->nWords );
924 //Supp_DeriveDumpProb2( p->vIsfs, p->vDivs[1], p->nWords, vDivs2, vRes );
925 Vec_IntFree( vDivs2 );
926 s_Counter++;
927 }
928 return vRes;
929}
930
943{
944 int i, iObj, iSet = 0;
945 Vec_Int_t * vSet = Vec_IntStart( 2 );
946 //extern void Patch_GenerateSet11( Gia_Man_t * p, Vec_Int_t * vDivs, Vec_Int_t * vCands );
947 //Patch_GenerateSet11( p->pGia, vSet, p->vCands );
948 Vec_IntDrop( vSet, 0 );
949 Vec_IntDrop( vSet, 0 );
950 Vec_IntForEachEntry( vSet, iObj, i )
951 iSet = Supp_ManSubsetAdd( p, iSet, iObj, 1 );
952 Vec_IntFree( vSet );
953 return iSet;
954}
955
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 )
968{
969 int fVeryVerbose = 0;
970 int i, r, iSet, iBest = -1;
971 abctime clk = Abc_Clock();
972 Vec_Int_t * vRes = NULL;
973 Supp_Man_t * p;
974 if ( vCands )
975 p = Supp_ManCreate( vIsfs, vCands, vWeights, vSims, vSimsC, nWords, pGia, nIters, nRounds );
976 else
977 p = Supp_ManCreate2( vIsfs, vSims, NULL, nWords, nIters, nRounds );
978 if ( Supp_SetFuncNum(p, 0) == 0 )
979 {
980 Supp_ManDelete( p );
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) );
985 return vRes;
986 }
987 if ( fVerbose )
988 printf( "Using %d divisors with %d words. Problem has %d functions and %d minterm pairs.\n",
989 Vec_IntSize(p->vCands), p->nWords, Supp_SetFuncNum(p, 0), Supp_SetPairNum(p, 0) );
990 //iBest = Supp_FindGivenOne( p );
991 if ( iBest == -1 )
992 for ( i = 0; i < p->nIters; i++ )
993 {
995 iSet = Supp_ManRandomSolution( p, 0, fVeryVerbose );
996 if ( iSet == -1 ) {
997 Supp_ManDelete( p );
998 return NULL;
999 }
1000 for ( r = 0; r < p->nRounds; r++ )
1001 {
1002 if ( fVeryVerbose )
1003 printf( "\n\nITER %d ROUND %d\n", i, r );
1004 iSet = Supp_ManMinimize( p, iSet, r, fVeryVerbose );
1005 if ( iBest == -1 || Supp_SetWeight(p, iBest) > Supp_SetWeight(p, iSet) )
1006 //if ( Supp_SetSize(p, iBest) > Supp_SetSize(p, iSet) )
1007 {
1008 if ( fVeryVerbose )
1009 printf( "\nThe best solution found:\n" );
1010 if ( fVeryVerbose )
1011 Supp_PrintOne( p, iSet );
1012 iBest = iSet;
1013 }
1014 iSet = Supp_ManReconstruct( p, fVeryVerbose );
1015 if ( iSet == -1 ) {
1016 Supp_ManDelete( p );
1017 return NULL;
1018 }
1019 }
1020 if ( fVeryVerbose )
1021 printf( "Matrix size %d.\n", Vec_PtrSize(p->vMatrix) );
1023 }
1024 if ( fVerbose )
1025 {
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: " );
1030 if ( iBest == -1 )
1031 printf( "No solution.\n" );
1032 else
1033 Supp_PrintOne( p, iBest );
1034 }
1035 vRes = Supp_ManFindBestSolution( p, p->vSolutions, fVerbose, pvDivs );
1036 //Vec_IntPrint( vRes );
1037 Supp_ManDelete( p );
1038// if ( vRes && Vec_IntSize(vRes) == 0 )
1039// Vec_IntFreeP( &vRes );
1040 return vRes;
1041}
1043{
1044 Vec_Wrd_t * vSimsPi = Vec_WrdStartTruthTables( Gia_ManCiNum(p) );
1045 Vec_Wrd_t * vSims = Gia_ManSimPatSimOut( p, vSimsPi, 0 );
1046 int i, iPoId, nWords = Vec_WrdSize(vSimsPi) / Gia_ManCiNum(p);
1047 Vec_Wrd_t * vIsfs = Vec_WrdStart( 2*nWords );
1048 Vec_Int_t * vCands = Vec_IntAlloc( 4 );
1049 Vec_Int_t * vRes;
1050
1051// for ( i = 0; i < Gia_ManCiNum(p)+5; i++ )
1052 for ( i = 0; i < Gia_ManCiNum(p); i++ )
1053 Vec_IntPush( vCands, 1+i );
1054
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 );
1058
1059 vRes = Supp_ManCompute( vIsfs, vCands, NULL, vSims, NULL, nWords, p, NULL, 1, 1, 0 );
1060 Vec_IntPrint( vRes );
1061
1062 Vec_WrdFree( vSimsPi );
1063 Vec_WrdFree( vSims );
1064 Vec_WrdFree( vIsfs );
1065 Vec_IntFree( vCands );
1066 Vec_IntFree( vRes );
1067}
1068
1080void Supp_RecordSolution( char * pFileName, Vec_Int_t * vDivs, Vec_Int_t * vRes )
1081{
1082 FILE * pFile = fopen( pFileName, "ab" );
1083 if ( pFile == NULL ) {
1084 printf( "Cannot open file \"%s\" for writing.\n", pFileName );
1085 return;
1086 }
1087 int i, Temp;
1088 fprintf( pFile, "\n.s" );
1089 Vec_IntForEachEntryStart( vDivs, Temp, i, 2 )
1090 fprintf( pFile, " %d", Temp );
1091 fprintf( pFile, "\n.a" );
1092 Vec_IntForEachEntry( vRes, Temp, i )
1093 fprintf( pFile, " %d", Temp-2 );
1094 fprintf( pFile, "\n" );
1095 fclose( pFile );
1096}
1097
1110{
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 );
1115 Gia_Man_t * pNew = Gia_ManStart( 100 );
1116 pNew->pName = Abc_UtilStrsav( "resub" );
1117 for ( i = 0; i < nIns; i++ )
1118 Gia_ManAppendCi(pNew);
1119 Vec_IntForEachEntryDouble( vRes, iLit0, iLit1, i ) {
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 );
1124 else assert( 0 );
1125 }
1126 Gia_ManAppendCo(pNew, iTopLit-nAddOn);
1127 return pNew;
1128}
1129Gia_Man_t * Supp_ManSolveOne( char * pFileName, int nIters, int nRounds, int fWriteSol, int fVerbose )
1130{
1131 //Abc_Random(1);
1132 Abc_RData_t * p = Abc_ReadPla( pFileName );
1133 if ( p == NULL ) return NULL;
1134 assert( p->nOuts == 1 );
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 );
1139 Gia_Man_t * pNew = vRes ? Supp_GenerateGia( vRes, vDivs ) : NULL;
1140 if ( fWriteSol && vDivs && vRes )
1141 Supp_RecordSolution( pFileName, vDivs, vRes );
1142 Vec_IntFreeP( &vRes );
1143 Vec_IntFreeP( &vDivs );
1144 Abc_RDataStop( p );
1145 return pNew;
1146}
1147
1151
1152
1154
int nWords
Definition abcNpn.c:127
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition abc_global.h:250
unsigned Abc_Random(int fReset)
Definition utilSort.c:1004
#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
Cube * p
Definition exorList.c:222
int s_Counter
Definition giaCSat.c:494
void Supp_DeriveDumpProb(Vec_Wrd_t *vIsfs, Vec_Wrd_t *vDivs, int nWords)
Definition giaSupps.c:759
int Supp_ArrayWeight(Vec_Int_t *vRes, Vec_Int_t *vWeights)
Definition giaSupps.c:297
int Supp_ManFuncInit(Vec_Wrd_t *vFuncs, int nWords)
FUNCTION DEFINITIONS ///.
Definition giaSupps.c:84
void Supp_PrintNodes(Gia_Man_t *pGia, Vec_Int_t *vObjs, int Skip, int Limit)
Definition giaSupps.c:328
int Supp_ManRandomSolution(Supp_Man_t *p, int iSet, int fVerbose)
Definition giaSupps.c:629
Supp_Man_t * Supp_ManCreate2(Vec_Wrd_t *vIsfs, Vec_Wrd_t *vSims, Vec_Int_t *vWeights, int nWords, int nIters, int nRounds)
Definition giaSupps.c:202
void Supp_ManAddPatterns(Supp_Man_t *p, Vec_Int_t *vSets)
Definition giaSupps.c:567
int Supp_ManSubsetRemove(Supp_Man_t *p, int iSet, int iPos)
Definition giaSupps.c:647
void Supp_ManRefine(Supp_Man_t *p, int iSet, int iObj, int *pnFuncs, int *pnPairs)
Definition giaSupps.c:401
int Supp_SetPairNum(Supp_Man_t *p, int iSet)
Definition giaSupps.c:318
int Supp_ComputePair1(Supp_Man_t *p, int iSet)
Definition giaSupps.c:492
void Supp_SetConvert(Vec_Int_t *vSet, Vec_Int_t *vCands)
Definition giaSupps.c:322
void Supp_RecordSolution(char *pFileName, Vec_Int_t *vDivs, Vec_Int_t *vRes)
Definition giaSupps.c:1080
int Supp_SetFuncNum(Supp_Man_t *p, int iSet)
Definition giaSupps.c:314
Vec_Int_t * Supp_ManCollectOnes(word *pSim, int nWords)
Definition giaSupps.c:574
void Supp_ManDelete(Supp_Man_t *p)
Definition giaSupps.c:240
int Supp_ManCostInit(Vec_Wrd_t *vFuncs, int nWords)
Definition giaSupps.c:101
int Supp_DeriveLines(Supp_Man_t *p)
Definition giaSupps.c:139
void Supp_ManComputeTest(Gia_Man_t *p)
Definition giaSupps.c:1042
int Supp_ManMinimize(Supp_Man_t *p, int iSet0, int r, int fVerbose)
Definition giaSupps.c:655
int Supp_ManMemory(Supp_Man_t *p)
Definition giaSupps.c:266
Gia_Man_t * Supp_GenerateGia(Vec_Int_t *vRes, Vec_Int_t *vDivs)
Definition giaSupps.c:1109
void Supp_DeriveDumpProbC(Vec_Wrd_t *vIsfs, Vec_Wrd_t *vDivs[2], int nWords)
Definition giaSupps.c:773
void Supp_ManInit(Supp_Man_t *p)
Definition giaSupps.c:115
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)
Definition giaSupps.c:967
void Supp_DeriveDumpProb2(Vec_Wrd_t *vIsfs, Vec_Wrd_t *vDivs, int nWords, Vec_Int_t *vSupp, Vec_Int_t *vRes)
Definition giaSupps.c:832
void Supp_ManCleanMatrix(Supp_Man_t *p)
Definition giaSupps.c:233
int Supp_ManReconstruct(Supp_Man_t *p, int fVerbose)
Definition giaSupps.c:699
Vec_Int_t * Supp_ManFindBestSolution(Supp_Man_t *p, Vec_Wec_t *vSols, int fVerbose, Vec_Int_t **pvDivs)
Definition giaSupps.c:879
void Supp_DeriveDumpSol(Vec_Int_t *vSet, Vec_Int_t *vRes, int nDivs)
Definition giaSupps.c:787
Vec_Int_t * Supp_Compute64Pairs(Supp_Man_t *p, Vec_Int_t *vSets)
Definition giaSupps.c:538
int Supp_ManRefine1(Supp_Man_t *p, int iSet, int iObj)
Definition giaSupps.c:364
int Supp_DeriveLines2(Supp_Man_t *p)
Definition giaSupps.c:189
typedefABC_NAMESPACE_IMPL_START struct Supp_Man_t_ Supp_Man_t
DECLARATIONS ///.
Definition giaSupps.c:34
int Supp_SetWeight(Supp_Man_t *p, int iSet)
Definition giaSupps.c:306
void Supp_ManAddPatternsFunc(Supp_Man_t *p, int nBatches)
Definition giaSupps.c:595
int Supp_ComputePair(Supp_Man_t *p, int iSet)
Definition giaSupps.c:512
int Supp_FindNextDiv(Supp_Man_t *p, int Pair)
Definition giaSupps.c:610
Vec_Int_t * Supp_Compute64PairsFunc(Supp_Man_t *p, Vec_Int_t *vBits0, Vec_Int_t *vBits1)
Definition giaSupps.c:582
void Supp_DeriveDumpSimsC(FILE *pFile, Vec_Wrd_t *vDivs[2], int nWords)
Definition giaSupps.c:742
void Supp_DeriveDumpSims(FILE *pFile, Vec_Wrd_t *vDivs, int nWords)
Definition giaSupps.c:731
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)
Definition giaSupps.c:159
int Supp_FindGivenOne(Supp_Man_t *p)
Definition giaSupps.c:942
int Supp_SetSize(Supp_Man_t *p, int iSet)
Definition giaSupps.c:310
void Supp_PrintOne(Supp_Man_t *p, int iSet)
Definition giaSupps.c:352
Gia_Man_t * Supp_ManSolveOne(char *pFileName, int nIters, int nRounds, int fWriteSol, int fVerbose)
Definition giaSupps.c:1129
int Supp_ManFindNextObj(Supp_Man_t *p, int fVerbose)
Definition giaSupps.c:683
void Supp_ManFillBlock(Supp_Man_t *p, Vec_Int_t *vPairs, Vec_Wrd_t *vRes)
Definition giaSupps.c:550
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)
Definition giaSupps.c:454
Vec_Wrd_t * Gia_ManSimPatSimOut(Gia_Man_t *pGia, Vec_Wrd_t *vSimsPi, int fOuts)
Definition giaSimBase.c:138
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)
Definition giaDecs.c:318
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
Definition giaMan.c:57
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
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)
Definition giaDecs.c:277
typedefABC_NAMESPACE_HEADER_START struct Abc_RData_t_ Abc_RData_t
INCLUDES ///.
Definition ioResub.h:40
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
char * pName
Definition gia.h:99
Vec_Int_t * vWeights
Definition gia.h:174
Vec_Wrd_t * vDivs[2]
Definition giaSupps.c:49
Vec_Int_t * vCosts
Definition giaSupps.c:55
Vec_Wrd_t * vPats[2]
Definition giaSupps.c:51
Vec_Ptr_t * vMatrix
Definition giaSupps.c:52
Vec_Wrd_t * vDivsC[2]
Definition giaSupps.c:50
Vec_Int_t * vSStarts
Definition giaSupps.c:58
Vec_Int_t * vTemp
Definition giaSupps.c:61
Vec_Wrd_t * vSimsC
Definition giaSupps.c:46
Hsh_VecMan_t * pHash
Definition giaSupps.c:56
int nDivWords
Definition giaSupps.c:41
Vec_Wrd_t * vSims
Definition giaSupps.c:45
Vec_Wrd_t * vMask
Definition giaSupps.c:53
Vec_Int_t * vTempPairs
Definition giaSupps.c:63
Vec_Wrd_t * vIsfs
Definition giaSupps.c:42
Gia_Man_t * pGia
Definition giaSupps.c:47
Vec_Wrd_t * vRowTemp
Definition giaSupps.c:54
Vec_Wrd_t * vSFuncs
Definition giaSupps.c:57
Vec_Int_t * vSCount
Definition giaSupps.c:59
Vec_Int_t * vSPairs
Definition giaSupps.c:60
Vec_Wec_t * vSolutions
Definition giaSupps.c:64
Vec_Int_t * vTempSets
Definition giaSupps.c:62
int nRounds
Definition giaSupps.c:39
Vec_Int_t * vWeights
Definition giaSupps.c:44
Vec_Int_t * vCands
Definition giaSupps.c:43
#define assert(ex)
Definition util_old.h:213
char * sprintf()
struct Hsh_VecMan_t_ Hsh_VecMan_t
Definition vecHsh.h:85
#define Vec_IntForEachEntryDouble(vVec, Entry1, Entry2, i)
Definition vecInt.h:72
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
Definition vecInt.h:56
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
#define Vec_WecForEachLevel(vGlob, vVec, i)
MACRO DEFINITIONS ///.
Definition vecWec.h:55
typedefABC_NAMESPACE_HEADER_START struct Vec_Wec_t_ Vec_Wec_t
INCLUDES ///.
Definition vecWec.h:42
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.
Definition vecWrd.h:42
#define Vec_WrdForEachEntryStop(vVec, Entry, i, Stop)
Definition vecWrd.h:58